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

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