<div dir="ltr"><div><div><div><div>Hannes,<br></div><br>would you Ack this one, or do you have some other idea for this in your tree ?<br><br></div>Best regards,<br></div>Christophe Varoqui<br></div><a href="http://www.opensvc.com">www.opensvc.com</a><br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 30, 2014 at 7:13 AM, Benjamin Marzinski <span dir="ltr"><<a href="mailto:bmarzins@redhat.com" target="_blank">bmarzins@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch adds another option to multipath, "-A", which reads<br>
/proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds to<br>
/etc/multipath/wwids.  While this isn't usually important during normal<br>
operation, since these wwids should already be added, it can be helpful<br>
during installation, to make sure that multipath can claim devices as its<br>
own, before LVM or something else makes use of them.  The patch also execs<br>
"/sbin/multipath -A" before running multipathd in multipathd.service<br>
<br>
Signed-off-by: Benjamin Marzinski <<a href="mailto:bmarzins@redhat.com">bmarzins@redhat.com</a>><br>
---<br>
 libmultipath/wwids.c          | 44 +++++++++++++++++++++++++++++++++++++++++++<br>
 libmultipath/wwids.h          |  1 +<br>
 multipath/main.c              | 10 ++++++++--<br>
 multipath/multipath.8         |  5 ++++-<br>
 multipathd/multipathd.service |  1 +<br>
 5 files changed, 58 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c<br>
index eca1799..1dc00bb 100644<br>
--- a/libmultipath/wwids.c<br>
+++ b/libmultipath/wwids.c<br>
@@ -274,3 +274,47 @@ remember_wwid(char *wwid)<br>
                condlog(4, "wwid %s already in wwids file", wwid);<br>
        return 0;<br>
 }<br>
+<br>
+int remember_cmdline_wwid(void)<br>
+{<br>
+       FILE *f = NULL;<br>
+       char buf[LINE_MAX], *next, *ptr;<br>
+       int ret = 0;<br>
+<br>
+       f = fopen("/proc/cmdline", "re");<br>
+       if (!f) {<br>
+               condlog(0, "can't open /proc/cmdline : %s", strerror(errno));<br>
+               return -1;<br>
+       }<br>
+<br>
+       if (!fgets(buf, sizeof(buf), f)) {<br>
+               if (ferror(f))<br>
+                       condlog(0, "read of /proc/cmdline failed : %s",<br>
+                               strerror(errno));<br>
+               else<br>
+                       condlog(0, "couldn't read /proc/cmdline");<br>
+               fclose(f);<br>
+               return -1;<br>
+       }<br>
+       fclose(f);<br>
+       next = buf;<br>
+       while((ptr = strstr(next, "mpath.wwid="))) {<br>
+               ptr += 11;<br>
+               next = strpbrk(ptr, " \t\n");<br>
+               if (next) {<br>
+                       *next = '\0';<br>
+                       next++;<br>
+               }<br>
+               if (strlen(ptr)) {<br>
+                       if (remember_wwid(ptr) != 0)<br>
+                               ret = -1;<br>
+               }<br>
+               else {<br>
+                       condlog(0, "empty mpath.wwid kernel command line option");<br>
+                       ret = -1;<br>
+               }<br>
+               if (!next)<br>
+                       break;<br>
+       }<br>
+       return ret;<br>
+}<br>
diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h<br>
index f3b21fa..2fbd419 100644<br>
--- a/libmultipath/wwids.h<br>
+++ b/libmultipath/wwids.h<br>
@@ -16,5 +16,6 @@ int remember_wwid(char *wwid);<br>
 int check_wwids_file(char *wwid, int write_wwid);<br>
 int remove_wwid(char *wwid);<br>
 int replace_wwids(vector mp);<br>
+int remember_cmdline_wwid(void);<br>
<br>
 #endif /* _WWIDS_H */<br>
diff --git a/multipath/main.c b/multipath/main.c<br>
index 157475e..ed93f66 100644<br>
--- a/multipath/main.c<br>
+++ b/multipath/main.c<br>
@@ -84,7 +84,7 @@ usage (char * progname)<br>
 {<br>
        fprintf (stderr, VERSION_STRING);<br>
        fprintf (stderr, "Usage:\n");<br>
-       fprintf (stderr, "  %s [-a|-c|-w|-W] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);<br>
+       fprintf (stderr, "  %s [-a|-A|-c|-w|-W] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);<br>
        fprintf (stderr, "  %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);<br>
        fprintf (stderr, "  %s -F [-v lvl]\n", progname);<br>
        fprintf (stderr, "  %s -t\n", progname);<br>
@@ -98,6 +98,8 @@ usage (char * progname)<br>
                "  -f      flush a multipath device map\n" \<br>
                "  -F      flush all multipath device maps\n" \<br>
                "  -a      add a device wwid to the wwids file\n" \<br>
+               "  -A      add devices from kernel command line mpath.wwids\n"<br>
+               "          parameters to wwids file\n" \<br>
                "  -c      check if a device should be a path in a multipath device\n" \<br>
                "  -q      allow queue_if_no_path when multipathd is not running\n"\<br>
                "  -d      dry run, do not create or update devmaps\n" \<br>
@@ -445,7 +447,7 @@ main (int argc, char *argv[])<br>
        if (load_config(DEFAULT_CONFIGFILE, udev))<br>
                exit(1);<br>
<br>
-       while ((arg = getopt(argc, argv, ":adchl::FfM:v:p:b:BrtqwW")) != EOF ) {<br>
+       while ((arg = getopt(argc, argv, ":aAdchl::FfM:v:p:b:BrtqwW")) != EOF ) {<br>
                switch(arg) {<br>
                case 1: printf("optarg : %s\n",optarg);<br>
                        break;<br>
@@ -518,6 +520,10 @@ main (int argc, char *argv[])<br>
                case 'a':<br>
                        conf->cmd = CMD_ADD_WWID;<br>
                        break;<br>
+               case 'A':<br>
+                       if (remember_cmdline_wwid() != 0)<br>
+                               exit(1);<br>
+                       exit(0);<br>
                case ':':<br>
                        fprintf(stderr, "Missing option argument\n");<br>
                        usage(argv[0]);<br>
diff --git a/multipath/multipath.8 b/multipath/multipath.8<br>
index b6479b1..f6b30c7 100644<br>
--- a/multipath/multipath.8<br>
+++ b/multipath/multipath.8<br>
@@ -8,7 +8,7 @@ multipath \- Device mapper target autoconfig<br>
 .RB [\| \-b\ \c<br>
 .IR bindings_file \|]<br>
 .RB [\| \-d \|]<br>
-.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \-a | \-w | \-W \|]<br>
+.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \-a | \-A | \-w | \-W \|]<br>
 .RB [\| \-p\ \c<br>
 .BR failover | multibus | group_by_serial | group_by_prio | group_by_node_name \|]<br>
 .RB [\| device \|]<br>
@@ -71,6 +71,9 @@ allow device tables with queue_if_no_path when multipathd is not running<br>
 .B \-a<br>
 add the wwid for the specified device to the wwids file<br>
 .TP<br>
+.B \-A<br>
+add wwids from any kernel command line mpath.wwid parameters to the wwids file<br>
+.TP<br>
 .B \-w<br>
 remove the wwid for the specified device from the wwids file<br>
 .TP<br>
diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service<br>
index be3ba3f..8bb48b5 100644<br>
--- a/multipathd/multipathd.service<br>
+++ b/multipathd/multipathd.service<br>
@@ -10,6 +10,7 @@ Type=notify<br>
 NotifyAccess=main<br>
 LimitCORE=infinity<br>
 ExecStartPre=/sbin/modprobe dm-multipath<br>
+ExecStartPre=-/sbin/multipath -A<br>
 ExecStart=/sbin/multipathd -d -s<br>
 ExecReload=/sbin/multipathd reconfigure<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.8.3.1<br>
<br>
</font></span></blockquote></div><br></div>