From 519aec83f574d5d60b46d716161db2195f0a0ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 7 Apr 2021 17:37:55 +0200 Subject: [PATCH] zvol_wait: fix for zvols with spaces in name, optimise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list_zvols() would happily, for zvols with spaces in their names, assign the second half to volmode, &c., so use a normal read and set IFS to a tab instead of using 4 separate AWK processes(?) Similarly, in filter_out_deleted_zvols(), run zfs(8) once and use the output directly instead of spawning a zfs(8) process per zvol Reviewed-by: Brian Behlendorf Reviewed-by: Pavel Zakharov Reviewed-by: Ryan Moeller Signed-off-by: Ahelenia ZiemiaƄska Closes #11859 --- cmd/zvol_wait/zvol_wait | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/zvol_wait/zvol_wait b/cmd/zvol_wait/zvol_wait index eb1b3e81f6..90a4bf8dd0 100755 --- a/cmd/zvol_wait/zvol_wait +++ b/cmd/zvol_wait/zvol_wait @@ -9,29 +9,25 @@ count_zvols() { } filter_out_zvols_with_links() { - while read -r zvol; do - if [ ! -L "/dev/zvol/$zvol" ]; then + echo "$zvols" | tr ' ' '+' | while read -r zvol; do + if ! [ -L "/dev/zvol/$zvol" ]; then echo "$zvol" fi - done + done | tr '+' ' ' } filter_out_deleted_zvols() { - while read -r zvol; do - if zfs list "$zvol" >/dev/null 2>&1; then - echo "$zvol" - fi - done + OIFS="$IFS" + IFS=" +" + zfs list -H -o name $zvols 2>/dev/null + IFS="$OIFS" } list_zvols() { zfs list -t volume -H -o \ - name,volmode,receive_resume_token,redact_snaps | - while read -r zvol_line; do - name=$(echo "$zvol_line" | awk '{print $1}') - volmode=$(echo "$zvol_line" | awk '{print $2}') - token=$(echo "$zvol_line" | awk '{print $3}') - redacted=$(echo "$zvol_line" | awk '{print $4}') + name,volmode,receive_resume_token,redact_snaps | + while IFS=" " read -r name volmode token redacted; do # IFS=\t here! # # /dev links are not created for zvols with volmode = "none" # or for redacted zvols. @@ -75,7 +71,7 @@ while [ "$outer_loop" -lt 20 ]; do while [ "$inner_loop" -lt 30 ]; do inner_loop=$((inner_loop + 1)) - zvols="$(echo "$zvols" | filter_out_zvols_with_links)" + zvols="$(filter_out_zvols_with_links)" zvols_count=$(count_zvols) if [ "$zvols_count" -eq 0 ]; then @@ -95,7 +91,7 @@ while [ "$outer_loop" -lt 20 ]; do echo "No progress since last loop." echo "Checking if any zvols were deleted." - zvols=$(echo "$zvols" | filter_out_deleted_zvols) + zvols=$(filter_out_deleted_zvols) zvols_count=$(count_zvols) if [ "$old_zvols_count" -ne "$zvols_count" ]; then