Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 1 | From 0f54b3120ca06ff3168cdbf901a27b68c4638398 Mon Sep 17 00:00:00 2001 |
| 2 | From: Changqing Li <changqing.li@windriver.com> |
| 3 | Date: Thu, 26 Sep 2019 16:29:48 +0800 |
| 4 | Subject: [PATCH] From 0000000000000000000000000000000000000000 Mon Sep 17 |
| 5 | 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Fri, 17 |
| 6 | Oct 2014 11:20:34 -0500 Subject: [PATCH] RH: add wwids from kernel cmdline |
| 7 | mpath.wwids with -A |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | |
| 9 | This patch adds another option to multipath, "-A", which reads |
| 10 | /proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds |
| 11 | to /etc/multipath/wwids. While this isn't usually important during |
| 12 | normal operation, since these wwids should already be added, it can be |
| 13 | helpful during installation, to make sure that multipath can claim |
| 14 | devices as its own, before LVM or something else makes use of them. The |
| 15 | patch also execs "/sbin/multipath -A" before running multipathd in |
| 16 | multipathd.service |
| 17 | |
| 18 | Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 19 | |
| 20 | Upstream-Status: Pending |
| 21 | |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 22 | Update this patch to new version 0.8.2 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 23 | |
| 24 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | --- |
| 26 | libmultipath/wwids.c | 44 +++++++++++++++++++++++++++++++++++++++++++ |
| 27 | libmultipath/wwids.h | 1 + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | multipath/main.c | 9 ++++++++- |
| 29 | multipath/multipath.8 | 3 +++ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | multipathd/multipathd.service | 1 + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 31 | 5 files changed, 57 insertions(+), 1 deletion(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | |
| 33 | diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 34 | index ef74812..19c4d68 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 35 | --- a/libmultipath/wwids.c |
| 36 | +++ b/libmultipath/wwids.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 37 | @@ -444,3 +444,47 @@ int op ## _wwid(const char *wwid) \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 44 | + FILE *f = NULL; |
| 45 | + char buf[LINE_MAX], *next, *ptr; |
| 46 | + int ret = 0; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | + f = fopen("/proc/cmdline", "re"); |
| 49 | + if (!f) { |
| 50 | + condlog(0, "can't open /proc/cmdline : %s", strerror(errno)); |
| 51 | + return -1; |
| 52 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 84 | +} |
| 85 | diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h |
| 86 | index 0c6ee54..e32a0b0 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 | diff --git a/multipath/main.c b/multipath/main.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 98 | index 96a1146..5fc65ef 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | --- a/multipath/main.c |
| 100 | +++ b/multipath/main.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 101 | @@ -139,6 +139,7 @@ usage (char * progname) |
| 102 | fprintf (stderr, " %s [-v level] [-l|-ll] [device]\n", progname); |
| 103 | fprintf (stderr, " %s [-v level] [-a|-w] device\n", progname); |
| 104 | fprintf (stderr, " %s [-v level] -W\n", progname); |
| 105 | + fprintf (stderr, " %s [-v level] -A\n", progname); |
| 106 | fprintf (stderr, " %s [-v level] [-i] [-c|-C] device\n", progname); |
| 107 | fprintf (stderr, " %s [-v level] [-i] [-u|-U]\n", progname); |
| 108 | fprintf (stderr, " %s [-h|-t|-T]\n", progname); |
| 109 | @@ -151,6 +152,8 @@ usage (char * progname) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 110 | " -f flush a multipath device map\n" |
| 111 | " -F flush all multipath device maps\n" |
| 112 | " -a add a device wwid to the wwids file\n" |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 113 | + " -A add devices from kernel command line mpath.wwids\n" |
| 114 | + " parameters to wwids file\n" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 115 | " -c check if a device should be a path in a multipath device\n" |
| 116 | " -C check if a multipath device has usable paths\n" |
| 117 | " -q allow queue_if_no_path when multipathd is not running\n" |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 118 | @@ -905,7 +908,7 @@ main (int argc, char *argv[]) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 119 | exit(RTVL_FAIL); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 120 | multipath_conf = conf; |
| 121 | conf->retrigger_tries = 0; |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 122 | - while ((arg = getopt(argc, argv, ":adcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) { |
| 123 | + while ((arg = getopt(argc, argv, ":aAdcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 124 | switch(arg) { |
| 125 | case 1: printf("optarg : %s\n",optarg); |
| 126 | break; |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 127 | @@ -998,6 +1001,10 @@ main (int argc, char *argv[]) |
| 128 | case 'R': |
| 129 | retries = atoi(optarg); |
| 130 | break; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 131 | + case 'A': |
| 132 | + if (remember_cmdline_wwid() != 0) |
| 133 | + exit(1); |
| 134 | + exit(0); |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 135 | case ':': |
| 136 | fprintf(stderr, "Missing option argument\n"); |
| 137 | usage(argv[0]); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 138 | diff --git a/multipath/multipath.8 b/multipath/multipath.8 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 139 | index 9cdd05a..1e120f3 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 140 | --- a/multipath/multipath.8 |
| 141 | +++ b/multipath/multipath.8 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 142 | @@ -167,6 +167,9 @@ itself doesn't attempt to do I/O on the device. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 143 | Check if the device specified in the program environment should be |
| 144 | a path in a multipath device. |
| 145 | . |
| 146 | +.B \-A |
| 147 | +add wwids from any kernel command line mpath.wwid parameters to the wwids file |
| 148 | +. |
| 149 | .TP |
| 150 | .B \-U |
| 151 | Check if the device specified in the program environment is a multipath device |
| 152 | diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service |
| 153 | index 17434ce..0fbcc46 100644 |
| 154 | --- a/multipathd/multipathd.service |
| 155 | +++ b/multipathd/multipathd.service |
| 156 | @@ -15,6 +15,7 @@ Type=notify |
| 157 | NotifyAccess=main |
| 158 | LimitCORE=infinity |
| 159 | ExecStartPre=-/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath |
| 160 | +ExecStartPre=-/sbin/multipath -A |
| 161 | ExecStart=/sbin/multipathd -d -s |
| 162 | ExecReload=/sbin/multipathd reconfigure |
| 163 | TasksMax=infinity |
| 164 | -- |
| 165 | 2.7.4 |
| 166 | |