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

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