1From 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 517 6 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Fri, 717 8 Oct 2014 11:20:34 -0500 Subject: [PATCH] RH: add wwids from kernel 9cmdline 10 mpath.wwids with -A 11 12This patch adds another option to multipath, "-A", which reads 13/proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds 14to /etc/multipath/wwids. While this isn't usually important during 15normal operation, since these wwids should already be added, it can be 16helpful during installation, to make sure that multipath can claim 17devices as its own, before LVM or something else makes use of them. The 18patch also execs "/sbin/multipath -A" before running multipathd in 19multipathd.service 20 21Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> 22 23Upstream-Status: Pending 24 25Update this patch to new version 0.8.2 26 27Signed-off-by: Changqing Li <changqing.li@windriver.com> 28--- 29 libmultipath/wwids.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 30 libmultipath/wwids.h | 1 + 31 2 files changed, 45 insertions(+) 32 33diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c 34index 28a2150d..a0bfa851 100644 35--- a/libmultipath/wwids.c 36+++ b/libmultipath/wwids.c 37@@ -454,3 +454,47 @@ int op ## _wwid(const char *wwid) \ 38 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+{ 44+ FILE *f = NULL; 45+ char buf[LINE_MAX], *next, *ptr; 46+ int ret = 0; 47+ 48+ f = fopen("/proc/cmdline", "re"); 49+ if (!f) { 50+ condlog(0, "can't open /proc/cmdline : %s", strerror(errno)); 51+ return -1; 52+ } 53+ 54+ 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; 84+} 85diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h 86index 0c6ee54d..e32a0b0e 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, 97-- 982.17.1 99 100