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

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