Blame SOURCES/0024-RH-multipath-wipe-wwids.patch

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