|
|
38852f |
---
|
|
|
38852f |
libmultipath/discovery.c | 3 +
|
|
|
38852f |
libmultipath/wwids.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
38852f |
libmultipath/wwids.h | 1
|
|
|
38852f |
multipath/main.c | 26 ++++++++++++--
|
|
|
38852f |
multipath/multipath.8 | 5 ++
|
|
|
38852f |
5 files changed, 115 insertions(+), 6 deletions(-)
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/discovery.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/discovery.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/discovery.c
|
|
|
38852f |
@@ -53,7 +53,8 @@ store_pathinfo (vector pathvec, vector h
|
|
|
38852f |
goto out;
|
|
|
38852f |
}
|
|
|
38852f |
pp->udev = udev_device_ref(udevice);
|
|
|
38852f |
- err = pathinfo(pp, hwtable, flag | DI_BLACKLIST);
|
|
|
38852f |
+ err = pathinfo(pp, hwtable,
|
|
|
38852f |
+ (conf->dry_run == 3)? flag : (flag | DI_BLACKLIST));
|
|
|
38852f |
if (err)
|
|
|
38852f |
goto out;
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/wwids.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/wwids.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/wwids.c
|
|
|
38852f |
@@ -82,6 +82,92 @@ write_out_wwid(int fd, char *wwid) {
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
int
|
|
|
38852f |
+do_remove_wwid(int fd, char *str) {
|
|
|
38852f |
+ char buf[4097];
|
|
|
38852f |
+ char *ptr;
|
|
|
38852f |
+ off_t start = 0;
|
|
|
38852f |
+ int bytes;
|
|
|
38852f |
+
|
|
|
38852f |
+ while (1) {
|
|
|
38852f |
+ if (lseek(fd, start, SEEK_SET) < 0) {
|
|
|
38852f |
+ condlog(0, "wwid file read lseek failed : %s",
|
|
|
38852f |
+ strerror(errno));
|
|
|
38852f |
+ return -1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ bytes = read(fd, buf, 4096);
|
|
|
38852f |
+ if (bytes < 0) {
|
|
|
38852f |
+ if (errno == EINTR || errno == EAGAIN)
|
|
|
38852f |
+ continue;
|
|
|
38852f |
+ condlog(0, "failed to read from wwids file : %s",
|
|
|
38852f |
+ strerror(errno));
|
|
|
38852f |
+ return -1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ if (!bytes) /* didn't find wwid to remove */
|
|
|
38852f |
+ return 1;
|
|
|
38852f |
+ buf[bytes] = '\0';
|
|
|
38852f |
+ ptr = strstr(buf, str);
|
|
|
38852f |
+ if (ptr != NULL) {
|
|
|
38852f |
+ condlog(3, "found '%s'", str);
|
|
|
38852f |
+ if (lseek(fd, start + (ptr - buf), SEEK_SET) < 0) {
|
|
|
38852f |
+ condlog(0, "write lseek failed : %s",
|
|
|
38852f |
+ strerror(errno));
|
|
|
38852f |
+ return -1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ while (1) {
|
|
|
38852f |
+ if (write(fd, "#", 1) < 0) {
|
|
|
38852f |
+ if (errno == EINTR || errno == EAGAIN)
|
|
|
38852f |
+ continue;
|
|
|
38852f |
+ condlog(0, "failed to write to wwids file : %s", strerror(errno));
|
|
|
38852f |
+ return -1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ return 0;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ }
|
|
|
38852f |
+ ptr = strrchr(buf, '\n');
|
|
|
38852f |
+ if (ptr == NULL) { /* shouldn't happen, assume it is EOF */
|
|
|
38852f |
+ condlog(4, "couldn't find newline, assuming end of file");
|
|
|
38852f |
+ return 1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ start = start + (ptr - buf) + 1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+}
|
|
|
38852f |
+
|
|
|
38852f |
+
|
|
|
38852f |
+int
|
|
|
38852f |
+remove_wwid(char *wwid) {
|
|
|
38852f |
+ int fd, len, can_write;
|
|
|
38852f |
+ char *str;
|
|
|
38852f |
+ int ret = -1;
|
|
|
38852f |
+
|
|
|
38852f |
+ len = strlen(wwid) + 4; /* two slashes the newline and a zero byte */
|
|
|
38852f |
+ str = malloc(len);
|
|
|
38852f |
+ if (str == NULL) {
|
|
|
38852f |
+ condlog(0, "can't allocate memory to remove wwid : %s",
|
|
|
38852f |
+ strerror(errno));
|
|
|
38852f |
+ return -1;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ if (snprintf(str, len, "/%s/\n", wwid) >= len) {
|
|
|
38852f |
+ condlog(0, "string overflow trying to remove wwid");
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ condlog(3, "removing line '%s' from wwids file", str);
|
|
|
38852f |
+ fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER);
|
|
|
38852f |
+ if (fd < 0)
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+ if (!can_write) {
|
|
|
38852f |
+ condlog(0, "cannot remove wwid. wwids file is read-only");
|
|
|
38852f |
+ goto out_file;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ ret = do_remove_wwid(fd, str);
|
|
|
38852f |
+
|
|
|
38852f |
+out_file:
|
|
|
38852f |
+ close(fd);
|
|
|
38852f |
+out:
|
|
|
38852f |
+ free(str);
|
|
|
38852f |
+ return ret;
|
|
|
38852f |
+}
|
|
|
38852f |
+
|
|
|
38852f |
+int
|
|
|
38852f |
check_wwids_file(char *wwid, int write_wwid)
|
|
|
38852f |
{
|
|
|
38852f |
int fd, can_write, found, ret;
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/wwids.h
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/wwids.h
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/wwids.h
|
|
|
38852f |
@@ -15,5 +15,6 @@
|
|
|
38852f |
int should_multipath(struct path *pp, vector pathvec);
|
|
|
38852f |
int remember_wwid(char *wwid);
|
|
|
38852f |
int check_wwids_file(char *wwid, int write_wwid);
|
|
|
38852f |
+int remove_wwid(char *wwid);
|
|
|
38852f |
|
|
|
38852f |
#endif /* _WWIDS_H */
|
|
|
38852f |
Index: multipath-tools-130222/multipath/main.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/multipath/main.c
|
|
|
38852f |
+++ multipath-tools-130222/multipath/main.c
|
|
|
38852f |
@@ -83,7 +83,7 @@ usage (char * progname)
|
|
|
38852f |
{
|
|
|
38852f |
fprintf (stderr, VERSION_STRING);
|
|
|
38852f |
fprintf (stderr, "Usage:\n");
|
|
|
38852f |
- fprintf (stderr, " %s [-c] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
|
|
|
38852f |
+ fprintf (stderr, " %s [-c|-w] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
|
|
|
38852f |
fprintf (stderr, " %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);
|
|
|
38852f |
fprintf (stderr, " %s -F [-v lvl]\n", progname);
|
|
|
38852f |
fprintf (stderr, " %s -t\n", progname);
|
|
|
38852f |
@@ -104,6 +104,7 @@ usage (char * progname)
|
|
|
38852f |
" -B treat the bindings file as read only\n" \
|
|
|
38852f |
" -p policy failover|multibus|group_by_serial|group_by_prio\n" \
|
|
|
38852f |
" -b fil bindings file location\n" \
|
|
|
38852f |
+ " -w remove a device from the wwids file\n" \
|
|
|
38852f |
" -p pol force all maps to specified path grouping policy :\n" \
|
|
|
38852f |
" . failover one path per priority group\n" \
|
|
|
38852f |
" . multibus all paths in one priority group\n" \
|
|
|
38852f |
@@ -212,7 +213,6 @@ get_dm_mpvec (vector curmp, vector pathv
|
|
|
38852f |
|
|
|
38852f |
if (!conf->dry_run)
|
|
|
38852f |
reinstate_paths(mpp);
|
|
|
38852f |
- remember_wwid(mpp->wwid);
|
|
|
38852f |
}
|
|
|
38852f |
return 0;
|
|
|
38852f |
}
|
|
|
38852f |
@@ -262,7 +262,7 @@ configure (void)
|
|
|
38852f |
/*
|
|
|
38852f |
* if we have a blacklisted device parameter, exit early
|
|
|
38852f |
*/
|
|
|
38852f |
- if (dev && conf->dev_type == DEV_DEVNODE &&
|
|
|
38852f |
+ if (dev && conf->dev_type == DEV_DEVNODE && conf->dry_run != 3 &&
|
|
|
38852f |
(filter_devnode(conf->blist_devnode,
|
|
|
38852f |
conf->elist_devnode, dev) > 0)) {
|
|
|
38852f |
if (conf->dry_run == 2)
|
|
|
38852f |
@@ -284,6 +284,17 @@ configure (void)
|
|
|
38852f |
condlog(3, "scope is nul");
|
|
|
38852f |
goto out;
|
|
|
38852f |
}
|
|
|
38852f |
+ if (conf->dry_run == 3) {
|
|
|
38852f |
+ r = remove_wwid(refwwid);
|
|
|
38852f |
+ if (r == 0)
|
|
|
38852f |
+ printf("wwid '%s' removed\n", refwwid);
|
|
|
38852f |
+ else if (r == 1) {
|
|
|
38852f |
+ printf("wwid '%s' not in wwids file\n",
|
|
|
38852f |
+ refwwid);
|
|
|
38852f |
+ r = 0;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+ }
|
|
|
38852f |
condlog(3, "scope limited to %s", refwwid);
|
|
|
38852f |
if (conf->dry_run == 2) {
|
|
|
38852f |
if (check_wwids_file(refwwid, 0) == 0){
|
|
|
38852f |
@@ -439,7 +450,7 @@ main (int argc, char *argv[])
|
|
|
38852f |
if (dm_prereq())
|
|
|
38852f |
exit(1);
|
|
|
38852f |
|
|
|
38852f |
- while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:Brtq")) != EOF ) {
|
|
|
38852f |
+ while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:Brtqw")) != EOF ) {
|
|
|
38852f |
switch(arg) {
|
|
|
38852f |
case 1: printf("optarg : %s\n",optarg);
|
|
|
38852f |
break;
|
|
|
38852f |
@@ -504,6 +515,9 @@ main (int argc, char *argv[])
|
|
|
38852f |
case 'h':
|
|
|
38852f |
usage(argv[0]);
|
|
|
38852f |
exit(0);
|
|
|
38852f |
+ case 'w':
|
|
|
38852f |
+ conf->dry_run = 3;
|
|
|
38852f |
+ break;
|
|
|
38852f |
case ':':
|
|
|
38852f |
fprintf(stderr, "Missing option argument\n");
|
|
|
38852f |
usage(argv[0]);
|
|
|
38852f |
@@ -555,6 +569,10 @@ main (int argc, char *argv[])
|
|
|
38852f |
condlog(0, "the -c option requires a path to check");
|
|
|
38852f |
goto out;
|
|
|
38852f |
}
|
|
|
38852f |
+ if (conf->dry_run == 3 && !conf->dev) {
|
|
|
38852f |
+ condlog(0, "the -w option requires a device");
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+ }
|
|
|
38852f |
if (conf->remove == FLUSH_ONE) {
|
|
|
38852f |
if (conf->dev_type == DEV_DEVMAP) {
|
|
|
38852f |
r = dm_suspend_and_flush_map(conf->dev);
|
|
|
38852f |
Index: multipath-tools-130222/multipath/multipath.8
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/multipath/multipath.8
|
|
|
38852f |
+++ multipath-tools-130222/multipath/multipath.8
|
|
|
38852f |
@@ -8,7 +8,7 @@ multipath \- Device mapper target autoco
|
|
|
38852f |
.RB [\| \-b\ \c
|
|
|
38852f |
.IR bindings_file \|]
|
|
|
38852f |
.RB [\| \-d \|]
|
|
|
38852f |
-.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r \|]
|
|
|
38852f |
+.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \-w \|]
|
|
|
38852f |
.RB [\| \-p\ \c
|
|
|
38852f |
.BR failover | multibus | group_by_serial | group_by_prio | group_by_node_name \|]
|
|
|
38852f |
.RB [\| device \|]
|
|
|
38852f |
@@ -68,6 +68,9 @@ check if a block device should be a path
|
|
|
38852f |
.B \-q
|
|
|
38852f |
allow device tables with queue_if_no_path when multipathd is not running
|
|
|
38852f |
.TP
|
|
|
38852f |
+.B \-w
|
|
|
38852f |
+remove the wwid for the specified device from the wwids file
|
|
|
38852f |
+.TP
|
|
|
38852f |
.BI \-p " policy"
|
|
|
38852f |
force new maps to use the specified policy:
|
|
|
38852f |
.RS 1.2i
|