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

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