Blame SOURCES/0134-RHBZ-1241528-check-mpath-prefix.patch

4728c8
---
4728c8
 libmpathpersist/mpath_persist.c |    4 +-
4728c8
 libmultipath/devmapper.c        |   67 +++++++++++++++++++++++++++++-----------
4728c8
 libmultipath/devmapper.h        |    1 
4728c8
 multipathd/main.c               |    2 -
4728c8
 4 files changed, 53 insertions(+), 21 deletions(-)
4728c8
4728c8
Index: multipath-tools-130222/libmpathpersist/mpath_persist.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/libmpathpersist/mpath_persist.c
4728c8
+++ multipath-tools-130222/libmpathpersist/mpath_persist.c
4728c8
@@ -160,7 +160,7 @@ int mpath_persistent_reserve_in (int fd,
4728c8
 
4728c8
 	condlog(3, "alias = %s", alias);
4728c8
 	map_present = dm_map_present(alias);
4728c8
-	if (map_present && dm_type(alias, TGT_MPATH) <= 0){
4728c8
+	if (map_present && !dm_is_mpath(alias)){
4728c8
 		condlog( 0, "%s: not a multipath device.", alias);
4728c8
 		ret = MPATH_PR_DMMP_ERROR;
4728c8
 		goto out;
4728c8
@@ -250,7 +250,7 @@ int mpath_persistent_reserve_out ( int f
4728c8
 	condlog(3, "alias = %s", alias);
4728c8
 	map_present = dm_map_present(alias);
4728c8
 
4728c8
-	if (map_present && dm_type(alias, TGT_MPATH) <= 0){
4728c8
+	if (map_present && !dm_is_mpath(alias)){
4728c8
 		condlog(3, "%s: not a multipath device.", alias);
4728c8
 		ret = MPATH_PR_DMMP_ERROR;
4728c8
 		goto out;
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
@@ -564,6 +564,48 @@ out:
4728c8
 	return r;
4728c8
 }
4728c8
 
4728c8
+extern int
4728c8
+dm_is_mpath(const char * name)
4728c8
+{
4728c8
+	int r = 0;
4728c8
+	struct dm_task *dmt;
4728c8
+	struct dm_info info;
4728c8
+	uint64_t start, length;
4728c8
+	char *target_type = NULL;
4728c8
+	char *params;
4728c8
+	const char *uuid;
4728c8
+
4728c8
+	if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
4728c8
+		return 0;
4728c8
+
4728c8
+	if (!dm_task_set_name(dmt, name))
4728c8
+		goto out;
4728c8
+
4728c8
+	dm_task_no_open_count(dmt);
4728c8
+
4728c8
+	if (!dm_task_run(dmt))
4728c8
+		goto out;
4728c8
+
4728c8
+	if (!dm_task_get_info(dmt, &info) || !info.exists)
4728c8
+		goto out;
4728c8
+
4728c8
+	uuid = dm_task_get_uuid(dmt);
4728c8
+
4728c8
+	if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0)
4728c8
+		goto out;
4728c8
+
4728c8
+	/* Fetch 1st target */
4728c8
+	dm_get_next_target(dmt, NULL, &start, &length, &target_type, &params);
4728c8
+
4728c8
+	if (!target_type || strcmp(target_type, TGT_MPATH) != 0)
4728c8
+		goto out;
4728c8
+
4728c8
+	r = 1;
4728c8
+out:
4728c8
+	dm_task_destroy(dmt);
4728c8
+	return r;
4728c8
+}
4728c8
+
4728c8
 static int
4728c8
 dm_dev_t (const char * mapname, char * dev_t, int len)
4728c8
 {
4728c8
@@ -672,10 +714,7 @@ _dm_flush_map (const char * mapname, int
4728c8
 {
4728c8
 	int r;
4728c8
 
4728c8
-	if (!dm_map_present(mapname))
4728c8
-		return 0;
4728c8
-
4728c8
-	if (dm_type(mapname, TGT_MPATH) <= 0)
4728c8
+	if (!dm_is_mpath(mapname))
4728c8
 		return 0; /* nothing to do */
4728c8
 
4728c8
 	if (dm_remove_partmaps(mapname, need_sync, deferred_remove))
4728c8
@@ -725,10 +764,7 @@ dm_suspend_and_flush_map (const char * m
4728c8
 	unsigned long long mapsize;
4728c8
 	char params[PARAMS_SIZE] = {0};
4728c8
 
4728c8
-	if (!dm_map_present(mapname))
4728c8
-		return 0;
4728c8
-
4728c8
-	if (dm_type(mapname, TGT_MPATH) <= 0)
4728c8
+	if (!dm_is_mpath(mapname))
4728c8
 		return 0; /* nothing to do */
4728c8
 
4728c8
 	if (!dm_get_map(mapname, &mapsize, params)) {
4728c8
@@ -899,7 +935,6 @@ dm_get_maps (vector mp)
4728c8
 {
4728c8
 	struct multipath * mpp;
4728c8
 	int r = 1;
4728c8
-	int info;
4728c8
 	struct dm_task *dmt;
4728c8
 	struct dm_names *names;
4728c8
 	unsigned next = 0;
4728c8
@@ -924,9 +959,7 @@ dm_get_maps (vector mp)
4728c8
 	}
4728c8
 
4728c8
 	do {
4728c8
-		info = dm_type(names->name, TGT_MPATH);
4728c8
-
4728c8
-		if (info <= 0)
4728c8
+		if (!dm_is_mpath(names->name))
4728c8
 			goto next;
4728c8
 
4728c8
 		mpp = alloc_multipath();
4728c8
@@ -939,13 +972,11 @@ dm_get_maps (vector mp)
4728c8
 		if (!mpp->alias)
4728c8
 			goto out1;
4728c8
 
4728c8
-		if (info > 0) {
4728c8
-			if (dm_get_map(names->name, &mpp->size, NULL))
4728c8
-				goto out1;
4728c8
+		if (dm_get_map(names->name, &mpp->size, NULL))
4728c8
+			goto out1;
4728c8
 
4728c8
-			dm_get_uuid(names->name, mpp->wwid);
4728c8
-			dm_get_info(names->name, &mpp->dmi);
4728c8
-		}
4728c8
+		dm_get_uuid(names->name, mpp->wwid);
4728c8
+		dm_get_info(names->name, &mpp->dmi);
4728c8
 
4728c8
 		if (!vector_alloc_slot(mp))
4728c8
 			goto out1;
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
@@ -23,6 +23,7 @@ int dm_map_present (const char *);
4728c8
 int dm_get_map(const char *, unsigned long long *, char *);
4728c8
 int dm_get_status(char *, char *);
4728c8
 int dm_type(const char *, char *);
4728c8
+int dm_is_mpath(const char *);
4728c8
 int _dm_flush_map (const char *, int, int);
4728c8
 int dm_flush_map_nopaths(const char * mapname, int deferred_remove);
4728c8
 #define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0)
4728c8
Index: multipath-tools-130222/multipathd/main.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/multipathd/main.c
4728c8
+++ multipath-tools-130222/multipathd/main.c
4728c8
@@ -285,7 +285,7 @@ ev_add_map (char * dev, char * alias, st
4728c8
 
4728c8
 	map_present = dm_map_present(alias);
4728c8
 
4728c8
-	if (map_present && dm_type(alias, TGT_MPATH) <= 0) {
4728c8
+	if (map_present && !dm_is_mpath(alias)) {
4728c8
 		condlog(4, "%s: not a multipath map", alias);
4728c8
 		return 0;
4728c8
 	}