ab0e4d
From 603f33e28cfad45c4bf9ade8e3ff3b9014b5bd4d Mon Sep 17 00:00:00 2001
ab0e4d
From: Ben Howard <ben.howard@redhat.com>
ab0e4d
Date: Fri, 3 Apr 2020 13:32:44 -0600
ab0e4d
Subject: [PATCH] multipath: add automatic configuration for multipath
ab0e4d
ab0e4d
Add support for 'rd.multipath=default' for using the default
ab0e4d
configuration on boot. The intended purpose for this is to help support
ab0e4d
ostree-based image boots from multipathed devices (such as Fedora and
ab0e4d
Red Hat CoreOS).
ab0e4d
ab0e4d
(cherry picked from commit b8a92b715677d52dbc2b27a710b9816fd8b9a63b)
ab0e4d
ab0e4d
Resolves: #1888779
ab0e4d
---
ab0e4d
 dracut.cmdline.7.asc                               |  3 +++
ab0e4d
 modules.d/90multipath/module-setup.sh              |  7 +++++--
ab0e4d
 modules.d/90multipath/multipathd-configure.service | 19 +++++++++++++++++++
ab0e4d
 modules.d/90multipath/multipathd.sh                |  5 +++++
ab0e4d
 4 files changed, 32 insertions(+), 2 deletions(-)
ab0e4d
ab0e4d
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
ab0e4d
index 4a7c2517..19b5cc87 100644
ab0e4d
--- a/dracut.cmdline.7.asc
ab0e4d
+++ b/dracut.cmdline.7.asc
ab0e4d
@@ -406,6 +406,9 @@ MULTIPATH
ab0e4d
 **rd.multipath=0**::
ab0e4d
    disable multipath detection
ab0e4d
 
ab0e4d
+**rd.multipath=default**::
ab0e4d
+   use default multipath settings
ab0e4d
+
ab0e4d
 FIPS
ab0e4d
 ~~~~
ab0e4d
 **rd.fips**::
ab0e4d
diff --git a/modules.d/90multipath/module-setup.sh b/modules.d/90multipath/module-setup.sh
ab0e4d
index 8a032c86..a7f250f3 100755
ab0e4d
--- a/modules.d/90multipath/module-setup.sh
ab0e4d
+++ b/modules.d/90multipath/module-setup.sh
ab0e4d
@@ -83,11 +83,12 @@ install() {
ab0e4d
         dmsetup \
ab0e4d
         kpartx \
ab0e4d
         mpath_wait \
ab0e4d
+        mpathconf \
ab0e4d
+        mpathpersist \
ab0e4d
         multipath  \
ab0e4d
         multipathd \
ab0e4d
-        mpathpersist \
ab0e4d
-        xdrgetuid \
ab0e4d
         xdrgetprio \
ab0e4d
+        xdrgetuid \
ab0e4d
         /etc/xdrdevices.conf \
ab0e4d
         /etc/multipath.conf \
ab0e4d
         /etc/multipath/* \
ab0e4d
@@ -109,7 +110,9 @@ install() {
ab0e4d
     fi
ab0e4d
 
ab0e4d
     if dracut_module_included "systemd"; then
ab0e4d
+        inst_simple "${moddir}/multipathd-configure.service" "${systemdsystemunitdir}/multipathd-configure.service"
ab0e4d
         inst_simple "${moddir}/multipathd.service" "${systemdsystemunitdir}/multipathd.service"
ab0e4d
+        systemctl -q --root "$initdir" enable multipathd-configure.service
ab0e4d
         systemctl -q --root "$initdir" enable multipathd.service
ab0e4d
     else
ab0e4d
         inst_hook pre-trigger 02 "$moddir/multipathd.sh"
ab0e4d
diff --git a/modules.d/90multipath/multipathd-configure.service b/modules.d/90multipath/multipathd-configure.service
ab0e4d
new file mode 100644
ab0e4d
index 00000000..de690615
ab0e4d
--- /dev/null
ab0e4d
+++ b/modules.d/90multipath/multipathd-configure.service
ab0e4d
@@ -0,0 +1,19 @@
ab0e4d
+[Unit]
ab0e4d
+Description=Device-Mapper Multipath Default Configuration
ab0e4d
+Before=iscsi.service iscsid.service lvm2-activation-early.service
ab0e4d
+Wants=systemd-udev-trigger.service systemd-udev-settle.service local-fs-pre.target
ab0e4d
+After=systemd-udev-trigger.service systemd-udev-settle.service
ab0e4d
+Before=local-fs-pre.target multipathd.service
ab0e4d
+DefaultDependencies=no
ab0e4d
+Conflicts=shutdown.target
ab0e4d
+
ab0e4d
+ConditionKernelCommandLine=rd.multipath=default
ab0e4d
+ConditionPathExists=!/etc/multipath.conf
ab0e4d
+
ab0e4d
+[Service]
ab0e4d
+Type=oneshot
ab0e4d
+ExecStartPre=-/usr/bin/mkdir -p /etc/multipath/multipath.conf.d
ab0e4d
+ExecStart=/usr/sbin/mpathconf --enable
ab0e4d
+
ab0e4d
+[Install]
ab0e4d
+WantedBy=sysinit.target
ab0e4d
diff --git a/modules.d/90multipath/multipathd.sh b/modules.d/90multipath/multipathd.sh
ab0e4d
index 2c2dcc85..936c5dc7 100755
ab0e4d
--- a/modules.d/90multipath/multipathd.sh
ab0e4d
+++ b/modules.d/90multipath/multipathd.sh
ab0e4d
@@ -1,5 +1,10 @@
ab0e4d
 #!/bin/sh
ab0e4d
 
ab0e4d
+if [ "$(getarg rd.multipath)x" == "default" ] && [ ! -e /etc/multipath.conf ]; then
ab0e4d
+    mkdir -p /etc/multipath/multipath.conf.d
ab0e4d
+    mpathconf --enable
ab0e4d
+fi
ab0e4d
+
ab0e4d
 if getargbool 1 rd.multipath -d -n rd_NO_MULTIPATH && [ -e /etc/multipath.conf ]; then
ab0e4d
     modprobe dm-multipath
ab0e4d
     multipathd -B || multipathd
ab0e4d