Blame SOURCES/0148-RHBZ-1292599-verify-before-remove.patch

f20720
---
f20720
 libmultipath/devmapper.c |   45 +++++++++++++++++++++++++++++++++++++--------
f20720
 libmultipath/devmapper.h |    2 +-
f20720
 2 files changed, 38 insertions(+), 9 deletions(-)
f20720
f20720
Index: multipath-tools-130222/libmultipath/devmapper.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/devmapper.c
f20720
+++ multipath-tools-130222/libmultipath/devmapper.c
f20720
@@ -33,6 +33,9 @@
f20720
 #define UUID_PREFIX_LEN 6
f20720
 
f20720
 static int dm_cancel_remove_partmaps(const char * mapname);
f20720
+static int do_foreach_partmaps (const char * mapname,
f20720
+				int (*partmap_func)(const char *, void *),
f20720
+				void *data);
f20720
 
f20720
 #ifndef LIBDM_API_COOKIE
f20720
 static inline int dm_task_set_cookie(struct dm_task *dmt, uint32_t *c, int a)
f20720
@@ -709,6 +712,26 @@ out:
f20720
 	return r;
f20720
 }
f20720
 
f20720
+static int
f20720
+partmap_in_use(const char *name, void *data)
f20720
+{
f20720
+	int part_count, *ret_count = (int *)data;
f20720
+	int open_count = dm_get_opencount(name);
f20720
+
f20720
+	if (ret_count)
f20720
+		(*ret_count)++;
f20720
+	part_count = 0;
f20720
+	if (open_count) {
f20720
+		if (do_foreach_partmaps(name, partmap_in_use, &part_count))
f20720
+			return 1;
f20720
+		if (open_count != part_count) {
f20720
+			condlog(2, "%s: map in use", name);
f20720
+			return 1;
f20720
+		}
f20720
+	}
f20720
+	return 0;
f20720
+}
f20720
+
f20720
 extern int
f20720
 _dm_flush_map (const char * mapname, int need_sync, int deferred_remove)
f20720
 {
f20720
@@ -717,6 +740,11 @@ _dm_flush_map (const char * mapname, int
f20720
 	if (!dm_is_mpath(mapname))
f20720
 		return 0; /* nothing to do */
f20720
 
f20720
+	/* If you aren't doing a deferred remove, make sure that no
f20720
+	 * devices are in use */
f20720
+	if (!do_deferred(deferred_remove) && partmap_in_use(mapname, NULL))
f20720
+			return 1;
f20720
+
f20720
 	if (dm_remove_partmaps(mapname, need_sync, deferred_remove))
f20720
 		return 1;
f20720
 
f20720
@@ -825,7 +853,7 @@ dm_flush_maps (void)
f20720
 }
f20720
 
f20720
 int
f20720
-dm_message(char * mapname, char * message)
f20720
+dm_message(const char * mapname, char * message)
f20720
 {
f20720
 	int r = 1;
f20720
 	struct dm_task *dmt;
f20720
@@ -1076,7 +1104,8 @@ bad:
f20720
 }
f20720
 
f20720
 static int
f20720
-do_foreach_partmaps (const char * mapname, int (*partmap_func)(char *, void *),
f20720
+do_foreach_partmaps (const char * mapname,
f20720
+		     int (*partmap_func)(const char *, void *),
f20720
 		     void *data)
f20720
 {
f20720
 	struct dm_task *dmt;
f20720
@@ -1149,7 +1178,7 @@ struct remove_data {
f20720
 };
f20720
 
f20720
 static int
f20720
-remove_partmap(char *name, void *data)
f20720
+remove_partmap(const char *name, void *data)
f20720
 {
f20720
 	struct remove_data *rd = (struct remove_data *)data;
f20720
 
f20720
@@ -1176,7 +1205,7 @@ dm_remove_partmaps (const char * mapname
f20720
 #ifdef LIBDM_API_DEFERRED
f20720
 
f20720
 static int
f20720
-cancel_remove_partmap (char *name, void *unused)
f20720
+cancel_remove_partmap (const char *name, void *unused)
f20720
 {
f20720
 	if (dm_get_opencount(name))
f20720
 		dm_cancel_remove_partmaps(name);
f20720
@@ -1296,13 +1325,13 @@ out:
f20720
 }
f20720
 
f20720
 struct rename_data {
f20720
-	char *old;
f20720
+	const char *old;
f20720
 	char *new;
f20720
 	char *delim;
f20720
 };
f20720
 
f20720
 static int
f20720
-rename_partmap (char *name, void *data)
f20720
+rename_partmap (const char *name, void *data)
f20720
 {
f20720
 	char buff[PARAMS_SIZE];
f20720
 	int offset;
f20720
@@ -1319,7 +1348,7 @@ rename_partmap (char *name, void *data)
f20720
 }
f20720
 
f20720
 int
f20720
-dm_rename_partmaps (char * old, char * new)
f20720
+dm_rename_partmaps (const char * old, char * new)
f20720
 {
f20720
 	struct rename_data rd;
f20720
 
f20720
@@ -1333,7 +1362,7 @@ dm_rename_partmaps (char * old, char * n
f20720
 }
f20720
 
f20720
 int
f20720
-dm_rename (char * old, char * new)
f20720
+dm_rename (const char * old, char * new)
f20720
 {
f20720
 	int r = 0;
f20720
 	struct dm_task *dmt;
f20720
Index: multipath-tools-130222/libmultipath/devmapper.h
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/devmapper.h
f20720
+++ multipath-tools-130222/libmultipath/devmapper.h
f20720
@@ -47,7 +47,7 @@ int dm_remove_partmaps (const char * map
f20720
 			int deferred_remove);
f20720
 int dm_get_uuid(char *name, char *uuid);
f20720
 int dm_get_info (char * mapname, struct dm_info ** dmi);
f20720
-int dm_rename (char * old, char * new);
f20720
+int dm_rename (const char * old, char * new);
f20720
 int dm_reassign(const char * mapname);
f20720
 int dm_reassign_table(const char *name, char *old, char *new);
f20720
 int dm_setgeometry(struct multipath *mpp);