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

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