Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2 | From: Benjamin Marzinski <bmarzins@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 3 | Date: Fri, 17 Oct 2014 11:20:34 -0500 |
| 4 | Subject: [PATCH] RH: add wwids from kernel cmdline mpath.wwids with -A |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | |
| 6 | This patch adds another option to multipath, "-A", which reads |
| 7 | /proc/cmdline for mpath.wwid=<WWID> options, and adds any wwids it finds |
| 8 | to /etc/multipath/wwids. While this isn't usually important during |
| 9 | normal operation, since these wwids should already be added, it can be |
| 10 | helpful during installation, to make sure that multipath can claim |
| 11 | devices as its own, before LVM or something else makes use of them. The |
| 12 | patch also execs "/sbin/multipath -A" before running multipathd in |
| 13 | multipathd.service |
| 14 | |
| 15 | Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 16 | |
| 17 | Upstream-Status: Pending |
| 18 | |
| 19 | Update this patch to new version 0.8.0 |
| 20 | |
| 21 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | --- |
| 23 | libmultipath/wwids.c | 44 +++++++++++++++++++++++++++++++++++++++++++ |
| 24 | libmultipath/wwids.h | 1 + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 25 | multipath/main.c | 9 ++++++++- |
| 26 | multipath/multipath.8 | 3 +++ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | multipathd/multipathd.service | 1 + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 28 | 5 files changed, 57 insertions(+), 1 deletion(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | |
| 30 | diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 31 | index 53e7951..9ba9b62 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | --- a/libmultipath/wwids.c |
| 33 | +++ b/libmultipath/wwids.c |
| 34 | @@ -443,3 +443,47 @@ int op ## _wwid(const char *wwid) \ |
| 35 | declare_failed_wwid_op(is_failed, false) |
| 36 | declare_failed_wwid_op(mark_failed, true) |
| 37 | declare_failed_wwid_op(unmark_failed, true) |
| 38 | + |
| 39 | +int remember_cmdline_wwid(void) |
| 40 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 41 | + FILE *f = NULL; |
| 42 | + char buf[LINE_MAX], *next, *ptr; |
| 43 | + int ret = 0; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 44 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 45 | + f = fopen("/proc/cmdline", "re"); |
| 46 | + if (!f) { |
| 47 | + condlog(0, "can't open /proc/cmdline : %s", strerror(errno)); |
| 48 | + return -1; |
| 49 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 50 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 51 | + if (!fgets(buf, sizeof(buf), f)) { |
| 52 | + if (ferror(f)) |
| 53 | + condlog(0, "read of /proc/cmdline failed : %s", |
| 54 | + strerror(errno)); |
| 55 | + else |
| 56 | + condlog(0, "couldn't read /proc/cmdline"); |
| 57 | + fclose(f); |
| 58 | + return -1; |
| 59 | + } |
| 60 | + fclose(f); |
| 61 | + next = buf; |
| 62 | + while((ptr = strstr(next, "mpath.wwid="))) { |
| 63 | + ptr += 11; |
| 64 | + next = strpbrk(ptr, " \t\n"); |
| 65 | + if (next) { |
| 66 | + *next = '\0'; |
| 67 | + next++; |
| 68 | + } |
| 69 | + if (strlen(ptr)) { |
| 70 | + if (remember_wwid(ptr) != 0) |
| 71 | + ret = -1; |
| 72 | + } |
| 73 | + else { |
| 74 | + condlog(0, "empty mpath.wwid kernel command line option"); |
| 75 | + ret = -1; |
| 76 | + } |
| 77 | + if (!next) |
| 78 | + break; |
| 79 | + } |
| 80 | + return ret; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 81 | +} |
| 82 | diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h |
| 83 | index 0c6ee54..e32a0b0 100644 |
| 84 | --- a/libmultipath/wwids.h |
| 85 | +++ b/libmultipath/wwids.h |
| 86 | @@ -17,6 +17,7 @@ int remember_wwid(char *wwid); |
| 87 | int check_wwids_file(char *wwid, int write_wwid); |
| 88 | int remove_wwid(char *wwid); |
| 89 | int replace_wwids(vector mp); |
| 90 | +int remember_cmdline_wwid(void); |
| 91 | |
| 92 | enum { |
| 93 | WWID_IS_NOT_FAILED = 0, |
| 94 | diff --git a/multipath/main.c b/multipath/main.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 95 | index 5abb118..c751b31 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 96 | --- a/multipath/main.c |
| 97 | +++ b/multipath/main.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 98 | @@ -134,6 +134,7 @@ usage (char * progname) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | fprintf (stderr, VERSION_STRING); |
| 100 | fprintf (stderr, "Usage:\n"); |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 101 | fprintf (stderr, " %s [-a|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 102 | + fprintf (stderr, " %s [-a|-A|-c|-w|-W] [-d] [-r] [-i] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname); |
| 103 | fprintf (stderr, " %s -l|-ll|-f [-v lvl] [-b fil] [-R num] [dev]\n", progname); |
| 104 | fprintf (stderr, " %s -F [-v lvl] [-R num]\n", progname); |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 105 | fprintf (stderr, " %s [-t|-T]\n", progname); |
| 106 | @@ -147,6 +148,8 @@ usage (char * progname) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 107 | " -f flush a multipath device map\n" |
| 108 | " -F flush all multipath device maps\n" |
| 109 | " -a add a device wwid to the wwids file\n" |
| 110 | + " -A add devices from kernel command line mpath.wwids\n" |
| 111 | + " parameters to wwids file\n" |
| 112 | " -c check if a device should be a path in a multipath device\n" |
| 113 | " -C check if a multipath device has usable paths\n" |
| 114 | " -q allow queue_if_no_path when multipathd is not running\n" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 115 | @@ -870,7 +873,7 @@ main (int argc, char *argv[]) |
| 116 | exit(RTVL_FAIL); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 117 | multipath_conf = conf; |
| 118 | conf->retrigger_tries = 0; |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 119 | - while ((arg = getopt(argc, argv, ":adcChl::FfM:v:p:b:BrR:itTquUwW")) != EOF ) { |
| 120 | + 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] | 121 | switch(arg) { |
| 122 | case 1: printf("optarg : %s\n",optarg); |
| 123 | break; |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 124 | @@ -937,6 +940,10 @@ main (int argc, char *argv[]) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 125 | case 't': |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 126 | r = dump_config(conf, NULL, NULL) ? RTVL_FAIL : RTVL_OK; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 127 | goto out_free_config; |
| 128 | + case 'A': |
| 129 | + if (remember_cmdline_wwid() != 0) |
| 130 | + exit(1); |
| 131 | + exit(0); |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 132 | case 'T': |
| 133 | cmd = CMD_DUMP_CONFIG; |
| 134 | break; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 135 | diff --git a/multipath/multipath.8 b/multipath/multipath.8 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 136 | index 9cdd05a..1e120f3 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 137 | --- a/multipath/multipath.8 |
| 138 | +++ b/multipath/multipath.8 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 139 | @@ -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] | 140 | Check if the device specified in the program environment should be |
| 141 | a path in a multipath device. |
| 142 | . |
| 143 | +.B \-A |
| 144 | +add wwids from any kernel command line mpath.wwid parameters to the wwids file |
| 145 | +. |
| 146 | .TP |
| 147 | .B \-U |
| 148 | Check if the device specified in the program environment is a multipath device |
| 149 | diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service |
| 150 | index 17434ce..0fbcc46 100644 |
| 151 | --- a/multipathd/multipathd.service |
| 152 | +++ b/multipathd/multipathd.service |
| 153 | @@ -15,6 +15,7 @@ Type=notify |
| 154 | NotifyAccess=main |
| 155 | LimitCORE=infinity |
| 156 | ExecStartPre=-/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath |
| 157 | +ExecStartPre=-/sbin/multipath -A |
| 158 | ExecStart=/sbin/multipathd -d -s |
| 159 | ExecReload=/sbin/multipathd reconfigure |
| 160 | TasksMax=infinity |
| 161 | -- |
| 162 | 2.7.4 |
| 163 | |