blob: 724bef813a89d073710c8facf9e06e03775a420f [file] [log] [blame]
Brad Bishop00ab2372019-10-14 11:06:18 -04001From 0f54b3120ca06ff3168cdbf901a27b68c4638398 Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Thu, 26 Sep 2019 16:29:48 +0800
4Subject: [PATCH] From 0000000000000000000000000000000000000000 Mon Sep 17
5 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Fri, 17
6 Oct 2014 11:20:34 -0500 Subject: [PATCH] RH: add wwids from kernel cmdline
7 mpath.wwids with -A
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008
9This patch adds another option to multipath, "-A", which reads
10/proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds
11to /etc/multipath/wwids. While this isn't usually important during
12normal operation, since these wwids should already be added, it can be
13helpful during installation, to make sure that multipath can claim
14devices as its own, before LVM or something else makes use of them. The
15patch also execs "/sbin/multipath -A" before running multipathd in
16multipathd.service
17
18Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Brad Bishop19323692019-04-05 15:28:33 -040019
20Upstream-Status: Pending
21
Brad Bishop00ab2372019-10-14 11:06:18 -040022Update this patch to new version 0.8.2
Brad Bishop19323692019-04-05 15:28:33 -040023
24Signed-off-by: Changqing Li <changqing.li@windriver.com>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025---
26 libmultipath/wwids.c | 44 +++++++++++++++++++++++++++++++++++++++++++
27 libmultipath/wwids.h | 1 +
Brad Bishop19323692019-04-05 15:28:33 -040028 multipath/main.c | 9 ++++++++-
29 multipath/multipath.8 | 3 +++
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 multipathd/multipathd.service | 1 +
Brad Bishop19323692019-04-05 15:28:33 -040031 5 files changed, 57 insertions(+), 1 deletion(-)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032
33diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
Brad Bishop00ab2372019-10-14 11:06:18 -040034index ef74812..19c4d68 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035--- a/libmultipath/wwids.c
36+++ b/libmultipath/wwids.c
Brad Bishop00ab2372019-10-14 11:06:18 -040037@@ -444,3 +444,47 @@ int op ## _wwid(const char *wwid) \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038 declare_failed_wwid_op(is_failed, false)
39 declare_failed_wwid_op(mark_failed, true)
40 declare_failed_wwid_op(unmark_failed, true)
41+
42+int remember_cmdline_wwid(void)
43+{
Brad Bishop19323692019-04-05 15:28:33 -040044+ FILE *f = NULL;
45+ char buf[LINE_MAX], *next, *ptr;
46+ int ret = 0;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047+
Brad Bishop19323692019-04-05 15:28:33 -040048+ f = fopen("/proc/cmdline", "re");
49+ if (!f) {
50+ condlog(0, "can't open /proc/cmdline : %s", strerror(errno));
51+ return -1;
52+ }
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053+
Brad Bishop19323692019-04-05 15:28:33 -040054+ if (!fgets(buf, sizeof(buf), f)) {
55+ if (ferror(f))
56+ condlog(0, "read of /proc/cmdline failed : %s",
57+ strerror(errno));
58+ else
59+ condlog(0, "couldn't read /proc/cmdline");
60+ fclose(f);
61+ return -1;
62+ }
63+ fclose(f);
64+ next = buf;
65+ while((ptr = strstr(next, "mpath.wwid="))) {
66+ ptr += 11;
67+ next = strpbrk(ptr, " \t\n");
68+ if (next) {
69+ *next = '\0';
70+ next++;
71+ }
72+ if (strlen(ptr)) {
73+ if (remember_wwid(ptr) != 0)
74+ ret = -1;
75+ }
76+ else {
77+ condlog(0, "empty mpath.wwid kernel command line option");
78+ ret = -1;
79+ }
80+ if (!next)
81+ break;
82+ }
83+ return ret;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084+}
85diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h
86index 0c6ee54..e32a0b0 100644
87--- a/libmultipath/wwids.h
88+++ b/libmultipath/wwids.h
89@@ -17,6 +17,7 @@ int remember_wwid(char *wwid);
90 int check_wwids_file(char *wwid, int write_wwid);
91 int remove_wwid(char *wwid);
92 int replace_wwids(vector mp);
93+int remember_cmdline_wwid(void);
94
95 enum {
96 WWID_IS_NOT_FAILED = 0,
97diff --git a/multipath/main.c b/multipath/main.c
Brad Bishop00ab2372019-10-14 11:06:18 -040098index 96a1146..5fc65ef 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099--- a/multipath/main.c
100+++ b/multipath/main.c
Brad Bishop00ab2372019-10-14 11:06:18 -0400101@@ -139,6 +139,7 @@ usage (char * progname)
102 fprintf (stderr, " %s [-v level] [-l|-ll] [device]\n", progname);
103 fprintf (stderr, " %s [-v level] [-a|-w] device\n", progname);
104 fprintf (stderr, " %s [-v level] -W\n", progname);
105+ fprintf (stderr, " %s [-v level] -A\n", progname);
106 fprintf (stderr, " %s [-v level] [-i] [-c|-C] device\n", progname);
107 fprintf (stderr, " %s [-v level] [-i] [-u|-U]\n", progname);
108 fprintf (stderr, " %s [-h|-t|-T]\n", progname);
109@@ -151,6 +152,8 @@ usage (char * progname)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800110 " -f flush a multipath device map\n"
111 " -F flush all multipath device maps\n"
112 " -a add a device wwid to the wwids file\n"
Brad Bishop00ab2372019-10-14 11:06:18 -0400113+ " -A add devices from kernel command line mpath.wwids\n"
114+ " parameters to wwids file\n"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800115 " -c check if a device should be a path in a multipath device\n"
116 " -C check if a multipath device has usable paths\n"
117 " -q allow queue_if_no_path when multipathd is not running\n"
Brad Bishop00ab2372019-10-14 11:06:18 -0400118@@ -905,7 +908,7 @@ main (int argc, char *argv[])
Brad Bishop19323692019-04-05 15:28:33 -0400119 exit(RTVL_FAIL);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800120 multipath_conf = conf;
121 conf->retrigger_tries = 0;
Brad Bishop19323692019-04-05 15:28:33 -0400122- while ((arg = getopt(argc, argv, ":adcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
123+ while ((arg = getopt(argc, argv, ":aAdcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800124 switch(arg) {
125 case 1: printf("optarg : %s\n",optarg);
126 break;
Brad Bishop00ab2372019-10-14 11:06:18 -0400127@@ -998,6 +1001,10 @@ main (int argc, char *argv[])
128 case 'R':
129 retries = atoi(optarg);
130 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800131+ case 'A':
132+ if (remember_cmdline_wwid() != 0)
133+ exit(1);
134+ exit(0);
Brad Bishop00ab2372019-10-14 11:06:18 -0400135 case ':':
136 fprintf(stderr, "Missing option argument\n");
137 usage(argv[0]);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800138diff --git a/multipath/multipath.8 b/multipath/multipath.8
Brad Bishop19323692019-04-05 15:28:33 -0400139index 9cdd05a..1e120f3 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800140--- a/multipath/multipath.8
141+++ b/multipath/multipath.8
Brad Bishop19323692019-04-05 15:28:33 -0400142@@ -167,6 +167,9 @@ itself doesn't attempt to do I/O on the device.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800143 Check if the device specified in the program environment should be
144 a path in a multipath device.
145 .
146+.B \-A
147+add wwids from any kernel command line mpath.wwid parameters to the wwids file
148+.
149 .TP
150 .B \-U
151 Check if the device specified in the program environment is a multipath device
152diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
153index 17434ce..0fbcc46 100644
154--- a/multipathd/multipathd.service
155+++ b/multipathd/multipathd.service
156@@ -15,6 +15,7 @@ Type=notify
157 NotifyAccess=main
158 LimitCORE=infinity
159 ExecStartPre=-/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath
160+ExecStartPre=-/sbin/multipath -A
161 ExecStart=/sbin/multipathd -d -s
162 ExecReload=/sbin/multipathd reconfigure
163 TasksMax=infinity
164--
1652.7.4
166