Blame SOURCES/0023-RH-multipath-wipe-wwid.patch

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