Blame SOURCES/0012-RH-add-wwids-from-kernel-cmdline-mpath.wwids-with-A.patch

5c2e41
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5c2e41
From: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
Date: Fri, 17 Oct 2014 11:20:34 -0500
5c2e41
Subject: [PATCH] RH: add wwids from kernel cmdline mpath.wwids with -A
5c2e41
5c2e41
This patch adds another option to multipath, "-A", which reads
5c2e41
/proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds
5c2e41
to /etc/multipath/wwids.  While this isn't usually important during
5c2e41
normal operation, since these wwids should already be added, it can be
5c2e41
helpful during installation, to make sure that multipath can claim
5c2e41
devices as its own, before LVM or something else makes use of them.  The
5c2e41
patch also execs "/sbin/multipath -A" before running multipathd in
5c2e41
multipathd.service
5c2e41
5c2e41
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
---
5c2e41
 libmultipath/wwids.c          | 44 +++++++++++++++++++++++++++++++++++++++++++
5c2e41
 libmultipath/wwids.h          |  1 +
5c2e41
 multipath/main.c              | 10 ++++++++--
5c2e41
 multipath/multipath.8         |  5 ++++-
5c2e41
 multipathd/multipathd.service |  1 +
5c2e41
 5 files changed, 58 insertions(+), 3 deletions(-)
5c2e41
5c2e41
diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
5c2e41
index 53e7951..39e08cd 100644
5c2e41
--- a/libmultipath/wwids.c
5c2e41
+++ b/libmultipath/wwids.c
5c2e41
@@ -443,3 +443,47 @@ int op ## _wwid(const char *wwid) \
5c2e41
 declare_failed_wwid_op(is_failed, false)
5c2e41
 declare_failed_wwid_op(mark_failed, true)
5c2e41
 declare_failed_wwid_op(unmark_failed, true)
5c2e41
+
5c2e41
+int remember_cmdline_wwid(void)
5c2e41
+{
5c2e41
+	FILE *f = NULL;
5c2e41
+	char buf[LINE_MAX], *next, *ptr;
5c2e41
+	int ret = 0;
5c2e41
+
5c2e41
+	f = fopen("/proc/cmdline", "re");
5c2e41
+	if (!f) {
5c2e41
+		condlog(0, "can't open /proc/cmdline : %s", strerror(errno));
5c2e41
+		return -1;
5c2e41
+	}
5c2e41
+
5c2e41
+	if (!fgets(buf, sizeof(buf), f)) {
5c2e41
+		if (ferror(f))
5c2e41
+			condlog(0, "read of /proc/cmdline failed : %s",
5c2e41
+				strerror(errno));
5c2e41
+		else
5c2e41
+			condlog(0, "couldn't read /proc/cmdline");
5c2e41
+		fclose(f);
5c2e41
+		return -1;
5c2e41
+	}
5c2e41
+	fclose(f);
5c2e41
+	next = buf;
5c2e41
+	while((ptr = strstr(next, "mpath.wwid="))) {
5c2e41
+		ptr += 11;
5c2e41
+		next = strpbrk(ptr, " \t\n");
5c2e41
+		if (next) {
5c2e41
+			*next = '\0';
5c2e41
+			next++;
5c2e41
+		}
5c2e41
+		if (strlen(ptr)) {
5c2e41
+			if (remember_wwid(ptr) != 0)
5c2e41
+				ret = -1;
5c2e41
+		}
5c2e41
+		else {
5c2e41
+			condlog(0, "empty mpath.wwid kernel command line option");
5c2e41
+			ret = -1;
5c2e41
+		}
5c2e41
+		if (!next)
5c2e41
+			break;
5c2e41
+	}
5c2e41
+	return ret;
5c2e41
+}
5c2e41
diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h
5c2e41
index 0c6ee54..e32a0b0 100644
5c2e41
--- a/libmultipath/wwids.h
5c2e41
+++ b/libmultipath/wwids.h
5c2e41
@@ -17,6 +17,7 @@ int remember_wwid(char *wwid);
5c2e41
 int check_wwids_file(char *wwid, int write_wwid);
5c2e41
 int remove_wwid(char *wwid);
5c2e41
 int replace_wwids(vector mp);
5c2e41
+int remember_cmdline_wwid(void);
5c2e41
 
5c2e41
 enum {
5c2e41
 	WWID_IS_NOT_FAILED = 0,
5c2e41
diff --git a/multipath/main.c b/multipath/main.c
5c2e41
index ffa5b22..ccb6091 100644
5c2e41
--- a/multipath/main.c
5c2e41
+++ b/multipath/main.c
5c2e41
@@ -120,7 +120,7 @@ usage (char * progname)
5c2e41
 {
5c2e41
 	fprintf (stderr, VERSION_STRING);
5c2e41
 	fprintf (stderr, "Usage:\n");
5c2e41
-	fprintf (stderr, "  %s [-a|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
5c2e41
+	fprintf (stderr, "  %s [-a|-A|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
5c2e41
 	fprintf (stderr, "  %s -l|-ll|-f [-v lvl] [-b fil] [-R num] [dev]\n", progname);
5c2e41
 	fprintf (stderr, "  %s -F [-v lvl] [-R num]\n", progname);
5c2e41
 	fprintf (stderr, "  %s [-t|-T]\n", progname);
5c2e41
@@ -134,6 +134,8 @@ usage (char * progname)
5c2e41
 		"  -f      flush a multipath device map\n"
5c2e41
 		"  -F      flush all multipath device maps\n"
5c2e41
 		"  -a      add a device wwid to the wwids file\n"
5c2e41
+		"  -A      add devices from kernel command line mpath.wwids\n"
5c2e41
+		"          parameters to wwids file\n"
5c2e41
 		"  -c      check if a device should be a path in a multipath device\n"
5c2e41
 		"  -C      check if a multipath device has usable paths\n"
5c2e41
 		"  -q      allow queue_if_no_path when multipathd is not running\n"
5c2e41
@@ -868,7 +870,7 @@ main (int argc, char *argv[])
5c2e41
 		exit(1);
5c2e41
 	multipath_conf = conf;
5c2e41
 	conf->retrigger_tries = 0;
5c2e41
-	while ((arg = getopt(argc, argv, ":adcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
5c2e41
+	while ((arg = getopt(argc, argv, ":aAdcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) {
5c2e41
 		switch(arg) {
5c2e41
 		case 1: printf("optarg : %s\n",optarg);
5c2e41
 			break;
5c2e41
@@ -938,6 +940,10 @@ main (int argc, char *argv[])
5c2e41
 		case 'T':
5c2e41
 			cmd = CMD_DUMP_CONFIG;
5c2e41
 			break;
5c2e41
+		case 'A':
5c2e41
+			if (remember_cmdline_wwid() != 0)
5c2e41
+				exit(1);
5c2e41
+			exit(0);
5c2e41
 		case 'h':
5c2e41
 			usage(argv[0]);
5c2e41
 			exit(0);
5c2e41
diff --git a/multipath/multipath.8 b/multipath/multipath.8
5c2e41
index b5e5292..5bd5229 100644
5c2e41
--- a/multipath/multipath.8
5c2e41
+++ b/multipath/multipath.8
5c2e41
@@ -25,7 +25,7 @@ multipath \- Device mapper target autoconfig.
5c2e41
 .RB [\| \-b\ \c
5c2e41
 .IR bindings_file \|]
5c2e41
 .RB [\| \-d \|]
5c2e41
-.RB [\| \-h | \-l | \-ll | \-f | \-t | \-T | \-F | \-B | \-c | \-C | \-q | \-r | \-i | \-a | \-u | \-U | \-w | \-W \|]
5c2e41
+.RB [\| \-h | \-l | \-ll | \-f | \-t | \-T | \-F | \-B | \-c | \-C | \-q | \-r | \-i | \-a | \-A | \-u | \-U | \-w | \-W \|]
5c2e41
 .RB [\| \-p\ \c
5c2e41
 .IR failover | multibus | group_by_serial | group_by_prio | group_by_node_name \|]
5c2e41
 .RB [\| \-R\ \c
5c2e41
@@ -141,6 +141,9 @@ Add the WWID for the specified device to the WWIDs file.
5c2e41
 Check if the device specified in the program environment should be
5c2e41
 a path in a multipath device.
5c2e41
 .
5c2e41
+.B \-A
5c2e41
+add wwids from any kernel command line mpath.wwid parameters to the wwids file
5c2e41
+.
5c2e41
 .TP
5c2e41
 .B \-U
5c2e41
 Check if the device specified in the program environment is a multipath device
5c2e41
diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
5c2e41
index 17434ce..0fbcc46 100644
5c2e41
--- a/multipathd/multipathd.service
5c2e41
+++ b/multipathd/multipathd.service
5c2e41
@@ -15,6 +15,7 @@ Type=notify
5c2e41
 NotifyAccess=main
5c2e41
 LimitCORE=infinity
5c2e41
 ExecStartPre=-/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath
5c2e41
+ExecStartPre=-/sbin/multipath -A
5c2e41
 ExecStart=/sbin/multipathd -d -s
5c2e41
 ExecReload=/sbin/multipathd reconfigure
5c2e41
 TasksMax=infinity
5c2e41
-- 
5c2e41
2.7.4
5c2e41