public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH zfsonlinux 2/3] trim: clean up, fix
Date: Fri,  2 Dec 2022 17:32:52 +0100	[thread overview]
Message-ID: <20221202163253.713806-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20221202163253.713806-1-s.ivanov@proxmox.com>

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 <s.ivanov@proxmox.com>
---
 .../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 <<EOF
+	ret=$(get_property "${pool}") || continue
+	case "${ret}" in
+		disable);;
+		enable)	trim_if_not_already_trimming "${pool}" ;;
+		-|auto)	pool_is_nvme_only "${pool}" && trim_if_not_already_trimming "${pool}" ;;
+		*)	cat > /dev/stderr <<EOF
 $0: [WARNING] illegal value "${ret}" for property "${PROPERTY_NAME}" of ZFS dataset "${pool}".
 $0: Acceptable choices for this property are: auto, enable, disable. The default is auto.
 EOF
-	fi
+	esac
 done
-- 
2.30.2





  parent reply	other threads:[~2022-12-02 16:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 16:32 [pve-devel] [PATCH zfsonlinux 0/3] update to 2.1.7 Stoiko Ivanov
2022-12-02 16:32 ` [pve-devel] [PATCH zfsonlinux 1/3] update zfs submodule to 2.1.7 and refresh patches Stoiko Ivanov
2022-12-02 16:32 ` Stoiko Ivanov [this message]
2022-12-02 16:32 ` [pve-devel] [PATCH zfsonlinux 3/3] d/control: add libudev-dev and libaio-dev to build-depends Stoiko Ivanov
2022-12-06 15:45 ` [pve-devel] applied: [PATCH zfsonlinux 0/3] update to 2.1.7 Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221202163253.713806-3-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal