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

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