Blame SOURCES/0016-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
---
a1c519
 libmultipath/wwids.c          | 44 +++++++++++++++++++++++++++++++++++
5c2e41
 libmultipath/wwids.h          |  1 +
a1c519
 multipath/main.c              | 10 ++++++--
a1c519
 multipath/multipath.8         |  7 +++++-
5c2e41
 multipathd/multipathd.service |  1 +
a1c519
 5 files changed, 60 insertions(+), 3 deletions(-)
5c2e41
5c2e41
diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
96a22b
index 28a2150d..fab6fc8f 100644
5c2e41
--- a/libmultipath/wwids.c
5c2e41
+++ b/libmultipath/wwids.c
96a22b
@@ -454,3 +454,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
8444ee
index 0c6ee54d..e32a0b0e 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
96a22b
index cf9d2a28..78822ee1 100644
5c2e41
--- a/multipath/main.c
5c2e41
+++ b/multipath/main.c
8444ee
@@ -138,7 +138,7 @@ usage (char * progname)
8444ee
 	fprintf (stderr, "  %s [-v level] [-R retries] -F\n", progname);
8444ee
 	fprintf (stderr, "  %s [-v level] [-l|-ll] [device]\n", progname);
8444ee
 	fprintf (stderr, "  %s [-v level] [-a|-w] device\n", progname);
8444ee
-	fprintf (stderr, "  %s [-v level] -W\n", progname);
8444ee
+	fprintf (stderr, "  %s [-v level] [-A|-W]\n", progname);
8444ee
 	fprintf (stderr, "  %s [-v level] [-i] [-c|-C] device\n", progname);
8444ee
 	fprintf (stderr, "  %s [-v level] [-i] [-u|-U]\n", progname);
8444ee
 	fprintf (stderr, "  %s [-h|-t|-T]\n", progname);
8444ee
@@ -151,6 +151,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"
96a22b
@@ -907,7 +909,7 @@ main (int argc, char *argv[])
5c2e41
 	multipath_conf = conf;
5c2e41
 	conf->retrigger_tries = 0;
96a22b
 	conf->force_sync = 1;
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;
96a22b
@@ -977,6 +979,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)
a1c519
+				exit(RTVL_FAIL);
a1c519
+			exit(RTVL_OK);
5c2e41
 		case 'h':
5c2e41
 			usage(argv[0]);
a1c519
 			exit(RTVL_OK);
5c2e41
diff --git a/multipath/multipath.8 b/multipath/multipath.8
8444ee
index 9cdd05a3..8befc45a 100644
5c2e41
--- a/multipath/multipath.8
5c2e41
+++ b/multipath/multipath.8
a1c519
@@ -63,7 +63,7 @@ multipath \- Device mapper target autoconfig.
a1c519
 .B multipath
a1c519
 .RB [\| \-v\ \c
a1c519
 .IR level \|]
a1c519
-.B -W
a1c519
+.RB [\| \-A | \-W \|]
5c2e41
 .
a1c519
 .LP
a1c519
 .B multipath
a1c519
@@ -145,6 +145,11 @@ device mapper, path checkers ...).
a1c519
 Add the WWID for the specified device to the WWIDs file.
a1c519
 .
a1c519
 .TP
5c2e41
+.B \-A
a1c519
+Add the WWIDs from any kernel command line \fImpath.wwid\fR parameters to the
a1c519
+WWIDs file.
5c2e41
+.
a1c519
+.TP
a1c519
 .B \-w
a1c519
 Remove the WWID for the specified device from the WWIDs file.
a1c519
 .
5c2e41
diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
8444ee
index 17434cef..0fbcc46b 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
-- 
a1c519
2.17.2
5c2e41