File 0222-90dm-Fixup-shutdown-script.patch of Package dracut.16003

From 885b133ecd7913990449e7598526d0965ebc3458 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 25 Aug 2016 09:28:30 +0200
Subject: [PATCH] 90dm: Fixup shutdown script

When calling the shutdown script we need to take care of traversing
the device-mapper tables, otherwise we might end up trying to remove
a device-mapper device which still has another one stacked on top
and the removal will fail.

References: bsc#994860

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 modules.d/90dm/dm-shutdown.sh | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/modules.d/90dm/dm-shutdown.sh b/modules.d/90dm/dm-shutdown.sh
index 04c89be..0685a68 100755
--- a/modules.d/90dm/dm-shutdown.sh
+++ b/modules.d/90dm/dm-shutdown.sh
@@ -1,11 +1,28 @@
 #!/bin/sh
 
+_remove_dm() {
+    local dev=$1
+    local s
+    local devname
+
+    for s in /sys/block/${dev}/holders/dm-* ; do
+        [ -e ${s} ] || continue
+        _remove_dm ${s##*/}
+    done
+    devname=$(cat /sys/block/${dev}/dm/name)
+    dmsetup -v --noudevsync remove "$devname" || return $?
+    return 0
+}
+
 _do_dm_shutdown() {
     local ret=0
     local final=$1
+    local dev
+
     info "Disassembling device-mapper devices"
-    for dev in $(dmsetup info -c --noheadings -o name) ; do
-        dmsetup -v --noudevsync remove "$dev" || ret=$?
+    for dev in /sys/block/dm-* ; do
+        [ -e ${dev} ] || continue
+        _remove_dm ${dev##*/} || ret=$?
     done
     if [ "x$final" != "x" ]; then
         info "dmsetup ls --tree"
-- 
2.6.6