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

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