Blame SOURCES/0544-mdraid-wait-for-rd.md.uuid-specified-devices-to-be-a.patch

2d7ffa
From c9e0ee2c91de55a51d2afc6b0032f39f1f7f2ea8 Mon Sep 17 00:00:00 2001
2d7ffa
From: Harald Hoyer <harald@redhat.com>
2d7ffa
Date: Tue, 16 May 2017 11:31:26 +0200
2d7ffa
Subject: [PATCH] mdraid: wait for rd.md.uuid specified devices to be assembled
2d7ffa
2d7ffa
This patch uses wait_for_dev "/dev/disk/by-id/md-uuid-${uuid}" for the
2d7ffa
specified uuids.
2d7ffa
2d7ffa
On timeout only md devices are force started which are specified by
2d7ffa
uuid, or all, if rd.auto was specified.
2d7ffa
2d7ffa
Fixes https://github.com/dracutdevs/dracut/issues/227
2d7ffa
2d7ffa
Cherry-picked from: 3cea0658
2d7ffa
Resolves: #1451660
2d7ffa
---
49e6a8
 modules.d/90mdraid/mdraid_start.sh | 74 ++++++++++++++++++++++--------
2d7ffa
 modules.d/90mdraid/parse-md.sh     |  3 ++
2d7ffa
 2 files changed, 57 insertions(+), 20 deletions(-)
2d7ffa
2d7ffa
diff --git a/modules.d/90mdraid/mdraid_start.sh b/modules.d/90mdraid/mdraid_start.sh
2d7ffa
index 39998b03..5ebf09f4 100755
2d7ffa
--- a/modules.d/90mdraid/mdraid_start.sh
2d7ffa
+++ b/modules.d/90mdraid/mdraid_start.sh
2d7ffa
@@ -2,35 +2,69 @@
2d7ffa
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
2d7ffa
 # ex: ts=8 sw=4 sts=4 et filetype=sh
2d7ffa
 
2d7ffa
-type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
2d7ffa
-_md_force_run() {
2d7ffa
+type getargs >/dev/null 2>&1 || . /lib/dracut-lib.sh
2d7ffa
+
2d7ffa
+_md_start() {
2d7ffa
     local _udevinfo
2d7ffa
     local _path_s
2d7ffa
     local _path_d
2d7ffa
+    local _md="$1"
2d7ffa
+    local _offroot="$2"
2d7ffa
+
2d7ffa
+    _udevinfo="$(udevadm info --query=env --name="${_md}")"
2d7ffa
+    strstr "$_udevinfo" "MD_LEVEL=container" && continue
2d7ffa
+    strstr "$_udevinfo" "DEVTYPE=partition" && continue
2d7ffa
+
2d7ffa
+    _path_s="/sys/$(udevadm info -q path -n "${_md}")/md/array_state"
2d7ffa
+    [ ! -r "$_path_s" ] && continue
2d7ffa
+
2d7ffa
+    # inactive ?
2d7ffa
+    [ "$(cat "$_path_s")" != "inactive" ] && continue
2d7ffa
+
2d7ffa
+    mdadm $_offroot -R "${_md}" 2>&1 | vinfo
2d7ffa
+
2d7ffa
+    # still inactive ?
2d7ffa
+    [ "$(cat "$_path_s")" = "inactive" ] && continue
2d7ffa
+
2d7ffa
+    _path_d="${_path_s%/*}/degraded"
2d7ffa
+    [ ! -r "$_path_d" ] && continue
2d7ffa
+    > $hookdir/initqueue/work
2d7ffa
+}
2d7ffa
+
2d7ffa
+_md_force_run() {
2d7ffa
     local _offroot
2d7ffa
-    _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot)
2d7ffa
-    # try to force-run anything not running yet
2d7ffa
-    for md in /dev/md[0-9_]*; do
2d7ffa
-        [ -b "$md" ] || continue
2d7ffa
-        _udevinfo="$(udevadm info --query=env --name="$md")"
2d7ffa
-        strstr "$_udevinfo" "MD_LEVEL=container" && continue
2d7ffa
-        strstr "$_udevinfo" "DEVTYPE=partition" && continue
2d7ffa
+    local _md
2d7ffa
+    local _UUID
2d7ffa
+    local _MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=)
2d7ffa
+    [ -n "$_MD_UUID" ] || getargbool 0 rd.auto || return
2d7ffa
 
2d7ffa
-        _path_s="/sys/$(udevadm info -q path -n "$md")/md/array_state"
2d7ffa
-        [ ! -r "$_path_s" ] && continue
2d7ffa
+    _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot)
2d7ffa
 
2d7ffa
-        # inactive ?
2d7ffa
-        [ "$(cat "$_path_s")" != "inactive" ] && continue
2d7ffa
+    if [ -n "$_MD_UUID" ]; then
2d7ffa
+        for _md in /dev/md[0-9_]*; do
2d7ffa
+            [ -b "$_md" ] || continue
2d7ffa
+            _UUID=$(
2d7ffa
+                /sbin/mdadm -D --export "$_md" \
2d7ffa
+                    | while read line || [ -n "$line" ]; do
2d7ffa
+                    str_starts "$line" "MD_UUID=" || continue
2d7ffa
+                    printf "%s" "${line#MD_UUID=}"
2d7ffa
+                done
2d7ffa
+                )
2d7ffa
 
2d7ffa
-        mdadm $_offroot -R "$md" 2>&1 | vinfo
2d7ffa
+            [ -z "$_UUID" ] && continue
2d7ffa
 
2d7ffa
-        # still inactive ?
2d7ffa
-        [ "$(cat "$_path_s")" = "inactive" ] && continue
2d7ffa
+            # check if we should handle this device
2d7ffa
+            strstr " $_MD_UUID " " $_UUID " || continue
2d7ffa
 
2d7ffa
-        _path_d="${_path_s%/*}/degraded"
2d7ffa
-        [ ! -r "$_path_d" ] && continue
2d7ffa
-        > $hookdir/initqueue/work
2d7ffa
-    done
2d7ffa
+            _md_start "${_md}" "${_offroot}"
2d7ffa
+        done
2d7ffa
+    else
2d7ffa
+        # try to force-run anything not running yet
2d7ffa
+        for _md in /dev/md[0-9_]*; do
2d7ffa
+            [ -b "$_md" ] || continue
2d7ffa
+            _md_start "${_md}" "${_offroot}"
2d7ffa
+        done
2d7ffa
+    fi
2d7ffa
 }
2d7ffa
 
2d7ffa
 _md_force_run
2d7ffa
diff --git a/modules.d/90mdraid/parse-md.sh b/modules.d/90mdraid/parse-md.sh
2d7ffa
index dd7bda25..ae76bac1 100755
2d7ffa
--- a/modules.d/90mdraid/parse-md.sh
2d7ffa
+++ b/modules.d/90mdraid/parse-md.sh
2d7ffa
@@ -26,6 +26,9 @@ else
2d7ffa
             done < "${f}" > "${f}.new"
2d7ffa
             mv "${f}.new" "$f"
2d7ffa
         done
2d7ffa
+        for uuid in $MD_UUID; do
2d7ffa
+            wait_for_dev "/dev/disk/by-id/md-uuid-${uuid}"
2d7ffa
+        done
2d7ffa
     fi
2d7ffa
 fi
2d7ffa