Blame SOURCES/0101-RH-cleanup-partmaps-code.patch

4728c8
---
4728c8
 libmultipath/devmapper.c |  155 ++++++++++++++++++-----------------------------
4728c8
 1 file changed, 61 insertions(+), 94 deletions(-)
4728c8
4728c8
Index: multipath-tools-130222/libmultipath/devmapper.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/libmultipath/devmapper.c
4728c8
+++ multipath-tools-130222/libmultipath/devmapper.c
4728c8
@@ -1006,8 +1006,9 @@ bad:
4728c8
 	return NULL;
4728c8
 }
4728c8
 
4728c8
-int
4728c8
-dm_remove_partmaps (const char * mapname, int need_sync)
4728c8
+static int
4728c8
+do_foreach_partmaps (const char * mapname, int (*partmap_func)(char *, void *),
4728c8
+		     void *data)
4728c8
 {
4728c8
 	struct dm_task *dmt;
4728c8
 	struct dm_names *names;
4728c8
@@ -1059,26 +1060,8 @@ dm_remove_partmaps (const char * mapname
4728c8
 		     */
4728c8
 		    strstr(params, dev_t)
4728c8
 		   ) {
4728c8
-			/*
4728c8
-			 * then it's a kpartx generated partition.
4728c8
-			 * remove it.
4728c8
-			 */
4728c8
-			/*
4728c8
-			 * if the opencount is 0 maybe some other
4728c8
-			 * partitions depend on it.
4728c8
-			 */
4728c8
-			if (dm_get_opencount(names->name)) {
4728c8
-				dm_remove_partmaps(names->name, need_sync);
4728c8
-				if (dm_get_opencount(names->name)) {
4728c8
-					condlog(2, "%s: map in use",
4728c8
-						names->name);
4728c8
-					goto out;
4728c8
-				}
4728c8
-			}
4728c8
-			condlog(4, "partition map %s removed",
4728c8
-				names->name);
4728c8
-			dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
4728c8
-					   need_sync, 0);
4728c8
+			if (partmap_func(names->name, data) != 0)
4728c8
+				goto out;
4728c8
 		}
4728c8
 
4728c8
 		next = names->next;
4728c8
@@ -1091,6 +1074,35 @@ out:
4728c8
 	return r;
4728c8
 }
4728c8
 
4728c8
+struct remove_data {
4728c8
+	int need_sync;
4728c8
+};
4728c8
+
4728c8
+static int
4728c8
+remove_partmap(char *name, void *data)
4728c8
+{
4728c8
+	struct remove_data *rd = (struct remove_data *)data;
4728c8
+
4728c8
+	if (dm_get_opencount(name)) {
4728c8
+		dm_remove_partmaps(name, rd->need_sync);
4728c8
+		if (dm_get_opencount(name)) {
4728c8
+			condlog(2, "%s: map in use", name);
4728c8
+			return 1;
4728c8
+		}
4728c8
+	}
4728c8
+	condlog(4, "partition map %s removed", name);
4728c8
+	dm_simplecmd_flush(DM_DEVICE_REMOVE, name,
4728c8
+			   rd->need_sync, 0);
4728c8
+	return 0;
4728c8
+}
4728c8
+
4728c8
+int
4728c8
+dm_remove_partmaps (const char * mapname, int need_sync)
4728c8
+{
4728c8
+	struct remove_data rd = { need_sync };
4728c8
+	return do_foreach_partmaps(mapname, remove_partmap, &rd);
4728c8
+}
4728c8
+
4728c8
 static struct dm_info *
4728c8
 alloc_dminfo (void)
4728c8
 {
4728c8
@@ -1140,86 +1152,41 @@ out:
4728c8
 	return r;
4728c8
 }
4728c8
 
4728c8
-int
4728c8
-dm_rename_partmaps (char * old, char * new)
4728c8
+struct rename_data {
4728c8
+	char *old;
4728c8
+	char *new;
4728c8
+	char *delim;
4728c8
+};
4728c8
+
4728c8
+static int
4728c8
+rename_partmap (char *name, void *data)
4728c8
 {
4728c8
-	struct dm_task *dmt;
4728c8
-	struct dm_names *names;
4728c8
-	unsigned next = 0;
4728c8
 	char buff[PARAMS_SIZE];
4728c8
-	unsigned long long size;
4728c8
-	char dev_t[32];
4728c8
-	int r = 1;
4728c8
 	int offset;
4728c8
-	char *delim;
4728c8
-
4728c8
-	if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
4728c8
-		return 1;
4728c8
+	struct rename_data *rd = (struct rename_data *)data;
4728c8
 
4728c8
-	dm_task_no_open_count(dmt);
4728c8
-
4728c8
-	if (!dm_task_run(dmt))
4728c8
-		goto out;
4728c8
-
4728c8
-	if (!(names = dm_task_get_names(dmt)))
4728c8
-		goto out;
4728c8
-
4728c8
-	if (!names->dev) {
4728c8
-		r = 0; /* this is perfectly valid */
4728c8
-		goto out;
4728c8
-	}
4728c8
+	if (strncmp(name, rd->old, strlen(rd->old)) != 0)
4728c8
+		return 0;
4728c8
+	for (offset = strlen(rd->old); name[offset] && !(isdigit(name[offset])); offset++); /* do nothing */
4728c8
+	snprintf(buff, PARAMS_SIZE, "%s%s%s", rd->new, rd->delim,
4728c8
+		 name + offset);
4728c8
+	dm_rename(name, buff);
4728c8
+	condlog(4, "partition map %s renamed", name);
4728c8
+	return 0;
4728c8
+}
4728c8
 
4728c8
-	if (dm_dev_t(old, &dev_t[0], 32))
4728c8
-		goto out;
4728c8
+int
4728c8
+dm_rename_partmaps (char * old, char * new)
4728c8
+{
4728c8
+	struct rename_data rd;
4728c8
 
4728c8
+	rd.old = old;
4728c8
+	rd.new = new;
4728c8
 	if (isdigit(new[strlen(new)-1]))
4728c8
-		delim = "p";
4728c8
+		rd.delim = "p";
4728c8
 	else
4728c8
-		delim = "";
4728c8
-
4728c8
-	do {
4728c8
-		if (
4728c8
-		    /*
4728c8
-		     * if devmap target is "linear"
4728c8
-		     */
4728c8
-		    (dm_type(names->name, TGT_PART) > 0) &&
4728c8
-
4728c8
-		    /*
4728c8
-		     * and the multipath mapname and the part mapname start
4728c8
-		     * the same
4728c8
-		     */
4728c8
-		    !strncmp(names->name, old, strlen(old)) &&
4728c8
-
4728c8
-		    /*
4728c8
-		     * and we can fetch the map table from the kernel
4728c8
-		     */
4728c8
-		    !dm_get_map(names->name, &size, &buff[0]) &&
4728c8
-
4728c8
-		    /*
4728c8
-		     * and the table maps over the multipath map
4728c8
-		     */
4728c8
-		    strstr(buff, dev_t)
4728c8
-		   ) {
4728c8
-				/*
4728c8
-				 * then it's a kpartx generated partition.
4728c8
-				 * Rename it.
4728c8
-				 */
4728c8
-				for (offset = strlen(old); names->name[offset] && !(isdigit(names->name[offset])); offset++); /* do nothing */
4728c8
-				snprintf(buff, PARAMS_SIZE, "%s%s%s",
4728c8
-					 new, delim, names->name + offset);
4728c8
-				dm_rename(names->name, buff);
4728c8
-				condlog(4, "partition map %s renamed",
4728c8
-					names->name);
4728c8
-		   }
4728c8
-
4728c8
-		next = names->next;
4728c8
-		names = (void *) names + next;
4728c8
-	} while (next);
4728c8
-
4728c8
-	r = 0;
4728c8
-out:
4728c8
-	dm_task_destroy (dmt);
4728c8
-	return r;
4728c8
+		rd.delim = "";
4728c8
+	return do_foreach_partmaps(old, rename_partmap, &rd);
4728c8
 }
4728c8
 
4728c8
 int