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