4 if [ -z "$zvols" ]; then
11 filter_out_zvols_with_links
() {
12 echo "$zvols" |
tr ' ' '+' |
while read -r zvol
; do
13 if ! [ -L "/dev/zvol/$zvol" ]; then
19 filter_out_deleted_zvols
() {
23 # shellcheck disable=SC2086
24 zfs list
-H -o name
$zvols 2>/dev
/null
29 read -r default_volmode
< /sys
/module
/zfs
/parameters
/zvol_volmode
30 zfs list
-t volume
-H -o \
31 name
,volmode
,receive_resume_token
,redact_snaps
,keystatus |
32 while IFS
=" " read -r name volmode token redacted keystatus
; do # IFS=\t here!
34 # /dev links are not created for zvols with volmode = "none",
35 # redacted zvols, or encrypted zvols for which the key has not
37 [ "$volmode" = "none" ] && continue
38 [ "$volmode" = "default" ] && [ "$default_volmode" = "3" ] &&
40 [ "$redacted" = "-" ] ||
continue
41 [ "$keystatus" = "unavailable" ] && continue
43 # We also ignore partially received zvols if it is
44 # not an incremental receive, as those won't even have a block
45 # device minor node created yet.
46 if [ "$token" != "-" ]; then
48 # Incremental receives create an invisible clone that
49 # is not automatically displayed by zfs list.
50 if ! zfs list
"$name/%recv" >/dev
/null
2>&1; then
59 zvols_count
=$
(count_zvols
)
60 if [ "$zvols_count" -eq 0 ]; then
61 echo "No zvols found, nothing to do."
65 echo "Testing $zvols_count zvol links"
68 while [ "$outer_loop" -lt 20 ]; do
69 outer_loop
=$
((outer_loop
+ 1))
71 old_zvols_count
=$
(count_zvols
)
74 while [ "$inner_loop" -lt 30 ]; do
75 inner_loop
=$
((inner_loop
+ 1))
77 zvols
="$(filter_out_zvols_with_links)"
79 zvols_count
=$
(count_zvols
)
80 if [ "$zvols_count" -eq 0 ]; then
81 echo "All zvol links are now present."
87 echo "Still waiting on $zvols_count zvol links ..."
89 # Although zvols should normally not be deleted at boot time,
90 # if that is the case then their links will be missing and
93 if [ "$old_zvols_count" -eq "$zvols_count" ]; then
94 echo "No progress since last loop."
95 echo "Checking if any zvols were deleted."
97 zvols
=$
(filter_out_deleted_zvols
)
98 zvols_count
=$
(count_zvols
)
100 if [ "$old_zvols_count" -ne "$zvols_count" ]; then
101 echo "$((old_zvols_count - zvols_count)) zvol(s) deleted."
104 if [ "$zvols_count" -ne 0 ]; then
105 echo "Remaining zvols:"
108 echo "All zvol links are now present."
114 echo "Timed out waiting on zvol links"