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

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