[pve-devel] [PATCH zfsonlinux 2/6] trim: determine if a device uses nvme transport with lsblk (Closes: #990745)

Stoiko Ivanov s.ivanov at proxmox.com
Tue Oct 4 15:47:59 CEST 2022


Thanks to Miao Wang for get_transp() function

(cherry picked from debian-upstream[0]
commit 1f5433b15e4f7c823983bb90390c4b023f3d1948)

[0] https://salsa.debian.org/zfsonlinux-team/zfs
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 .../zfsutils-linux/usr/lib/zfs-linux/trim     | 29 +++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
index 5b6305b0..91d00bb0 100755
--- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
+++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
@@ -26,14 +26,33 @@ trim_if_not_already_trimming () {
 	fi
 }
 
+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"
+}
+
 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
-		}'
+        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
 }
 
 # TRIM all healthy pools that are not already trimming as per their configs.
-- 
2.30.2






More information about the pve-devel mailing list