[Pkg-zfsonlinux-devel] Bug#986380: /u/l/z-l/{scrub, trim}: proper handling for pools with spaces in name (mostly)
наб
nabijaczleweli at nabijaczleweli.xyz
Sun Apr 4 19:11:47 BST 2021
Package: zfsutils-linux
Version: 2.0.3-5
Severity: normal
Tags: patch
Dear Maintainer,
Please consider the following patch; it does:
* for both:
+ properly handles pools with spaces in names in the main list
+ uses $0 instead of hard-coding the path in error message
+ simplifies some confusing continues into :-nops
* for trim:
+ simplifies the is-nvme-only check (it might not look like it, but
I'm pretty sure that's -e-compatible; it worked right in my tests)
-- >8 --
diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub
index 2e48df82f..f18c6e83a 100755
--- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub
+++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/scrub
@@ -27,20 +27,19 @@ scrub_if_not_scrub_in_progress () {
# Scrub all healthy pools that are not already scrubbing as per their configs.
zpool list -H -o health,name 2>&1 | \
- awk '$1 ~ /^ONLINE/ { print $2; }' | \
+ 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
- continue
+ :
elif [ "-" = "${ret}" ] || [ "auto" = "${ret}" ] || [ "enable" = "${ret}" ]; then
scrub_if_not_scrub_in_progress "${pool}"
else
cat > /dev/stderr <<EOF
-/usr/lib/zfs-linux/scrub: [WARNING] illegal value "${ret}" for property "${PROPERTY_NAME}" of ZFS dataset "${pool}".
-/usr/lib/zfs-linux/scrub: Acceptable choices for this property are: auto, enable, disable. The default is auto.
+$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
- continue
fi
done
diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
index 75e876b7b..5b6305b07 100755
--- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
+++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim
@@ -29,37 +29,32 @@ trim_if_not_already_trimming () {
zpool_is_nvme_only () {
zpool=$1
# get a list of devices attached to the specified zpool
- zpool list -vHPL ${zpool} | awk '/\/dev\//{print $1}' \
- | while read dev
- do
- # are these devices all nvme drives?
- if !(echo ${dev} | grep -q /dev/nvme); then
- return 1
- fi
- done
- return 0
+ 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 '$1 ~ /^ONLINE/ { print $2; }' | \
+ 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
- continue
+ :
elif [ "enable" = "${ret}" ]; then
trim_if_not_already_trimming "${pool}"
elif [ "-" = "${ret}" ] || [ "auto" = "${ret}" ]; then
- # only automatically trim the nvme-only pools.
- zpool_is_nvme_only "${pool}" \
- && trim_if_not_already_trimming "${pool}" \
- || continue
+ if zpool_is_nvme_only "${pool}"; then
+ trim_if_not_already_trimming "${pool}"
+ fi
else
cat > /dev/stderr <<EOF
-/usr/lib/zfs-linux/trim: [WARNING] illegal value "${ret}" for property "${PROPERTY_NAME}" of ZFS dataset "${pool}".
-/usr/lib/zfs-linux/trim: Acceptable choices for this property are: auto, enable, disable. The default is auto.
+$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
done
-- >8 --
Best,
наб
-- System Information:
Debian Release: bullseye/sid
APT prefers unstable-debug
APT policy: (500, 'unstable-debug'), (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 5.10.0-3-amd64 (SMP w/8 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages zfsutils-linux depends on:
ii init-system-helpers 1.60
ii libblkid1 2.36.1-7
ii libc6 2.31-11
ii libnvpair3linux 2.0.3-5
ii libuuid1 2.36.1-7
ii libuutil3linux 2.0.3-5
ii libzfs4linux 2.0.3-5
ii libzpool4linux 2.0.3-5
ii python3 3.9.2-2
Versions of packages zfsutils-linux recommends:
ii lsb-base 11.1.0
ii zfs-dkms [zfs-modules] 2.0.3-5
ii zfs-zed 2.0.3-5
Versions of packages zfsutils-linux suggests:
pn nfs-kernel-server <none>
ii samba-common-bin 2:4.13.5+dfsg-1
ii zfs-dracut 2.0.3-5
-- Configuration Files:
/etc/sudoers.d/zfs [Errno 13] Permission denied: '/etc/sudoers.d/zfs'
-- no debconf information
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-zfsonlinux-devel/attachments/20210404/af308b1a/attachment.sig>
More information about the Pkg-zfsonlinux-devel
mailing list