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

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