Blame 0018-90multipath-add-hostonly-multipath.conf-in-case-host.patch

Harald Hoyer 0840a3
From 77403e0032c0ca8bcd4c3951e3ead3bd8c23f8e6 Mon Sep 17 00:00:00 2001
Harald Hoyer 0840a3
From: Dave Young <dyoung@redhat.com>
Harald Hoyer 0840a3
Date: Mon, 6 Jul 2015 15:31:26 +0800
Harald Hoyer 0840a3
Subject: [PATCH] 90multipath: add hostonly multipath.conf in case hostonly
Harald Hoyer 0840a3
 mode
Harald Hoyer 0840a3
Harald Hoyer 0840a3
For large machine, suppose there's a lot of multipath devices, multipath layer
Harald Hoyer 0840a3
will use a lot of memory. For kdump kernel memory is very limited thus it causes
Harald Hoyer 0840a3
oom. To avoid oom, we only add necessary multipath devices in kdump kernel
Harald Hoyer 0840a3
multipath.conf.
Harald Hoyer 0840a3
Harald Hoyer 0840a3
This is done by use mpathconf --allow, a new option which is like whitelist.
Harald Hoyer 0840a3
Harald Hoyer 0840a3
Signed-off-by: Dave Young <dyoung@redhat.com>
Harald Hoyer 0840a3
---
Harald Hoyer 0840a3
 modules.d/90multipath/module-setup.sh | 42 ++++++++++++++++++++++++++++-------
Harald Hoyer 0840a3
 1 file changed, 34 insertions(+), 8 deletions(-)
Harald Hoyer 0840a3
Harald Hoyer 0840a3
diff --git a/modules.d/90multipath/module-setup.sh b/modules.d/90multipath/module-setup.sh
Harald Hoyer 0840a3
index 29643d4..321f13e 100755
Harald Hoyer 0840a3
--- a/modules.d/90multipath/module-setup.sh
Harald Hoyer 0840a3
+++ b/modules.d/90multipath/module-setup.sh
Harald Hoyer 0840a3
@@ -1,18 +1,28 @@
Harald Hoyer 0840a3
 #!/bin/bash
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
+is_mpath() {
Harald Hoyer 0840a3
+    local _dev=$1
Harald Hoyer 0840a3
+    [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
Harald Hoyer 0840a3
+    [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
Harald Hoyer 0840a3
+    return 1
Harald Hoyer 0840a3
+}
Harald Hoyer 0840a3
+
Harald Hoyer 0840a3
+majmin_to_mpath_dev() {
Harald Hoyer 0840a3
+    local _dev
Harald Hoyer 0840a3
+    for i in `ls -1 /dev/mapper/mpath*`; do
Harald Hoyer 0840a3
+        dev=$(get_maj_min $i)
Harald Hoyer 0840a3
+        if [ "$dev" = "$1" ]; then
Harald Hoyer 0840a3
+            echo $i
Harald Hoyer 0840a3
+            return
Harald Hoyer 0840a3
+        fi
Harald Hoyer 0840a3
+    done
Harald Hoyer 0840a3
+}
Harald Hoyer 0840a3
 # called by dracut
Harald Hoyer 0840a3
 check() {
Harald Hoyer 0840a3
     local _rootdev
Harald Hoyer 0840a3
     # if there's no multipath binary, no go.
Harald Hoyer 0840a3
     require_binaries multipath || return 1
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
-    is_mpath() {
Harald Hoyer 0840a3
-        local _dev=$1
Harald Hoyer 0840a3
-        [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
Harald Hoyer 0840a3
-        [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
Harald Hoyer 0840a3
-        return 1
Harald Hoyer 0840a3
-    }
Harald Hoyer 0840a3
-
Harald Hoyer 0840a3
     [[ $hostonly ]] || [[ $mount_needs ]] && {
Harald Hoyer 0840a3
         for_each_host_dev_and_slaves is_mpath || return 255
Harald Hoyer 0840a3
     }
Harald Hoyer 0840a3
@@ -79,7 +89,18 @@ installkernel() {
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
 # called by dracut
Harald Hoyer 0840a3
 install() {
Harald Hoyer 0840a3
-    local _f
Harald Hoyer 0840a3
+    local _f _allow
Harald Hoyer 0840a3
+    add_hostonly_mpath_conf() {
Harald Hoyer 0840a3
+        is_mpath $1 && {
Harald Hoyer 0840a3
+            local _dev
Harald Hoyer 0840a3
+
Harald Hoyer 0840a3
+            _dev=$(majmin_to_mpath_dev $1)
Harald Hoyer 0840a3
+            [ -z "$_dev" ] && return
Harald Hoyer 0840a3
+            strstr "$_allow" "$_dev" && return
Harald Hoyer 0840a3
+            _allow="$_allow --allow $_dev"
Harald Hoyer 0840a3
+        }
Harald Hoyer 0840a3
+    }
Harald Hoyer 0840a3
+
Harald Hoyer 0840a3
     inst_multiple -o  \
Harald Hoyer 0840a3
         dmsetup \
Harald Hoyer 0840a3
         kpartx \
Harald Hoyer 0840a3
@@ -93,6 +114,11 @@ install() {
Harald Hoyer 0840a3
         /etc/multipath.conf \
Harald Hoyer 0840a3
         /etc/multipath/*
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
+    [[ $hostonly ]] && {
Harald Hoyer 0840a3
+        for_each_host_dev_and_slaves_all add_hostonly_mpath_conf
Harald Hoyer 0840a3
+        [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf
Harald Hoyer 0840a3
+    }
Harald Hoyer 0840a3
+
Harald Hoyer 0840a3
     inst $(command -v partx) /sbin/partx
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
     inst_libdir_file "libmultipath*" "multipath/*"