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

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