5c6c2a
From 6ef3173e86c2be99b504f7c7a789dea5c0072f64 Mon Sep 17 00:00:00 2001
5c6c2a
From: Harald Hoyer <harald@redhat.com>
5c6c2a
Date: Mon, 10 Jul 2017 13:28:40 +0200
5c6c2a
Subject: [PATCH] add 90multipath-hostonly module
5c6c2a
5c6c2a
hardcoding the wwid of the drives in the initramfs causes problems
5c6c2a
when the drives are cloned to a system with the same hardware, but
5c6c2a
different disk wwid's
5c6c2a
5c6c2a
https://bugzilla.redhat.com/show_bug.cgi?id=1457311
5c6c2a
5c6c2a
Cherry-picked from: 5ce7cc7337a4c769b223152c083914f2052aa348
5c6c2a
Resolves: #1457311
5c6c2a
---
5c6c2a
 modules.d/90multipath-hostonly/module-setup.sh | 53 ++++++++++++++++++++++++++
5c6c2a
 modules.d/90multipath/module-setup.sh          | 26 -------------
5c6c2a
 2 files changed, 53 insertions(+), 26 deletions(-)
5c6c2a
 create mode 100755 modules.d/90multipath-hostonly/module-setup.sh
5c6c2a
5c6c2a
diff --git a/modules.d/90multipath-hostonly/module-setup.sh b/modules.d/90multipath-hostonly/module-setup.sh
5c6c2a
new file mode 100755
5c6c2a
index 00000000..88839033
5c6c2a
--- /dev/null
5c6c2a
+++ b/modules.d/90multipath-hostonly/module-setup.sh
5c6c2a
@@ -0,0 +1,53 @@
5c6c2a
+#!/bin/bash
5c6c2a
+
5c6c2a
+# called by dracut
5c6c2a
+check() {
5c6c2a
+    return 255
5c6c2a
+}
5c6c2a
+
5c6c2a
+# called by dracut
5c6c2a
+depends() {
5c6c2a
+    echo multipath
5c6c2a
+    return 0
5c6c2a
+}
5c6c2a
+
5c6c2a
+# called by dracut
5c6c2a
+install() {
5c6c2a
+    local _f _allow
5c6c2a
+
5c6c2a
+    is_mpath() {
5c6c2a
+        local _dev=$1
5c6c2a
+        [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
5c6c2a
+        [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
5c6c2a
+        return 1
5c6c2a
+    }
5c6c2a
+
5c6c2a
+    majmin_to_mpath_dev() {
5c6c2a
+        local _dev
5c6c2a
+        for i in /dev/mapper/*; do
5c6c2a
+            [[ $i == /dev/mapper/control ]] && continue
5c6c2a
+            _dev=$(get_maj_min $i)
5c6c2a
+            if [ "$_dev" = "$1" ]; then
5c6c2a
+                echo $i
5c6c2a
+                return
5c6c2a
+            fi
5c6c2a
+        done
5c6c2a
+    }
5c6c2a
+
5c6c2a
+    add_hostonly_mpath_conf() {
5c6c2a
+        is_mpath $1 && {
5c6c2a
+            local _dev
5c6c2a
+
5c6c2a
+            _dev=$(majmin_to_mpath_dev $1)
5c6c2a
+            [ -z "$_dev" ] && return
5c6c2a
+            strstr "$_allow" "$_dev" && return
5c6c2a
+            _allow="$_allow --allow $_dev"
5c6c2a
+        }
5c6c2a
+    }
5c6c2a
+
5c6c2a
+    [[ $hostonly ]] && {
5c6c2a
+        for_each_host_dev_and_slaves_all add_hostonly_mpath_conf
5c6c2a
+        [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf
5c6c2a
+    }
5c6c2a
+}
5c6c2a
+
5c6c2a
diff --git a/modules.d/90multipath/module-setup.sh b/modules.d/90multipath/module-setup.sh
5c6c2a
index 3983b7b7..232ddcd8 100755
5c6c2a
--- a/modules.d/90multipath/module-setup.sh
5c6c2a
+++ b/modules.d/90multipath/module-setup.sh
5c6c2a
@@ -9,17 +9,6 @@ is_mpath() {
5c6c2a
     return 1
5c6c2a
 }
5c6c2a
 
5c6c2a
-majmin_to_mpath_dev() {
5c6c2a
-    local _dev
5c6c2a
-    for i in /dev/mapper/*; do
5c6c2a
-        [[ $i == /dev/mapper/control ]] && continue
5c6c2a
-        _dev=$(get_maj_min $i)
5c6c2a
-        if [ "$_dev" = "$1" ]; then
5c6c2a
-            echo $i
5c6c2a
-            return
5c6c2a
-        fi
5c6c2a
-    done
5c6c2a
-}
5c6c2a
 
5c6c2a
 check() {
5c6c2a
     local _rootdev
5c6c2a
@@ -81,16 +70,6 @@ installkernel() {
5c6c2a
 
5c6c2a
 install() {
5c6c2a
     local _f _allow
5c6c2a
-    add_hostonly_mpath_conf() {
5c6c2a
-        is_mpath $1 && {
5c6c2a
-            local _dev
5c6c2a
-
5c6c2a
-            _dev=$(majmin_to_mpath_dev $1)
5c6c2a
-            [ -z "$_dev" ] && return
5c6c2a
-            strstr "$_allow" "$_dev" && return
5c6c2a
-            _allow="$_allow --allow $_dev"
5c6c2a
-        }
5c6c2a
-    }
5c6c2a
 
5c6c2a
     inst_multiple -o  \
5c6c2a
         dmsetup \
5c6c2a
@@ -105,11 +84,6 @@ install() {
5c6c2a
         /etc/multipath.conf \
5c6c2a
         /etc/multipath/*
5c6c2a
 
5c6c2a
-    [[ $hostonly ]] && {
5c6c2a
-        for_each_host_dev_and_slaves_all add_hostonly_mpath_conf
5c6c2a
-        [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf
5c6c2a
-    }
5c6c2a
-
5c6c2a
     inst $(command -v partx) /sbin/partx
5c6c2a
 
5c6c2a
     inst_libdir_file "libmultipath*" "multipath/*"