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