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

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