Description: don't wait for links when volume has property keystatus=unavailable
  zfs-volume-wait.service systemd unit does not start if the encrypted
  zvol is locked. The /sbin/zvol_wait should not wait for links when the
  volume has property keystatus=unavailable. This patch fixes this issue
Bug: https://bugs.launchpad.net/ubuntu/+source/zfs-linux/+bug/1888405
Author: James Dingwall
Origin: ubuntu
Forwarded: no
Reviewed-By: Colin Ian King <colin.king@canonical.com>
Last-Update: 2020-07-22

Index: zfs-linux/cmd/zvol_wait/zvol_wait
===================================================================
--- zfs-linux.orig/cmd/zvol_wait/zvol_wait
+++ zfs-linux/cmd/zvol_wait/zvol_wait
@@ -25,6 +25,14 @@ filter_out_deleted_zvols() {
 	IFS="$OIFS"
 }
 
+filter_out_locked_zvols() {
+	while read -r zvol; do
+		if ! [ "$(zfs list -H -o keystatus rpool/export/vault/block "$zvol")" = "unavailable" ]; then
+			echo "$zvol"
+		fi
+	done
+}
+
 list_zvols() {
 	read -r default_volmode < /sys/module/zfs/parameters/zvol_volmode
 	zfs list -t volume -H -o \
@@ -74,7 +82,7 @@ while [ "$outer_loop" -lt 20 ]; do
 	while [ "$inner_loop" -lt 30 ]; do
 		inner_loop=$((inner_loop + 1))
 
-		zvols="$(filter_out_zvols_with_links)"
+		zvols="$(filter_out_zvols_with_links | filter_out_locked_zvols)"
 
 		zvols_count=$(count_zvols)
 		if [ "$zvols_count" -eq 0 ]; then
