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