From 734d725d62d2cbe4445524448de024e3b9e7f4b3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 3 Jun 2024 16:01:37 +0200 Subject: Merging upstream version 102. Signed-off-by: Daniel Baumann --- modules.d/90dm/dm-shutdown.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'modules.d/90dm') diff --git a/modules.d/90dm/dm-shutdown.sh b/modules.d/90dm/dm-shutdown.sh index bd7134a..93b62bb 100755 --- a/modules.d/90dm/dm-shutdown.sh +++ b/modules.d/90dm/dm-shutdown.sh @@ -2,26 +2,40 @@ _remove_dm() { local dev="$1" + local final="$2" local s local devname for s in /sys/block/"${dev}"/holders/dm-*; do [ -e "${s}" ] || continue - _remove_dm "${s##*/}" + _remove_dm "${s##*/}" "$final" || return $? done - # multipath devices might have MD devices on top, - # which are removed after this script. So do not - # remove those to avoid spurious errors + + read -r devname < /sys/block/"${dev}"/dm/name case $(cat /sys/block/"${dev}"/dm/uuid) in mpath-*) + # multipath devices might have MD devices on top, + # which are removed after this script. So do not + # remove those to avoid spurious errors return 0 ;; - *) - read -r devname < /sys/block/"${dev}"/dm/name - dmsetup -v --noudevsync remove "$devname" || return $? + CRYPT-*) + if command -v systemd-cryptsetup > /dev/null; then + DM_DISABLE_UDEV=true SYSTEMD_LOG_LEVEL=debug systemd-cryptsetup detach "$devname" && return 0 + elif command -v cryptsetup > /dev/null; then + DM_DISABLE_UDEV=true cryptsetup close --debug "$devname" && return 0 + else + dmsetup -v --noudevsync remove "$devname" + return $? + fi + + # try using plain dmsetup if we're on the final attempt. + [ -z "$final" ] && return 1 ;; esac - return 0 + + dmsetup -v --noudevsync remove "$devname" + return $? } _do_dm_shutdown() { @@ -33,9 +47,9 @@ _do_dm_shutdown() { for dev in /sys/block/dm-*; do [ -e "${dev}" ] || continue if [ "x$final" != "x" ]; then - _remove_dm "${dev##*/}" || ret=$? + _remove_dm "${dev##*/}" "$final" || ret=$? else - _remove_dm "${dev##*/}" > /dev/null 2>&1 || ret=$? + _remove_dm "${dev##*/}" "$final" > /dev/null 2>&1 || ret=$? fi done if [ "x$final" != "x" ]; then -- cgit v1.2.3