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

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