1From 0bf8ff8dab26201b268b419809844c07e168f17d Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Fri, 23 Nov 2018 17:25:15 +0800
4Subject: [PATCH] From 0000000000000000000000000000000000000000 Mon Sep 17
5 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Wed, 15
6 Oct 2014 10:39:30 -0500 Subject: [PATCH] RH: don't start without a config
7 file
8
9If /etc/multipath.conf doesn't exist, don't start multipathd and blacklist
10all devices when running multipath.  A completely blank configuration file
11is almost never what users want.  Also, people may have the multipath
12packages installed but don't want to use them.  This patch provides a
13simple way to disable multipath.  Simply removing or renaming
14/etc/multipath.conf will keep multipath from doing anything.
15
16Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17
18Upstream-Status: Pending
19
20update this patch to new version
21Signed-off-by: Changqing Li <changqing.li@windriver.com>
22---
23 libmultipath/config.c         | 18 ++++++++++++++++++
24 libmultipath/config.h         |  1 +
25 multipath/multipath.rules     |  1 +
26 multipathd/multipathd.8       |  2 ++
27 multipathd/multipathd.service |  1 +
28 5 files changed, 23 insertions(+)
29
30diff --git a/libmultipath/config.c b/libmultipath/config.c
31index 5af7af5..e4233f1 100644
32--- a/libmultipath/config.c
33+++ b/libmultipath/config.c
34@@ -26,6 +26,7 @@
35 #include "devmapper.h"
36 #include "mpath_cmd.h"
37 #include "propsel.h"
38+#include "version.h"
39
40 static int
41 hwe_strmatch (const struct hwentry *hwe1, const struct hwentry *hwe2)
42@@ -743,6 +745,23 @@ load_config (char * file)
43 			goto out;
44 		}
45 		factorize_hwtable(conf->hwtable, builtin_hwtable_size, file);
46+	} else {
47+		condlog(0, "/etc/multipath.conf does not exist, blacklisting all devices.");
48+		if (conf->blist_devnode == NULL) {
49+			conf->blist_devnode = vector_alloc();
50+			if (!conf->blist_devnode) {
51+				conf->blist_devnode = vector_alloc();
52+				if (!conf->blist_devnode) {
53+					condlog(0, "cannot allocate blacklist\n");
54+					goto out;
55+				}
56+			}
57+			if (store_ble(conf->blist_devnode, strdup(".*"),
58+				ORIGIN_NO_CONFIG)) {
59+				condlog(0, "cannot store default no-config blacklist\n");
60+				goto out;
61+			}
62+		}
63 	}
64
65 	conf->processed_main_config = 1;
66diff --git a/libmultipath/config.h b/libmultipath/config.h
67index 7d0cd9a..d7fb8e2 100644
68--- a/libmultipath/config.h
69+++ b/libmultipath/config.h
70@@ -9,6 +9,7 @@
71
72 #define ORIGIN_DEFAULT 0
73 #define ORIGIN_CONFIG  1
74+#define ORIGIN_NO_CONFIG 2
75
76 /*
77  * In kernel, fast_io_fail == 0 means immediate failure on rport delete.
78diff --git a/multipath/multipath.rules b/multipath/multipath.rules
79index 9df11a9..0486bf7 100644
80--- a/multipath/multipath.rules
81+++ b/multipath/multipath.rules
82@@ -9,6 +9,7 @@ IMPORT{cmdline}="nompath"
83 ENV{nompath}=="?*", GOTO="end_mpath"
84 IMPORT{cmdline}="multipath"
85 ENV{multipath}=="off", GOTO="end_mpath"
86+TEST!="/etc/multipath.conf", GOTO="end_mpath"
87
88 ENV{DEVTYPE}!="partition", GOTO="test_dev"
89 IMPORT{parent}="DM_MULTIPATH_DEVICE_PATH"
90diff --git a/multipathd/multipathd.8 b/multipathd/multipathd.8
91index 94c3f97..ed13efd 100644
92--- a/multipathd/multipathd.8
93+++ b/multipathd/multipathd.8
94@@ -38,6 +38,8 @@ map regains its maximum performance and redundancy.
95 This daemon executes the external \fBmultipath\fR tool when events occur.
96 In turn, the multipath tool signals the multipathd daemon when it is done with
97 devmap reconfiguration, so that it can refresh its failed path list.
98+
99+In this Linux distribution, multipathd does not run unless a /etc/multipath.conf file exists.
100 .
101 .
102 .\" ----------------------------------------------------------------------------
103diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
104index ba24983..17434ce 100644
105--- a/multipathd/multipathd.service
106+++ b/multipathd/multipathd.service
107@@ -4,6 +4,7 @@ Wants=systemd-udev-trigger.service systemd-udev-settle.service
108 Before=iscsi.service iscsid.service lvm2-activation-early.service
109 Before=local-fs-pre.target blk-availability.service
110 After=multipathd.socket systemd-udev-trigger.service systemd-udev-settle.service
111+ConditionPathExists=/etc/multipath.conf
112 DefaultDependencies=no
113 Conflicts=shutdown.target
114 ConditionKernelCommandLine=!nompath
115--
1162.7.4
117
118