|
|
4728c8 |
---
|
|
|
4728c8 |
libmultipath/wwids.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
4728c8 |
libmultipath/wwids.h | 1 +
|
|
|
4728c8 |
multipath/main.c | 29 +++++++++++++++++++++++++++--
|
|
|
4728c8 |
multipath/multipath.8 | 5 ++++-
|
|
|
4728c8 |
4 files changed, 76 insertions(+), 3 deletions(-)
|
|
|
4728c8 |
|
|
|
4728c8 |
Index: multipath-tools-130222/libmultipath/wwids.c
|
|
|
4728c8 |
===================================================================
|
|
|
4728c8 |
--- multipath-tools-130222.orig/libmultipath/wwids.c
|
|
|
4728c8 |
+++ multipath-tools-130222/libmultipath/wwids.c
|
|
|
4728c8 |
@@ -82,6 +82,50 @@ write_out_wwid(int fd, char *wwid) {
|
|
|
4728c8 |
}
|
|
|
4728c8 |
|
|
|
4728c8 |
int
|
|
|
4728c8 |
+replace_wwids(vector mp)
|
|
|
4728c8 |
+{
|
|
|
4728c8 |
+ int i, fd, can_write;
|
|
|
4728c8 |
+ struct multipath * mpp;
|
|
|
4728c8 |
+ size_t len;
|
|
|
4728c8 |
+ int ret = -1;
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+ fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER);
|
|
|
4728c8 |
+ if (fd < 0)
|
|
|
4728c8 |
+ goto out;
|
|
|
4728c8 |
+ if (!can_write) {
|
|
|
4728c8 |
+ condlog(0, "cannot replace wwids. wwids file is read-only");
|
|
|
4728c8 |
+ goto out_file;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (ftruncate(fd, 0) < 0) {
|
|
|
4728c8 |
+ condlog(0, "cannot truncate wwids file : %s", strerror(errno));
|
|
|
4728c8 |
+ goto out_file;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ len = strlen(WWIDS_FILE_HEADER);
|
|
|
4728c8 |
+ if (write_all(fd, WWIDS_FILE_HEADER, len) != len) {
|
|
|
4728c8 |
+ condlog(0, "Can't write wwid file header : %s",
|
|
|
4728c8 |
+ strerror(errno));
|
|
|
4728c8 |
+ /* cleanup partially written header */
|
|
|
4728c8 |
+ if (ftruncate(fd, 0) < 0)
|
|
|
4728c8 |
+ condlog(0, "Cannot truncate header : %s",
|
|
|
4728c8 |
+ strerror(errno));
|
|
|
4728c8 |
+ goto out_file;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (!mp || !mp->allocated) {
|
|
|
4728c8 |
+ ret = 0;
|
|
|
4728c8 |
+ goto out_file;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ vector_foreach_slot(mp, mpp, i) {
|
|
|
4728c8 |
+ if (write_out_wwid(fd, mpp->wwid) < 0)
|
|
|
4728c8 |
+ goto out_file;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ ret = 0;
|
|
|
4728c8 |
+out_file:
|
|
|
4728c8 |
+ close(fd);
|
|
|
4728c8 |
+out:
|
|
|
4728c8 |
+ return ret;
|
|
|
4728c8 |
+}
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+int
|
|
|
4728c8 |
do_remove_wwid(int fd, char *str) {
|
|
|
4728c8 |
char buf[4097];
|
|
|
4728c8 |
char *ptr;
|
|
|
4728c8 |
Index: multipath-tools-130222/libmultipath/wwids.h
|
|
|
4728c8 |
===================================================================
|
|
|
4728c8 |
--- multipath-tools-130222.orig/libmultipath/wwids.h
|
|
|
4728c8 |
+++ multipath-tools-130222/libmultipath/wwids.h
|
|
|
4728c8 |
@@ -16,5 +16,6 @@ int should_multipath(struct path *pp, ve
|
|
|
4728c8 |
int remember_wwid(char *wwid);
|
|
|
4728c8 |
int check_wwids_file(char *wwid, int write_wwid);
|
|
|
4728c8 |
int remove_wwid(char *wwid);
|
|
|
4728c8 |
+int replace_wwids(vector mp);
|
|
|
4728c8 |
|
|
|
4728c8 |
#endif /* _WWIDS_H */
|
|
|
4728c8 |
Index: multipath-tools-130222/multipath/main.c
|
|
|
4728c8 |
===================================================================
|
|
|
4728c8 |
--- multipath-tools-130222.orig/multipath/main.c
|
|
|
4728c8 |
+++ multipath-tools-130222/multipath/main.c
|
|
|
4728c8 |
@@ -83,7 +83,7 @@ usage (char * progname)
|
|
|
4728c8 |
{
|
|
|
4728c8 |
fprintf (stderr, VERSION_STRING);
|
|
|
4728c8 |
fprintf (stderr, "Usage:\n");
|
|
|
4728c8 |
- fprintf (stderr, " %s [-c|-w] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
|
|
|
4728c8 |
+ fprintf (stderr, " %s [-c|-w|-W] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
|
|
|
4728c8 |
fprintf (stderr, " %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);
|
|
|
4728c8 |
fprintf (stderr, " %s -F [-v lvl]\n", progname);
|
|
|
4728c8 |
fprintf (stderr, " %s -t\n", progname);
|
|
|
4728c8 |
@@ -105,6 +105,7 @@ usage (char * progname)
|
|
|
4728c8 |
" -p policy failover|multibus|group_by_serial|group_by_prio\n" \
|
|
|
4728c8 |
" -b fil bindings file location\n" \
|
|
|
4728c8 |
" -w remove a device from the wwids file\n" \
|
|
|
4728c8 |
+ " -W reset the wwids file include only the current devices\n" \
|
|
|
4728c8 |
" -p pol force all maps to specified path grouping policy :\n" \
|
|
|
4728c8 |
" . failover one path per priority group\n" \
|
|
|
4728c8 |
" . multibus all paths in one priority group\n" \
|
|
|
4728c8 |
@@ -450,7 +451,7 @@ main (int argc, char *argv[])
|
|
|
4728c8 |
if (dm_prereq())
|
|
|
4728c8 |
exit(1);
|
|
|
4728c8 |
|
|
|
4728c8 |
- while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:Brtqw")) != EOF ) {
|
|
|
4728c8 |
+ while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtqwW")) != EOF ) {
|
|
|
4728c8 |
switch(arg) {
|
|
|
4728c8 |
case 1: printf("optarg : %s\n",optarg);
|
|
|
4728c8 |
break;
|
|
|
4728c8 |
@@ -518,6 +519,9 @@ main (int argc, char *argv[])
|
|
|
4728c8 |
case 'w':
|
|
|
4728c8 |
conf->dry_run = 3;
|
|
|
4728c8 |
break;
|
|
|
4728c8 |
+ case 'W':
|
|
|
4728c8 |
+ conf->dry_run = 4;
|
|
|
4728c8 |
+ break;
|
|
|
4728c8 |
case ':':
|
|
|
4728c8 |
fprintf(stderr, "Missing option argument\n");
|
|
|
4728c8 |
usage(argv[0]);
|
|
|
4728c8 |
@@ -573,6 +577,27 @@ main (int argc, char *argv[])
|
|
|
4728c8 |
condlog(0, "the -w option requires a device");
|
|
|
4728c8 |
goto out;
|
|
|
4728c8 |
}
|
|
|
4728c8 |
+ if (conf->dry_run == 4) {
|
|
|
4728c8 |
+ struct multipath * mpp;
|
|
|
4728c8 |
+ int i;
|
|
|
4728c8 |
+ vector curmp;
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+ curmp = vector_alloc();
|
|
|
4728c8 |
+ if (!curmp) {
|
|
|
4728c8 |
+ condlog(0, "can't allocate memory for mp list");
|
|
|
4728c8 |
+ goto out;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (dm_get_maps(curmp) == 0)
|
|
|
4728c8 |
+ r = replace_wwids(curmp);
|
|
|
4728c8 |
+ if (r == 0)
|
|
|
4728c8 |
+ printf("successfully reset wwids\n");
|
|
|
4728c8 |
+ vector_foreach_slot_backwards(curmp, mpp, i) {
|
|
|
4728c8 |
+ vector_del_slot(curmp, i);
|
|
|
4728c8 |
+ free_multipath(mpp, KEEP_PATHS);
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ vector_free(curmp);
|
|
|
4728c8 |
+ goto out;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
if (conf->remove == FLUSH_ONE) {
|
|
|
4728c8 |
if (conf->dev_type == DEV_DEVMAP) {
|
|
|
4728c8 |
r = dm_suspend_and_flush_map(conf->dev);
|
|
|
4728c8 |
Index: multipath-tools-130222/multipath/multipath.8
|
|
|
4728c8 |
===================================================================
|
|
|
4728c8 |
--- multipath-tools-130222.orig/multipath/multipath.8
|
|
|
4728c8 |
+++ multipath-tools-130222/multipath/multipath.8
|
|
|
4728c8 |
@@ -8,7 +8,7 @@ multipath \- Device mapper target autoco
|
|
|
4728c8 |
.RB [\| \-b\ \c
|
|
|
4728c8 |
.IR bindings_file \|]
|
|
|
4728c8 |
.RB [\| \-d \|]
|
|
|
4728c8 |
-.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \-w \|]
|
|
|
4728c8 |
+.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \-w | \-W \|]
|
|
|
4728c8 |
.RB [\| \-p\ \c
|
|
|
4728c8 |
.BR failover | multibus | group_by_serial | group_by_prio | group_by_node_name \|]
|
|
|
4728c8 |
.RB [\| device \|]
|
|
|
4728c8 |
@@ -71,6 +71,9 @@ allow device tables with queue_if_no_pat
|
|
|
4728c8 |
.B \-w
|
|
|
4728c8 |
remove the wwid for the specified device from the wwids file
|
|
|
4728c8 |
.TP
|
|
|
4728c8 |
+.B \-W
|
|
|
4728c8 |
+reset the wwids file to only include the current multipath devices
|
|
|
4728c8 |
+.TP
|
|
|
4728c8 |
.BI \-p " policy"
|
|
|
4728c8 |
force new maps to use the specified policy:
|
|
|
4728c8 |
.RS 1.2i
|