Blame SOURCES/0198-RHBZ-1372032-detect-path-checker.patch

d88bf6
---
d88bf6
 libmultipath/config.c      |    4 ++
d88bf6
 libmultipath/config.h      |    2 +
d88bf6
 libmultipath/defaults.h    |    1 
d88bf6
 libmultipath/dict.c        |   74 +++++++++++++++++++++++++++++++++++++++++++++
d88bf6
 libmultipath/discovery.c   |    1 
d88bf6
 libmultipath/hwtable.c     |    1 
d88bf6
 libmultipath/propsel.c     |   65 +++++++++++++++++++++++++++++++--------
d88bf6
 libmultipath/propsel.h     |    1 
d88bf6
 libmultipath/structs.h     |    7 ++++
d88bf6
 multipath/multipath.conf.5 |    9 +++++
d88bf6
 10 files changed, 152 insertions(+), 13 deletions(-)
d88bf6
d88bf6
Index: multipath-tools-130222/libmultipath/config.c
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/config.c
d88bf6
+++ multipath-tools-130222/libmultipath/config.c
d88bf6
@@ -340,6 +340,7 @@ merge_hwe (struct hwentry * dst, struct
d88bf6
 	merge_num(user_friendly_names);
d88bf6
 	merge_num(retain_hwhandler);
d88bf6
 	merge_num(detect_prio);
d88bf6
+	merge_num(detect_checker);
d88bf6
 	merge_num(deferred_remove);
d88bf6
 	merge_num(delay_watch_checks);
d88bf6
 	merge_num(delay_wait_checks);
d88bf6
@@ -402,6 +403,7 @@ overwrite_hwe (struct hwentry * dst, str
d88bf6
 	overwrite_num(user_friendly_names);
d88bf6
 	overwrite_num(retain_hwhandler);
d88bf6
 	overwrite_num(detect_prio);
d88bf6
+	overwrite_num(detect_checker);
d88bf6
 	overwrite_num(deferred_remove);
d88bf6
 	overwrite_num(delay_watch_checks);
d88bf6
 	overwrite_num(delay_wait_checks);
d88bf6
@@ -476,6 +478,7 @@ store_hwe (vector hwtable, struct hwentr
d88bf6
 	hwe->user_friendly_names = dhwe->user_friendly_names;
d88bf6
 	hwe->retain_hwhandler = dhwe->retain_hwhandler;
d88bf6
 	hwe->detect_prio = dhwe->detect_prio;
d88bf6
+	hwe->detect_checker = dhwe->detect_checker;
d88bf6
 
d88bf6
 	if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
d88bf6
 		goto out;
d88bf6
@@ -672,6 +675,7 @@ load_config (char * file, struct udev *u
d88bf6
 	conf->fast_io_fail = DEFAULT_FAST_IO_FAIL;
d88bf6
 	conf->retain_hwhandler = DEFAULT_RETAIN_HWHANDLER;
d88bf6
 	conf->detect_prio = DEFAULT_DETECT_PRIO;
d88bf6
+	conf->detect_checker = DEFAULT_DETECT_CHECKER;
d88bf6
 	conf->deferred_remove = DEFAULT_DEFERRED_REMOVE;
d88bf6
 	conf->hw_strmatch = 0;
d88bf6
 	conf->force_sync = 0;
d88bf6
Index: multipath-tools-130222/libmultipath/config.h
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/config.h
d88bf6
+++ multipath-tools-130222/libmultipath/config.h
d88bf6
@@ -61,6 +61,7 @@ struct hwentry {
d88bf6
 	int user_friendly_names;
d88bf6
 	int retain_hwhandler;
d88bf6
 	int detect_prio;
d88bf6
+	int detect_checker;
d88bf6
 	int deferred_remove;
d88bf6
 	int delay_watch_checks;
d88bf6
 	int delay_wait_checks;
d88bf6
@@ -136,6 +137,7 @@ struct config {
d88bf6
 	int reassign_maps;
d88bf6
 	int retain_hwhandler;
d88bf6
 	int detect_prio;
d88bf6
+	int detect_checker;
d88bf6
 	int force_sync;
d88bf6
 	int deferred_remove;
d88bf6
 	int ignore_new_boot_devs;
d88bf6
Index: multipath-tools-130222/libmultipath/defaults.h
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/defaults.h
d88bf6
+++ multipath-tools-130222/libmultipath/defaults.h
d88bf6
@@ -19,6 +19,7 @@
d88bf6
 #define DEFAULT_FAST_IO_FAIL	5
d88bf6
 #define DEFAULT_RETAIN_HWHANDLER RETAIN_HWHANDLER_OFF
d88bf6
 #define DEFAULT_DETECT_PRIO DETECT_PRIO_OFF
d88bf6
+#define DEFAULT_DETECT_CHECKER DETECT_CHECKER_OFF
d88bf6
 #define DEFAULT_DEFERRED_REMOVE DEFERRED_REMOVE_OFF
d88bf6
 #define DEFAULT_DELAY_CHECKS DELAY_CHECKS_OFF
d88bf6
 #define DEFAULT_RETRIGGER_DELAY 10
d88bf6
Index: multipath-tools-130222/libmultipath/dict.c
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/dict.c
d88bf6
+++ multipath-tools-130222/libmultipath/dict.c
d88bf6
@@ -714,6 +714,29 @@ def_detect_prio_handler(vector strvec)
d88bf6
 }
d88bf6
 
d88bf6
 static int
d88bf6
+def_detect_checker_handler(vector strvec)
d88bf6
+{
d88bf6
+	char * buff;
d88bf6
+
d88bf6
+	buff = set_value(strvec);
d88bf6
+
d88bf6
+	if (!buff)
d88bf6
+		return 1;
d88bf6
+
d88bf6
+	if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
d88bf6
+	    (strlen(buff) == 1 && !strcmp(buff, "0")))
d88bf6
+		conf->detect_checker = DETECT_CHECKER_OFF;
d88bf6
+	else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
d88bf6
+		 (strlen(buff) == 1 && !strcmp(buff, "1")))
d88bf6
+		conf->detect_checker = DETECT_CHECKER_ON;
d88bf6
+	else
d88bf6
+		conf->detect_checker = DETECT_CHECKER_UNDEF;
d88bf6
+
d88bf6
+	FREE(buff);
d88bf6
+	return 0;
d88bf6
+}
d88bf6
+
d88bf6
+static int
d88bf6
 def_hw_strmatch_handler(vector strvec)
d88bf6
 {
d88bf6
 	char *buff;
d88bf6
@@ -1682,6 +1705,33 @@ hw_detect_prio_handler(vector strvec)
d88bf6
 }
d88bf6
 
d88bf6
 static int
d88bf6
+hw_detect_checker_handler(vector strvec)
d88bf6
+{
d88bf6
+	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
d88bf6
+	char * buff;
d88bf6
+
d88bf6
+	if (!hwe)
d88bf6
+		return 1;
d88bf6
+
d88bf6
+	buff = set_value(strvec);
d88bf6
+
d88bf6
+	if (!buff)
d88bf6
+		return 1;
d88bf6
+
d88bf6
+	if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
d88bf6
+	    (strlen(buff) == 1 && !strcmp(buff, "0")))
d88bf6
+		hwe->detect_checker = DETECT_CHECKER_OFF;
d88bf6
+	else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
d88bf6
+		 (strlen(buff) == 1 && !strcmp(buff, "1")))
d88bf6
+		hwe->detect_checker = DETECT_CHECKER_ON;
d88bf6
+	else
d88bf6
+		hwe->detect_checker = DETECT_CHECKER_UNDEF;
d88bf6
+
d88bf6
+	FREE(buff);
d88bf6
+	return 0;
d88bf6
+}
d88bf6
+
d88bf6
+static int
d88bf6
 hw_deferred_remove_handler(vector strvec)
d88bf6
 {
d88bf6
 	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
d88bf6
@@ -3059,6 +3109,19 @@ snprint_detect_prio(char * buff, int len
d88bf6
 }
d88bf6
 
d88bf6
 static int
d88bf6
+snprint_detect_checker(char * buff, int len, void * data)
d88bf6
+{
d88bf6
+	struct hwentry * hwe = (struct hwentry *)data;
d88bf6
+
d88bf6
+	if (hwe->detect_checker == DETECT_CHECKER_ON)
d88bf6
+		return snprintf(buff, len, "yes");
d88bf6
+	else if (hwe->detect_checker == DETECT_CHECKER_OFF)
d88bf6
+		return snprintf(buff, len, "no");
d88bf6
+	else
d88bf6
+		return 0;
d88bf6
+}
d88bf6
+
d88bf6
+static int
d88bf6
 snprint_hw_max_sectors_kb(char * buff, int len, void * data)
d88bf6
 {
d88bf6
 	struct hwentry * hwe = (struct hwentry *)data;
d88bf6
@@ -3424,6 +3487,15 @@ snprint_def_detect_prio(char * buff, int
d88bf6
 }
d88bf6
 
d88bf6
 static int
d88bf6
+snprint_def_detect_checker(char * buff, int len, void * data)
d88bf6
+{
d88bf6
+	if (conf->detect_checker == DETECT_PRIO_ON)
d88bf6
+		return snprintf(buff, len, "yes");
d88bf6
+	else
d88bf6
+		return snprintf(buff, len, "no");
d88bf6
+}
d88bf6
+
d88bf6
+static int
d88bf6
 snprint_def_hw_strmatch(char * buff, int len, void * data)
d88bf6
 {
d88bf6
 	if (conf->hw_strmatch)
d88bf6
@@ -3611,6 +3683,7 @@ init_keywords(void)
d88bf6
 	install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
d88bf6
 	install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler_handler);
d88bf6
 	install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
d88bf6
+	install_keyword("detect_path_checker", &def_detect_checker_handler, &snprint_def_detect_checker);
d88bf6
 	install_keyword("hw_str_match", &def_hw_strmatch_handler, &snprint_def_hw_strmatch);
d88bf6
 	install_keyword("force_sync", &def_force_sync_handler, &snprint_def_force_sync);
d88bf6
 	install_keyword("deferred_remove", &def_deferred_remove_handler, &snprint_def_deferred_remove);
d88bf6
@@ -3690,6 +3763,7 @@ init_keywords(void)
d88bf6
 	install_keyword("user_friendly_names", &hw_names_handler, &snprint_hw_user_friendly_names);
d88bf6
 	install_keyword("retain_attached_hw_handler", &hw_retain_hwhandler_handler, &snprint_hw_retain_hwhandler_handler);
d88bf6
 	install_keyword("detect_prio", &hw_detect_prio_handler, &snprint_detect_prio);
d88bf6
+	install_keyword("detect_path_checker", &hw_detect_checker_handler, &snprint_detect_checker);
d88bf6
 	install_keyword("deferred_remove", &hw_deferred_remove_handler, &snprint_hw_deferred_remove);
d88bf6
 	install_keyword("delay_watch_checks", &hw_delay_watch_checks_handler, &snprint_hw_delay_watch_checks);
d88bf6
 	install_keyword("delay_wait_checks", &hw_delay_wait_checks_handler, &snprint_hw_delay_wait_checks);
d88bf6
Index: multipath-tools-130222/libmultipath/discovery.c
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/discovery.c
d88bf6
+++ multipath-tools-130222/libmultipath/discovery.c
d88bf6
@@ -1107,6 +1107,7 @@ get_state (struct path * pp, int daemon)
d88bf6
 				return PATH_UNCHECKED;
d88bf6
 			}
d88bf6
 		}
d88bf6
+		select_detect_checker(pp);
d88bf6
 		select_checker(pp);
d88bf6
 		if (!checker_selected(c)) {
d88bf6
 			condlog(3, "%s: No checker selected", pp->dev);
d88bf6
Index: multipath-tools-130222/libmultipath/hwtable.c
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/hwtable.c
d88bf6
+++ multipath-tools-130222/libmultipath/hwtable.c
d88bf6
@@ -289,6 +289,7 @@ static struct hwentry default_hw[] = {
d88bf6
 		.prio_args     = NULL,
d88bf6
 		.retain_hwhandler = RETAIN_HWHANDLER_ON,
d88bf6
 		.detect_prio   = DETECT_PRIO_ON,
d88bf6
+		.detect_checker = DETECT_CHECKER_ON,
d88bf6
 	},
d88bf6
 	{
d88bf6
 		.vendor        = "EMC",
d88bf6
Index: multipath-tools-130222/libmultipath/propsel.c
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/propsel.c
d88bf6
+++ multipath-tools-130222/libmultipath/propsel.c
d88bf6
@@ -335,11 +335,43 @@ select_hwhandler (struct multipath * mp)
d88bf6
 	return 0;
d88bf6
 }
d88bf6
 
d88bf6
+int
d88bf6
+detect_alua(struct path * pp)
d88bf6
+{
d88bf6
+	int ret;
d88bf6
+	int tpgs = 0;
d88bf6
+
d88bf6
+	if ((tpgs = get_target_port_group_support(pp->fd)) <= 0)
d88bf6
+		return 0;
d88bf6
+	pp->tpgs = tpgs;
d88bf6
+	ret = get_target_port_group(pp->fd, NULL);
d88bf6
+	if (ret < 0)
d88bf6
+		return 0;
d88bf6
+	if (get_asymmetric_access_state(pp->fd, ret, NULL) < 0)
d88bf6
+		return 0;
d88bf6
+	return 1;
d88bf6
+}
d88bf6
+
d88bf6
+void
d88bf6
+detect_checker(struct path * pp)
d88bf6
+{
d88bf6
+	if (detect_alua(pp))
d88bf6
+		checker_get(&pp->checker, TUR);
d88bf6
+}
d88bf6
+
d88bf6
 extern int
d88bf6
 select_checker(struct path *pp)
d88bf6
 {
d88bf6
 	struct checker * c = &pp->checker;
d88bf6
 
d88bf6
+	if (pp->detect_checker == DETECT_CHECKER_ON) {
d88bf6
+		detect_checker(pp);
d88bf6
+		if (checker_selected(c)) {
d88bf6
+			condlog(3, "%s: path checker = %s (detected setting)",
d88bf6
+				pp->dev, checker_name(c));
d88bf6
+			goto out;
d88bf6
+		}
d88bf6
+	}
d88bf6
 	if (pp->hwe && pp->hwe->checker_name) {
d88bf6
 		checker_get(c, pp->hwe->checker_name);
d88bf6
 		condlog(3, "%s: path checker = %s (controller setting)",
d88bf6
@@ -396,19 +428,8 @@ select_getuid (struct path * pp)
d88bf6
 void
d88bf6
 detect_prio(struct path * pp)
d88bf6
 {
d88bf6
-	int ret;
d88bf6
-	struct prio *p = &pp->prio;
d88bf6
-	int tpgs = 0;
d88bf6
-
d88bf6
-	if ((tpgs = get_target_port_group_support(pp->fd)) <= 0)
d88bf6
-		return;
d88bf6
-	pp->tpgs = tpgs;
d88bf6
-	ret = get_target_port_group(pp->fd, NULL);
d88bf6
-	if (ret < 0)
d88bf6
-		return;
d88bf6
-	if (get_asymmetric_access_state(pp->fd, ret, NULL) < 0)
d88bf6
-		return;
d88bf6
-	prio_get(p, PRIO_ALUA, DEFAULT_PRIO_ARGS);
d88bf6
+	if (detect_alua(pp))
d88bf6
+		prio_get(&pp->prio, PRIO_ALUA, DEFAULT_PRIO_ARGS);
d88bf6
 }
d88bf6
 
d88bf6
 extern int
d88bf6
@@ -803,6 +824,24 @@ select_detect_prio (struct path * pp)
d88bf6
 	return 0;
d88bf6
 }
d88bf6
 
d88bf6
+extern int
d88bf6
+select_detect_checker (struct path * pp)
d88bf6
+{
d88bf6
+	if (pp->hwe && pp->hwe->detect_checker) {
d88bf6
+		pp->detect_checker = pp->hwe->detect_checker;
d88bf6
+		condlog(3, "%s: detect_checker = %d (controller default)", pp->dev, pp->detect_checker);
d88bf6
+		return 0;
d88bf6
+	}
d88bf6
+	if (conf->detect_checker) {
d88bf6
+		pp->detect_checker = conf->detect_checker;
d88bf6
+		condlog(3, "%s: detect_checker = %d (config file default)", pp->dev, pp->detect_checker);
d88bf6
+		return 0;
d88bf6
+	}
d88bf6
+	pp->detect_checker = DEFAULT_DETECT_CHECKER;
d88bf6
+	condlog(3, "%s: detect_checker = %d (compiled in default)", pp->dev, pp->detect_checker);
d88bf6
+	return 0;
d88bf6
+}
d88bf6
+
d88bf6
 extern int
d88bf6
 select_delay_watch_checks (struct multipath * mp)
d88bf6
 {
d88bf6
Index: multipath-tools-130222/libmultipath/propsel.h
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/propsel.h
d88bf6
+++ multipath-tools-130222/libmultipath/propsel.h
d88bf6
@@ -20,6 +20,7 @@ int select_dev_loss(struct multipath *mp
d88bf6
 int select_reservation_key(struct multipath *mp);
d88bf6
 int select_retain_hwhandler (struct multipath * mp);
d88bf6
 int select_detect_prio(struct path * pp);
d88bf6
+int select_detect_checker(struct path * pp);
d88bf6
 int select_deferred_remove(struct multipath *mp);
d88bf6
 int select_delay_watch_checks (struct multipath * mp);
d88bf6
 int select_delay_wait_checks (struct multipath * mp);
d88bf6
Index: multipath-tools-130222/libmultipath/structs.h
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/libmultipath/structs.h
d88bf6
+++ multipath-tools-130222/libmultipath/structs.h
d88bf6
@@ -115,6 +115,12 @@ enum detect_prio_states {
d88bf6
 	DETECT_PRIO_ON,
d88bf6
 };
d88bf6
 
d88bf6
+enum detect_checker_states {
d88bf6
+	DETECT_CHECKER_UNDEF,
d88bf6
+	DETECT_CHECKER_OFF,
d88bf6
+	DETECT_CHECKER_ON,
d88bf6
+};
d88bf6
+
d88bf6
 enum deferred_remove_states {
d88bf6
 	DEFERRED_REMOVE_UNDEF,
d88bf6
 	DEFERRED_REMOVE_OFF,
d88bf6
@@ -204,6 +210,7 @@ struct path {
d88bf6
 	int priority;
d88bf6
 	int pgindex;
d88bf6
 	int detect_prio;
d88bf6
+	int detect_checker;
d88bf6
 	int watch_checks;
d88bf6
 	int wait_checks;
d88bf6
 	int tpgs;
d88bf6
Index: multipath-tools-130222/multipath/multipath.conf.5
d88bf6
===================================================================
d88bf6
--- multipath-tools-130222.orig/multipath/multipath.conf.5
d88bf6
+++ multipath-tools-130222/multipath/multipath.conf.5
d88bf6
@@ -448,6 +448,15 @@ will automatically use the
d88bf6
 prioritizer. If not, the prioritizer will be selected as usual. Default is
d88bf6
 .I no
d88bf6
 .TP
d88bf6
+.B detect_checker
d88bf6
+If set to
d88bf6
+.I yes
d88bf6
+, multipath will try to detect if the device supports ALUA. If so, the device
d88bf6
+will automatically use the
d88bf6
+.I tur
d88bf6
+checker. If not, the prioritizer will be selected as ususal. Default is
d88bf6
+.I no
d88bf6
+.TP
d88bf6
 .B hw_str_match
d88bf6
 If set to
d88bf6
 .I yes