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

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