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