From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BF3C37329A for ; Thu, 17 Jun 2021 15:53:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E3B9B1CA21 for ; Thu, 17 Jun 2021 15:52:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CFA0D1C5FB for ; Thu, 17 Jun 2021 15:52:49 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A7BA34419B for ; Thu, 17 Jun 2021 15:52:49 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Thu, 17 Jun 2021 15:52:18 +0200 Message-Id: <20210617135223.23472-12-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210617135223.23472-1-s.ivanov@proxmox.com> References: <20210617135223.23472-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.685 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH zfsonlinux 11/16] sync scrub and trim cronjobs with debian upstream X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 13:53:29 -0000 * Pull in the changes to the automatic scrub cronjob from debian-upstream [0] commit f6d45405df0a2ed2748975667e8ea50714034d13 * Add a script and cronjob for regular trimming of pools * Change the logic to scrub/trim pools based on a per pool('s root dataset property) pulled the changes in as one commit instead of cherry-picking, since the planned and reverted debconf questions would have caused unneccessary churn. commits identified by running: `git log --full-diff -- debian/tree/zfsutils-linux/usr/lib/zfs-linux` in a worktree from [0]. [0] https://salsa.debian.org/zfsonlinux-team/zfs/ Signed-off-by: Stoiko Ivanov --- .../zfsutils-linux/usr/lib/zfs-linux/scrub | 43 +++++++++++-- .../zfsutils-linux/usr/lib/zfs-linux/trim | 60 +++++++++++++++++++ debian/zfsutils-linux.cron.d | 5 +- 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100755 debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub index 38f071af..f18c6e83 100755 --- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub +++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub @@ -1,12 +1,45 @@ #!/bin/sh -eu -# Scrub all healthy pools that are not already scrubbing. +# directly exit successfully when zfs module is not loaded +if ! [ -d /sys/module/zfs ]; then + exit 0 +fi + +# [auto] / enable / disable +PROPERTY_NAME="org.debian:periodic-scrub" + +get_property () { + # Detect the ${PROPERTY_NAME} property on a given pool. + # We are abusing user-defined properties on the root dataset, + # since they're not available on pools https://github.com/openzfs/zfs/pull/11680 + # TODO: use zpool user-defined property when such feature is available. + pool="$1" + zfs get -H -o value "${PROPERTY_NAME}" "${pool}" 2>/dev/null || return 1 +} + +scrub_if_not_scrub_in_progress () { + pool="$1" + if ! zpool status "${pool}" | grep -q "scrub in progress"; then + # Ignore errors and continue with scrubbing other pools. + zpool scrub "${pool}" || true + fi +} + +# Scrub all healthy pools that are not already scrubbing as per their configs. zpool list -H -o health,name 2>&1 | \ - awk 'BEGIN {FS="\t"} {if ($1 ~ /^ONLINE/) print $2}' | \ + awk -F'\t' '$1 == "ONLINE" {print $2}' | \ while read pool do - if ! zpool status "$pool" | grep -q "scrub in progress" - then - zpool scrub "$pool" + # read user-defined config + ret=$(get_property "${pool}") + if [ $? -ne 0 ] || [ "disable" = "${ret}" ]; then + : + elif [ "-" = "${ret}" ] || [ "auto" = "${ret}" ] || [ "enable" = "${ret}" ]; then + scrub_if_not_scrub_in_progress "${pool}" + else + cat > /dev/stderr </dev/null || return 1 +} + +trim_if_not_already_trimming () { + pool="$1" + if ! zpool status "${pool}" | grep -q "trimming"; then + # Ignore errors (i.e. HDD pools), + # and continue with trimming other pools. + zpool trim "${pool}" || true + fi +} + +zpool_is_nvme_only () { + zpool=$1 + # get a list of devices attached to the specified zpool + zpool list -vHPL "${zpool}" | + awk -F'\t' '$2 ~ /^\/dev\// { + if($2 !~ /^\/dev\/nvme/) + exit 1 + }' +} + +# TRIM all healthy pools that are not already trimming as per their configs. +zpool list -H -o health,name 2>&1 | \ + awk -F'\t' '$1 == "ONLINE" {print $2}' | \ +while read pool +do + # read user-defined config + ret=$(get_property "${pool}") + if [ $? -ne 0 ] || [ "disable" = "${ret}" ]; then + : + elif [ "enable" = "${ret}" ]; then + trim_if_not_already_trimming "${pool}" + elif [ "-" = "${ret}" ] || [ "auto" = "${ret}" ]; then + if zpool_is_nvme_only "${pool}"; then + trim_if_not_already_trimming "${pool}" + fi + else + cat > /dev/stderr <