Blame SOURCES/0327-multipath-add-hostonly-multipath.conf.patch

64b87c
From 3d1bd59eb09780fe156bb24fc6709ce844f68052 Mon Sep 17 00:00:00 2001
64b87c
From: Harald Hoyer <harald@redhat.com>
64b87c
Date: Tue, 25 Aug 2015 13:49:10 +0200
64b87c
Subject: [PATCH] multipath: add hostonly multipath.conf
64b87c
64b87c
Resolves: rhbz#994702
64b87c
---
64b87c
 modules.d/90multipath/module-setup.sh | 43 ++++++++++++++++++++++++++++-------
64b87c
 1 file changed, 35 insertions(+), 8 deletions(-)
64b87c
64b87c
diff --git a/modules.d/90multipath/module-setup.sh b/modules.d/90multipath/module-setup.sh
64b87c
index acfc56f..4971d18 100755
64b87c
--- a/modules.d/90multipath/module-setup.sh
64b87c
+++ b/modules.d/90multipath/module-setup.sh
64b87c
@@ -2,18 +2,29 @@
64b87c
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
64b87c
 # ex: ts=8 sw=4 sts=4 et filetype=sh
64b87c
 
64b87c
+is_mpath() {
64b87c
+    local _dev=$1
64b87c
+    [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
64b87c
+    [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
64b87c
+    return 1
64b87c
+}
64b87c
+
64b87c
+majmin_to_mpath_dev() {
64b87c
+    local _dev
64b87c
+    for i in `ls -1 /dev/mapper/mpath*`; do
64b87c
+        dev=$(get_maj_min $i)
64b87c
+        if [ "$dev" = "$1" ]; then
64b87c
+            echo $i
64b87c
+            return
64b87c
+        fi
64b87c
+    done
64b87c
+}
64b87c
+
64b87c
 check() {
64b87c
     local _rootdev
64b87c
     # if there's no multipath binary, no go.
64b87c
     require_binaries multipath || return 1
64b87c
 
64b87c
-    is_mpath() {
64b87c
-        local _dev=$1
64b87c
-        [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
64b87c
-        [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
64b87c
-        return 1
64b87c
-    }
64b87c
-
64b87c
     [[ $hostonly ]] || [[ $mount_needs ]] && {
64b87c
         for_each_host_dev_and_slaves is_mpath || return 255
64b87c
     }
64b87c
@@ -68,7 +79,18 @@ installkernel() {
64b87c
 }
64b87c
 
64b87c
 install() {
64b87c
-    local _f
64b87c
+    local _f _allow
64b87c
+    add_hostonly_mpath_conf() {
64b87c
+        is_mpath $1 && {
64b87c
+            local _dev
64b87c
+
64b87c
+            _dev=$(majmin_to_mpath_dev $1)
64b87c
+            [ -z "$_dev" ] && return
64b87c
+            strstr "$_allow" "$_dev" && return
64b87c
+            _allow="$_allow --allow $_dev"
64b87c
+        }
64b87c
+    }
64b87c
+
64b87c
     inst_multiple -o  \
64b87c
         dmsetup \
64b87c
         kpartx \
64b87c
@@ -82,6 +104,11 @@ install() {
64b87c
         /etc/multipath.conf \
64b87c
         /etc/multipath/*
64b87c
 
64b87c
+    [[ $hostonly ]] && {
64b87c
+        for_each_host_dev_and_slaves_all add_hostonly_mpath_conf
64b87c
+        [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf
64b87c
+    }
64b87c
+
64b87c
     inst $(command -v partx) /sbin/partx
64b87c
 
64b87c
     inst_libdir_file "libmultipath*" "multipath/*"