Blame SOURCES/0006-RH-add-find-multipaths.patch

671555
---
671555
 libmultipath/config.c    |    1 +
671555
 libmultipath/config.h    |    1 +
671555
 libmultipath/configure.c |   11 +++++++++++
671555
 libmultipath/defaults.h  |    1 +
671555
 libmultipath/dict.c      |   34 ++++++++++++++++++++++++++++++++++
671555
 libmultipath/wwids.c     |   26 ++++++++++++++++++++++++++
671555
 libmultipath/wwids.h     |    1 +
671555
 multipath/main.c         |    2 +-
671555
 multipathd/main.c        |    6 ++++++
671555
 9 files changed, 82 insertions(+), 1 deletion(-)
671555
671555
Index: multipath-tools-130222/libmultipath/config.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/config.c
671555
+++ multipath-tools-130222/libmultipath/config.c
671555
@@ -547,6 +547,7 @@ load_config (char * file)
671555
 	conf->reassign_maps = DEFAULT_REASSIGN_MAPS;
671555
 	conf->checkint = DEFAULT_CHECKINT;
671555
 	conf->max_checkint = MAX_CHECKINT(conf->checkint);
671555
+	conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
671555
 	conf->fast_io_fail = DEFAULT_FAST_IO_FAIL;
671555
 	conf->retain_hwhandler = DEFAULT_RETAIN_HWHANDLER;
671555
 	conf->detect_prio = DEFAULT_DETECT_PRIO;
671555
Index: multipath-tools-130222/libmultipath/configure.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/configure.c
671555
+++ multipath-tools-130222/libmultipath/configure.c
671555
@@ -508,6 +508,10 @@ coalesce_paths (struct vectors * vecs, v
671555
 
671555
 	memset(empty_buff, 0, WWID_SIZE);
671555
 
671555
+	/* ignore refwwid if it's empty */
671555
+	if (refwwid && !strlen(refwwid))
671555
+		refwwid = NULL;
671555
+
671555
 	if (force_reload) {
671555
 		vector_foreach_slot (pathvec, pp1, k) {
671555
 			pp1->mpp = NULL;
671555
@@ -537,6 +541,13 @@ coalesce_paths (struct vectors * vecs, v
671555
 		if (refwwid && strncmp(pp1->wwid, refwwid, WWID_SIZE))
671555
 			continue;
671555
 
671555
+		/* If find_multipaths was selected check if the path is valid */
671555
+		if (conf->find_multipaths && !refwwid &&
671555
+		    !should_multipath(pp1, pathvec)) {
671555
+			orphan_path(pp1);
671555
+			continue;
671555
+		}
671555
+
671555
 		/*
671555
 		 * at this point, we know we really got a new mp
671555
 		 */
671555
Index: multipath-tools-130222/libmultipath/defaults.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/defaults.h
671555
+++ multipath-tools-130222/libmultipath/defaults.h
671555
@@ -15,6 +15,7 @@
671555
 #define DEFAULT_USER_FRIENDLY_NAMES    0
671555
 #define DEFAULT_VERBOSITY	2
671555
 #define DEFAULT_REASSIGN_MAPS	1
671555
+#define DEFAULT_FIND_MULTIPATHS	0
671555
 #define DEFAULT_FAST_IO_FAIL	5
671555
 #define DEFAULT_RETAIN_HWHANDLER RETAIN_HWHANDLER_OFF
671555
 #define DEFAULT_DETECT_PRIO DETECT_PRIO_OFF
671555
Index: multipath-tools-130222/libmultipath/dict.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/dict.c
671555
+++ multipath-tools-130222/libmultipath/dict.c
671555
@@ -585,6 +585,27 @@ def_reservation_key_handler(vector strve
671555
 }
671555
 
671555
 static int
671555
+def_find_multipaths_handler(vector strvec)
671555
+{
671555
+	char * buff;
671555
+
671555
+	buff = set_value(strvec);
671555
+
671555
+	if (!buff)
671555
+		return 1;
671555
+
671555
+	if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
671555
+	    (strlen(buff) == 1 && !strcmp(buff, "0")))
671555
+		conf->find_multipaths = 0;
671555
+	else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
671555
+		 (strlen(buff) == 1 && !strcmp(buff, "1")))
671555
+		conf->find_multipaths = 1;
671555
+
671555
+	FREE(buff);
671555
+	return 0;
671555
+}
671555
+
671555
+static int
671555
 def_names_handler(vector strvec)
671555
 {
671555
 	char * buff;
671555
@@ -2700,6 +2721,18 @@ snprint_def_log_checker_err (char * buff
671555
 }
671555
 
671555
 static int
671555
+snprint_def_find_multipaths (char * buff, int len, void * data)
671555
+{
671555
+	if (conf->find_multipaths == DEFAULT_FIND_MULTIPATHS)
671555
+		return 0;
671555
+	if (!conf->find_multipaths)
671555
+		return snprintf(buff, len, "no");
671555
+
671555
+	return snprintf(buff, len, "yes");
671555
+}
671555
+
671555
+
671555
+static int
671555
 snprint_def_user_friendly_names (char * buff, int len, void * data)
671555
 {
671555
 	if (conf->user_friendly_names  == USER_FRIENDLY_NAMES_ON)
671555
@@ -2833,6 +2866,7 @@ init_keywords(void)
671555
 	install_keyword("wwids_file", &wwids_file_handler, &snprint_def_wwids_file);
671555
 	install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err);
671555
 	install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
671555
+	install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
671555
 	install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler_handler);
671555
 	install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
671555
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
671555
Index: multipath-tools-130222/libmultipath/wwids.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/wwids.c
671555
+++ multipath-tools-130222/libmultipath/wwids.c
671555
@@ -125,6 +125,32 @@ out:
671555
 }
671555
 
671555
 int
671555
+should_multipath(struct path *pp1, vector pathvec)
671555
+{
671555
+	int i;
671555
+	struct path *pp2;
671555
+
671555
+	condlog(4, "checking if %s should be multipathed", pp1->dev);
671555
+	vector_foreach_slot(pathvec, pp2, i) {
671555
+		if (pp1->dev == pp2->dev)
671555
+			continue;
671555
+		if (strncmp(pp1->wwid, pp2->wwid, WWID_SIZE) == 0) {
671555
+			condlog(3, "found multiple paths with wwid %s, "
671555
+				"multipathing %s", pp1->wwid, pp1->dev);
671555
+			return 1;
671555
+		}
671555
+	}
671555
+	if (check_wwids_file(pp1->wwid, 0) < 0) {
671555
+		condlog(3, "wwid %s not in wwids file, skipping %s",
671555
+			pp1->wwid, pp1->dev);
671555
+		return 0;
671555
+	}
671555
+	condlog(3, "found wwid %s in wwids file, multipathing %s", pp1->wwid,
671555
+		pp1->dev);
671555
+	return 1;
671555
+}
671555
+
671555
+int
671555
 remember_wwid(char *wwid)
671555
 {
671555
 	int ret = check_wwids_file(wwid, 1);
671555
Index: multipath-tools-130222/libmultipath/wwids.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/wwids.h
671555
+++ multipath-tools-130222/libmultipath/wwids.h
671555
@@ -12,6 +12,7 @@
671555
 "#\n" \
671555
 "# Valid WWIDs:\n"
671555
 
671555
+int should_multipath(struct path *pp, vector pathvec);
671555
 int remember_wwid(char *wwid);
671555
 int check_wwids_file(char *wwid, int write_wwid);
671555
 
671555
Index: multipath-tools-130222/multipath/main.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipath/main.c
671555
+++ multipath-tools-130222/multipath/main.c
671555
@@ -333,7 +333,7 @@ configure (void)
671555
 	/*
671555
 	 * core logic entry point
671555
 	 */
671555
-	r = coalesce_paths(&vecs, NULL, NULL, conf->force_reload);
671555
+	r = coalesce_paths(&vecs, NULL, refwwid, conf->force_reload);
671555
 
671555
 out:
671555
 	if (refwwid)
671555
Index: multipath-tools-130222/multipathd/main.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipathd/main.c
671555
+++ multipath-tools-130222/multipathd/main.c
671555
@@ -49,6 +49,7 @@
671555
 #include <print.h>
671555
 #include <configure.h>
671555
 #include <prio.h>
671555
+#include <wwids.h>
671555
 #include <pgpolicies.h>
671555
 #include <uevent.h>
671555
 
671555
@@ -471,6 +472,11 @@ rescan:
671555
 			return 1;
671555
 		}
671555
 
671555
+		if (conf->find_multipaths &&
671555
+		    !should_multipath(pp, vecs->pathvec)) {
671555
+			orphan_path(pp);
671555
+			return 0;
671555
+		}
671555
 		condlog(4,"%s: creating new map", pp->dev);
671555
 		if ((mpp = add_map_with_path(vecs, pp, 1))) {
671555
 			mpp->action = ACT_CREATE;
671555
Index: multipath-tools-130222/libmultipath/config.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/config.h
671555
+++ multipath-tools-130222/libmultipath/config.h
671555
@@ -106,6 +106,7 @@ struct config {
671555
 	unsigned int dev_loss;
671555
 	int log_checker_err;
671555
 	int allow_queueing;
671555
+	int find_multipaths;
671555
 	uid_t uid;
671555
 	gid_t gid;
671555
 	mode_t mode;