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 8413ED9CF for ; Fri, 2 Dec 2022 17:32:57 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6CFD136ECC for ; Fri, 2 Dec 2022 17:32:57 +0100 (CET) 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 for ; Fri, 2 Dec 2022 17:32:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2DEF944DBE for ; Fri, 2 Dec 2022 17:32:56 +0100 (CET) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Fri, 2 Dec 2022 17:32:52 +0100 Message-Id: <20221202163253.713806-3-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221202163253.713806-1-s.ivanov@proxmox.com> References: <20221202163253.713806-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.161 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 2/3] trim: clean up, fix 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: Fri, 02 Dec 2022 16:32:57 -0000 This does: * fix get_transp() on non-bash * re-indent of the code from #990745 * fix terminology: it's pool * remove -e: I originally actually fixed -e, but it turns out literally every bit that could fail is already either || : or wasn't by accident (like in the #990745 code) * simplify get_transp() and explain why we do it instead of matching nvme path * use remove -L from the data we feed to lsblk, zpool w/o -L is measurably faster * pipe the devices into while read to match rest of code * use read -r in main loop * match the userprop with case/esac instead of if tree * shellcheck-clean the script (cherry picked from debian-upstream[0] commit 769a09407c6b65db981804a05a81ea63d004ebeb) [0] https://salsa.debian.org/zfsonlinux-team/zfs Signed-off-by: Stoiko Ivanov --- .../zfsutils-linux/usr/lib/zfs-linux/trim | 74 ++++++++----------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim index 91d00bb0..341a2fbb 100755 --- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim +++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim @@ -1,4 +1,4 @@ -#!/bin/sh -eu +#!/bin/sh -u # directly exit successfully when zfs module is not loaded if ! [ -d /sys/module/zfs ]; then @@ -14,66 +14,56 @@ get_property () { # 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 + zfs get -H -o value "${PROPERTY_NAME}" "${pool}" 2>/dev/null } 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 + # This will error on HDD-only pools: doesn't matter + zpool trim "${pool}" fi } +# Walk up the kernel parent names: +# this will catch devices from LVM &a. get_transp () { - local dev="$1" - local par_dev="$dev" - local pd - while true; do - pd=$(lsblk -dnr -o PKNAME "$par_dev") - if [ "$?" -ne 0 ]; then - return $? - fi - if [ -z "$pd" ]; then - break - else - par_dev="/dev/$pd" - fi - done - lsblk -dnr -o TRAN "$par_dev" + dev="$1" + while pd="$(lsblk -dnr -o PKNAME "$dev")"; do + if [ -z "$pd" ]; then + break + else + dev="/dev/$pd" + fi + done + lsblk -dnr -o TRAN "$dev" } -zpool_is_nvme_only () { - zpool=$1 - # get a list of devices attached to the specified zpool - for x in $(zpool list -vHPL "${zpool}" |\ - awk -F'\t' '{if($2 ~ /^\/dev\//) print $2}'); do - if [ "$(get_transp $x)" != "nvme" ]; then - return 1 - fi - done +pool_is_nvme_only () { + pool="$1" + # get a list of devices attached to the specified pool + zpool list -vHP "${pool}" | \ + awk -F'\t' '$2 ~ "^/dev/" {print $2}' | \ + while read -r dev + do + [ "$(get_transp "$dev")" = "nvme" ] || return + done } # 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 +while read -r 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 < /dev/stderr <