blob: 938262ba479099c7ffbc6a774cd5d872a184ec64 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002From: Benjamin Marzinski <bmarzins@redhat.com>
Brad Bishop19323692019-04-05 15:28:33 -04003Date: Fri, 17 Oct 2014 11:20:34 -0500
4Subject: [PATCH] RH: add wwids from kernel cmdline mpath.wwids with -A
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005
6This patch adds another option to multipath, "-A", which reads
7/proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds
8to /etc/multipath/wwids. While this isn't usually important during
9normal operation, since these wwids should already be added, it can be
10helpful during installation, to make sure that multipath can claim
11devices as its own, before LVM or something else makes use of them. The
12patch also execs "/sbin/multipath -A" before running multipathd in
13multipathd.service
14
15Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Brad Bishop19323692019-04-05 15:28:33 -040016
17Upstream-Status: Pending
18
19Update this patch to new version 0.8.0
20
21Signed-off-by: Changqing Li <changqing.li@windriver.com>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022---
23 libmultipath/wwids.c | 44 +++++++++++++++++++++++++++++++++++++++++++
24 libmultipath/wwids.h | 1 +
Brad Bishop19323692019-04-05 15:28:33 -040025 multipath/main.c | 9 ++++++++-
26 multipath/multipath.8 | 3 +++
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027 multipathd/multipathd.service | 1 +
Brad Bishop19323692019-04-05 15:28:33 -040028 5 files changed, 57 insertions(+), 1 deletion(-)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029
30diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
Brad Bishop19323692019-04-05 15:28:33 -040031index 53e7951..9ba9b62 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032--- a/libmultipath/wwids.c
33+++ b/libmultipath/wwids.c
34@@ -443,3 +443,47 @@ int op ## _wwid(const char *wwid) \
35 declare_failed_wwid_op(is_failed, false)
36 declare_failed_wwid_op(mark_failed, true)
37 declare_failed_wwid_op(unmark_failed, true)
38+
39+int remember_cmdline_wwid(void)
40+{
Brad Bishop19323692019-04-05 15:28:33 -040041+ FILE *f = NULL;
42+ char buf[LINE_MAX], *next, *ptr;
43+ int ret = 0;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044+
Brad Bishop19323692019-04-05 15:28:33 -040045+ f = fopen("/proc/cmdline", "re");
46+ if (!f) {
47+ condlog(0, "can't open /proc/cmdline : %s", strerror(errno));
48+ return -1;
49+ }
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050+
Brad Bishop19323692019-04-05 15:28:33 -040051+ if (!fgets(buf, sizeof(buf), f)) {
52+ if (ferror(f))
53+ condlog(0, "read of /proc/cmdline failed : %s",
54+ strerror(errno));
55+ else
56+ condlog(0, "couldn't read /proc/cmdline");
57+ fclose(f);
58+ return -1;
59+ }
60+ fclose(f);
61+ next = buf;
62+ while((ptr = strstr(next, "mpath.wwid="))) {
63+ ptr += 11;
64+ next = strpbrk(ptr, " \t\n");
65+ if (next) {
66+ *next = '\0';
67+ next++;
68+ }
69+ if (strlen(ptr)) {
70+ if (remember_wwid(ptr) != 0)
71+ ret = -1;
72+ }
73+ else {
74+ condlog(0, "empty mpath.wwid kernel command line option");
75+ ret = -1;
76+ }
77+ if (!next)
78+ break;
79+ }
80+ return ret;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081+}
82diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h
83index 0c6ee54..e32a0b0 100644
84--- a/libmultipath/wwids.h
85+++ b/libmultipath/wwids.h
86@@ -17,6 +17,7 @@ int remember_wwid(char *wwid);
87 int check_wwids_file(char *wwid, int write_wwid);
88 int remove_wwid(char *wwid);
89 int replace_wwids(vector mp);
90+int remember_cmdline_wwid(void);
91
92 enum {
93 WWID_IS_NOT_FAILED = 0,
94diff --git a/multipath/main.c b/multipath/main.c
Brad Bishop19323692019-04-05 15:28:33 -040095index 5abb118..c751b31 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080096--- a/multipath/main.c
97+++ b/multipath/main.c
Brad Bishop19323692019-04-05 15:28:33 -040098@@ -134,6 +134,7 @@ usage (char * progname)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099 fprintf (stderr, VERSION_STRING);
100 fprintf (stderr, "Usage:\n");
Brad Bishop19323692019-04-05 15:28:33 -0400101 fprintf (stderr, " %s [-a|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800102+ fprintf (stderr, " %s [-a|-A|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
103 fprintf (stderr, " %s -l|-ll|-f [-v lvl] [-b fil] [-R num] [dev]\n", progname);
104 fprintf (stderr, " %s -F [-v lvl] [-R num]\n", progname);
Brad Bishop19323692019-04-05 15:28:33 -0400105 fprintf (stderr, " %s [-t|-T]\n", progname);
106@@ -147,6 +148,8 @@ usage (char * progname)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107 " -f flush a multipath device map\n"
108 " -F flush all multipath device maps\n"
109 " -a add a device wwid to the wwids file\n"
110+ " -A add devices from kernel command line mpath.wwids\n"
111+ " parameters to wwids file\n"
112 " -c check if a device should be a path in a multipath device\n"
113 " -C check if a multipath device has usable paths\n"
114 " -q allow queue_if_no_path when multipathd is not running\n"
Brad Bishop19323692019-04-05 15:28:33 -0400115@@ -870,7 +873,7 @@ main (int argc, char *argv[])
116 exit(RTVL_FAIL);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800117 multipath_conf = conf;
118 conf->retrigger_tries = 0;
Brad Bishop19323692019-04-05 15:28:33 -0400119- while ((arg = getopt(argc, argv, ":adcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
120+ while ((arg = getopt(argc, argv, ":aAdcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800121 switch(arg) {
122 case 1: printf("optarg : %s\n",optarg);
123 break;
Brad Bishop19323692019-04-05 15:28:33 -0400124@@ -937,6 +940,10 @@ main (int argc, char *argv[])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800125 case 't':
Brad Bishop19323692019-04-05 15:28:33 -0400126 r = dump_config(conf, NULL, NULL) ? RTVL_FAIL : RTVL_OK;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800127 goto out_free_config;
128+ case 'A':
129+ if (remember_cmdline_wwid() != 0)
130+ exit(1);
131+ exit(0);
Brad Bishop19323692019-04-05 15:28:33 -0400132 case 'T':
133 cmd = CMD_DUMP_CONFIG;
134 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800135diff --git a/multipath/multipath.8 b/multipath/multipath.8
Brad Bishop19323692019-04-05 15:28:33 -0400136index 9cdd05a..1e120f3 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137--- a/multipath/multipath.8
138+++ b/multipath/multipath.8
Brad Bishop19323692019-04-05 15:28:33 -0400139@@ -167,6 +167,9 @@ itself doesn't attempt to do I/O on the device.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800140 Check if the device specified in the program environment should be
141 a path in a multipath device.
142 .
143+.B \-A
144+add wwids from any kernel command line mpath.wwid parameters to the wwids file
145+.
146 .TP
147 .B \-U
148 Check if the device specified in the program environment is a multipath device
149diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
150index 17434ce..0fbcc46 100644
151--- a/multipathd/multipathd.service
152+++ b/multipathd/multipathd.service
153@@ -15,6 +15,7 @@ Type=notify
154 NotifyAccess=main
155 LimitCORE=infinity
156 ExecStartPre=-/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath
157+ExecStartPre=-/sbin/multipath -A
158 ExecStart=/sbin/multipathd -d -s
159 ExecReload=/sbin/multipathd reconfigure
160 TasksMax=infinity
161--
1622.7.4
163