trim: determine if a device uses nvme transport with lsblk (Closes: #990745)

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@proxmox.com>
This commit is contained in:
Stoiko Ivanov 2022-10-04 15:47:59 +02:00 committed by Thomas Lamprecht
parent 8f586181c6
commit 68b54bb663

View File

@ -26,14 +26,33 @@ trim_if_not_already_trimming () {
fi 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_is_nvme_only () {
zpool=$1 zpool=$1
# get a list of devices attached to the specified zpool # get a list of devices attached to the specified zpool
zpool list -vHPL "${zpool}" | for x in $(zpool list -vHPL "${zpool}" |\
awk -F'\t' '$2 ~ /^\/dev\// { awk -F'\t' '{if($2 ~ /^\/dev\//) print $2}'); do
if($2 !~ /^\/dev\/nvme/) if [ "$(get_transp $x)" != "nvme" ]; then
exit 1 return 1
}' fi
done
} }
# TRIM all healthy pools that are not already trimming as per their configs. # TRIM all healthy pools that are not already trimming as per their configs.