aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-04-07 17:37:55 +0200
committerBrian Behlendorf <[email protected]>2021-04-11 11:56:53 -0700
commit519aec83f574d5d60b46d716161db2195f0a0ae1 (patch)
tree30d75c6280d9e3057b58af51cbeedb983c1cc862
parentea4541e4c6c1bcd629d3d335e33b97fb94f3be38 (diff)
zvol_wait: fix for zvols with spaces in name, optimise
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 <[email protected]> Reviewed-by: Pavel Zakharov <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11859
-rwxr-xr-xcmd/zvol_wait/zvol_wait28
1 files changed, 12 insertions, 16 deletions
diff --git a/cmd/zvol_wait/zvol_wait b/cmd/zvol_wait/zvol_wait
index eb1b3e81f..90a4bf8dd 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