Blame 0048-90mdraid-fix-adjust-force-run-script.patch

Harald Hoyer 55891e
From 66426469d024b7760f59051af287e11ec6a94c1f Mon Sep 17 00:00:00 2001
Harald Hoyer 55891e
From: Michal Soltys <soltys@ziu.info>
Harald Hoyer 55891e
Date: Tue, 6 Sep 2011 00:17:27 +0200
Harald Hoyer 55891e
Subject: [PATCH] 90mdraid: fix/adjust force-run script
Harald Hoyer 55891e
Harald Hoyer 55891e
1) mdadm -As --auto=yes --run 2>&1 | vinfo (removed)
Harald Hoyer 55891e
Harald Hoyer 55891e
Currently such auto assembly will not complete or force-run partially
Harald Hoyer 55891e
assembled arrays. It might assemble "concurrent" separate array and
Harald Hoyer 55891e
force-run it, if possible (though the chances of suddenly showing
Harald Hoyer 55891e
missing components in this scenario - a script run after udev timeout -
Harald Hoyer 55891e
are pretty thin). See [1] for details. Also see #3 below.
Harald Hoyer 55891e
Harald Hoyer 55891e
2) mdadm -Is --run 2>&1 (removed)
Harald Hoyer 55891e
Harald Hoyer 55891e
This will only force-run native arrays - arrays in containers will not
Harald Hoyer 55891e
be affected. See [1] for details. Also see #3 below.
Harald Hoyer 55891e
Harald Hoyer 55891e
3) mdadm -R run loop (implicitly handles #1 & #2)
Harald Hoyer 55891e
Harald Hoyer 55891e
This loop does everywthing that #1 & #2 are expected to do. Thus, the
Harald Hoyer 55891e
above invocations are simply redundant and this is the most safe and
Harald Hoyer 55891e
flexible option.
Harald Hoyer 55891e
Harald Hoyer 55891e
Also, it shouldn't be necessary to go under md/ directory, as those are
Harald Hoyer 55891e
just symlinks to /dev/md[0-9]*.
Harald Hoyer 55891e
Harald Hoyer 55891e
Certain checks were changed to strict ones (array state, degraded state)
Harald Hoyer 55891e
instead of relying on env tricks.
Harald Hoyer 55891e
Harald Hoyer 55891e
'cat' was added explicitly to installed programs (it has been used
Harald Hoyer 55891e
implicitly in shutdown script either way)
Harald Hoyer 55891e
Harald Hoyer 55891e
4) mdmon bug
Harald Hoyer 55891e
Harald Hoyer 55891e
See [1] for details as well. In short - force-run arrays in containers
Harald Hoyer 55891e
will not have mdmon started, so we do that manually.
Harald Hoyer 55891e
Harald Hoyer 55891e
5) stop/run queue magic
Harald Hoyer 55891e
Harald Hoyer 55891e
Also removed. mdadm -R will only cause change events to the array
Harald Hoyer 55891e
itself, and they should not be an issue.
Harald Hoyer 55891e
Harald Hoyer 55891e
[1] http://article.gmane.org/gmane.linux.raid/35133
Harald Hoyer 55891e
Harald Hoyer 55891e
Signed-off-by: Michal Soltys <soltys@ziu.info>
Harald Hoyer 55891e
---
Harald Hoyer 55891e
 modules.d/90mdraid/mdraid_start.sh |   51 ++++++++++++++++++++++--------------
Harald Hoyer 55891e
 modules.d/90mdraid/module-setup.sh |    2 +-
Harald Hoyer 55891e
 modules.d/90mdraid/parse-md.sh     |    1 +
Harald Hoyer 55891e
 3 files changed, 33 insertions(+), 21 deletions(-)
Harald Hoyer 55891e
Harald Hoyer 55891e
diff --git a/modules.d/90mdraid/mdraid_start.sh b/modules.d/90mdraid/mdraid_start.sh
Harald Hoyer 55891e
index 4c0255e..be5a3ce 100755
Harald Hoyer 55891e
--- a/modules.d/90mdraid/mdraid_start.sh
Harald Hoyer 55891e
+++ b/modules.d/90mdraid/mdraid_start.sh
Harald Hoyer 55891e
@@ -3,23 +3,34 @@
Harald Hoyer 55891e
 # ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
Harald Hoyer 55891e
-# run mdadm if udev has settled
Harald Hoyer 55891e
-info "Assembling MD RAID arrays"
Harald Hoyer 55891e
-udevadm control --stop-exec-queue
Harald Hoyer 55891e
-mdadm -As --auto=yes --run 2>&1 | vinfo
Harald Hoyer 55891e
-mdadm -Is --run 2>&1 | vinfo
Harald Hoyer 55891e
-
Harald Hoyer 55891e
-# there could still be some leftover devices
Harald Hoyer 55891e
-# which have had a container added
Harald Hoyer 55891e
-for md in /dev/md[0-9]* /dev/md/*; do
Harald Hoyer 55891e
-    [ -b "$md" ] || continue
Harald Hoyer 55891e
-    udevinfo="$(udevadm info --query=env --name=$md)"
Harald Hoyer 55891e
-    strstr "$udevinfo" "MD_UUID=" && continue
Harald Hoyer 55891e
-    strstr "$udevinfo" "MD_LEVEL=container" && continue
Harald Hoyer 55891e
-    strstr "$udevinfo" "DEVTYPE=partition" && continue
Harald Hoyer 55891e
-    mdadm --run "$md" 2>&1 | vinfo
Harald Hoyer 55891e
-done
Harald Hoyer 55891e
-unset udevinfo
Harald Hoyer 55891e
-
Harald Hoyer 55891e
-ln -s $(command -v mdraid-cleanup) $hookdir/pre-pivot/31-mdraid-cleanup.sh 2>/dev/null
Harald Hoyer 55891e
-udevadm control --start-exec-queue
Harald Hoyer 55891e
+_md_force_run() {
Harald Hoyer 55891e
+    local _udevinfo
Harald Hoyer 55891e
+    local _path_s
Harald Hoyer 55891e
+    local _path_d
Harald Hoyer 55891e
+    # try to force-run anything not running yet
Harald Hoyer 55891e
+    for md in /dev/md[0-9]*; do
Harald Hoyer 55891e
+        [ -b "$md" ] || continue
Harald Hoyer 55891e
+        _udevinfo="$(udevadm info --query=env --name="$md")"
Harald Hoyer 55891e
+        strstr "$_udevinfo" "MD_LEVEL=container" && continue
Harald Hoyer 55891e
+        strstr "$_udevinfo" "DEVTYPE=partition" && continue
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        _path_s="$(udevadm info -q path -n "$md")/md/array_state"
Harald Hoyer 55891e
+        [ ! -r "$_path_s" ] && continue
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        # inactive ?
Harald Hoyer 55891e
+        [ "$(cat "$_path_s")" != "inactive" ] && continue
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        mdadm -R "$md" 2>&1 | vinfo
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        # still inactive ?
Harald Hoyer 55891e
+        [ "$(cat "$_path_s")" = "inactive" ] && continue
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        _path_d="${_path_s%/*}/degraded"
Harald Hoyer 55891e
+        [ ! -r "$_path_d" ] && continue
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        # workaround for mdmon bug
Harald Hoyer 55891e
+        [ "$(cat "$_path_d")" -gt "0" ] && mdmon --takeover "$md"
Harald Hoyer 55891e
+    done
Harald Hoyer 55891e
+}
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+_md_force_run
Harald Hoyer 55891e
diff --git a/modules.d/90mdraid/module-setup.sh b/modules.d/90mdraid/module-setup.sh
Harald Hoyer 55891e
index 2dba8cb..cfc2a20 100755
Harald Hoyer 55891e
--- a/modules.d/90mdraid/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/90mdraid/module-setup.sh
Harald Hoyer 55891e
@@ -37,7 +37,7 @@ installkernel() {
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 install() {
Harald Hoyer 55891e
-    dracut_install mdadm partx
Harald Hoyer 55891e
+    dracut_install mdadm partx cat
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 
Harald Hoyer 55891e
      # XXX: mdmon really needs to run as non-root?
Harald Hoyer 55891e
diff --git a/modules.d/90mdraid/parse-md.sh b/modules.d/90mdraid/parse-md.sh
Harald Hoyer 55891e
index 6d1b615..63f3278 100755
Harald Hoyer 55891e
--- a/modules.d/90mdraid/parse-md.sh
Harald Hoyer 55891e
+++ b/modules.d/90mdraid/parse-md.sh
Harald Hoyer 55891e
@@ -34,6 +34,7 @@ fi
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 if ! getargbool 1 rd.md.conf -n rd_NO_MDADMCONF; then
Harald Hoyer 55891e
     rm -f /etc/mdadm/mdadm.conf /etc/mdadm.conf
Harald Hoyer 55891e
+    ln -s $(command -v mdraid-cleanup) $hookdir/pre-pivot/31-mdraid-cleanup.sh 2>/dev/null
Harald Hoyer 55891e
 fi
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 # noiswmd nodmraid for anaconda / rc.sysinit compatibility