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

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