4728c8
---
4728c8
 libmpathpersist/mpath_persist.c |   28 +++++++++++---
4728c8
 libmultipath/config.c           |    3 +
4728c8
 libmultipath/config.h           |    2 +
4728c8
 libmultipath/defaults.h         |    1 
4728c8
 libmultipath/dict.c             |   77 ++++++++++++++++++++++++++++++++++++++++
4728c8
 libmultipath/propsel.c          |   20 ++++++++++
4728c8
 libmultipath/propsel.h          |    1 
4728c8
 libmultipath/structs.h          |    7 +++
4728c8
 multipath/multipath.conf.5      |    7 +++
4728c8
 9 files changed, 140 insertions(+), 6 deletions(-)
4728c8
4728c8
Index: multipath-tools-130222-patched/libmpathpersist/mpath_persist.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmpathpersist/mpath_persist.c
4728c8
+++ multipath-tools-130222-patched/libmpathpersist/mpath_persist.c
4728c8
@@ -287,6 +287,7 @@ int mpath_persistent_reserve_out ( int f
4728c8
 	}
4728c8
 
4728c8
 	select_reservation_key(mpp);
4728c8
+	select_all_tg_pt(mpp);
4728c8
 
4728c8
 	memcpy(&prkey, paramp->sa_key, 8);
4728c8
 	if (mpp->prkey_source == PRKEY_SOURCE_FILE && prkey &&
4728c8
@@ -419,7 +420,7 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 	unsigned int rq_type, struct prout_param_descriptor * paramp, int noisy)
4728c8
 {
4728c8
 
4728c8
-	int i, j;
4728c8
+	int i, j, k;
4728c8
 	struct pathgroup *pgp = NULL;
4728c8
 	struct path *pp = NULL;
4728c8
 	int rollback = 0;
4728c8
@@ -444,11 +445,13 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 	}
4728c8
 
4728c8
 	struct threadinfo thread[active_pathcount];
4728c8
+	int hosts[active_pathcount];
4728c8
 
4728c8
 	memset(thread, 0, sizeof(thread));
4728c8
 
4728c8
 	/* init thread parameter */
4728c8
 	for (i =0; i< active_pathcount; i++){
4728c8
+		hosts[i] = -1;
4728c8
 		thread[i].param.rq_servact = rq_servact;
4728c8
 		thread[i].param.rq_scope = rq_scope;
4728c8
 		thread[i].param.rq_type = rq_type;
4728c8
@@ -476,6 +479,17 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 				condlog (1, "%s: %s path not up. Skip.", mpp->wwid, pp->dev);
4728c8
 				continue;
4728c8
 			}
4728c8
+			if (mpp->all_tg_pt == ALL_TG_PT_ON &&
4728c8
+			    pp->sg_id.host_no != -1) {
4728c8
+				for (k = 0; k < count; k++) {
4728c8
+					if (pp->sg_id.host_no == hosts[k]) {
4728c8
+						condlog(3, "%s: %s host %d matches skip.", pp->wwid, pp->dev, pp->sg_id.host_no);
4728c8
+						break;
4728c8
+					}
4728c8
+				}
4728c8
+				if (k < count)
4728c8
+					continue;
4728c8
+			}
4728c8
 			strncpy(thread[count].param.dev, pp->dev, FILE_NAME_SIZE);
4728c8
 
4728c8
 			if (count && (thread[count].param.paramp->sa_flags & MPATH_F_SPEC_I_PT_MASK)){
4728c8
@@ -492,10 +506,12 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 				condlog (0, "%s: failed to create thread %d", mpp->wwid, rc);
4728c8
 				thread[count].param.status = MPATH_PR_THREAD_ERROR;
4728c8
 			}
4728c8
+			else
4728c8
+				hosts[count] = pp->sg_id.host_no;
4728c8
 			count = count +1;
4728c8
 		}
4728c8
 	}
4728c8
-	for( i=0; i < active_pathcount ; i++){
4728c8
+	for( i=0; i < count ; i++){
4728c8
 		if (thread[i].param.status != MPATH_PR_THREAD_ERROR) {
4728c8
 			rc = pthread_join(thread[i].id, NULL);
4728c8
 			if (rc){
4728c8
@@ -518,7 +534,7 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 	}
4728c8
 	if (rollback && ((rq_servact == MPATH_PROUT_REG_SA) && sa_key != 0 )){
4728c8
 		condlog (3, "%s: ERROR: initiating pr out rollback", mpp->wwid);
4728c8
-		for( i=0 ; i < active_pathcount ; i++){
4728c8
+		for( i=0 ; i < count ; i++){
4728c8
 			if (thread[i].param.status == MPATH_PR_SUCCESS) {
4728c8
 				memcpy(&thread[i].param.paramp->key, &thread[i].param.paramp->sa_key, 8);
4728c8
 				memset(&thread[i].param.paramp->sa_key, 0, 8);
4728c8
@@ -532,7 +548,7 @@ int mpath_prout_reg(struct multipath *mp
4728c8
 			} else
4728c8
 				thread[i].param.status = MPATH_PR_SKIP;
4728c8
 		}
4728c8
-		for(i=0; i < active_pathcount ; i++){
4728c8
+		for(i=0; i < count ; i++){
4728c8
 			if (thread[i].param.status != MPATH_PR_SKIP &&
4728c8
 			    thread[i].param.status != MPATH_PR_THREAD_ERROR) {
4728c8
 				rc = pthread_join(thread[i].id, NULL);
4728c8
@@ -678,7 +694,7 @@ int mpath_prout_rel(struct multipath *mp
4728c8
 		}
4728c8
 	}
4728c8
 	pthread_attr_destroy (&attr);
4728c8
-	for (i = 0; i < active_pathcount; i++){
4728c8
+	for (i = 0; i < count; i++){
4728c8
 		if (thread[i].param.status != MPATH_PR_THREAD_ERROR) {
4728c8
 			rc = pthread_join (thread[i].id, NULL);
4728c8
 			if (rc){
4728c8
@@ -687,7 +703,7 @@ int mpath_prout_rel(struct multipath *mp
4728c8
 		}
4728c8
 	}
4728c8
 
4728c8
-	for (i = 0; i < active_pathcount; i++){
4728c8
+	for (i = 0; i < count; i++){
4728c8
 		/*  check thread status here and return the status */
4728c8
 
4728c8
 		if (thread[i].param.status == MPATH_PR_RESERV_CONFLICT)
4728c8
Index: multipath-tools-130222-patched/libmultipath/config.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/config.c
4728c8
+++ multipath-tools-130222-patched/libmultipath/config.c
4728c8
@@ -349,6 +349,7 @@ merge_hwe (struct hwentry * dst, struct
4728c8
 	merge_num(max_sectors_kb);
4728c8
 	merge_num(unpriv_sgio);
4728c8
 	merge_num(ghost_delay);
4728c8
+	merge_num(all_tg_pt);
4728c8
 
4728c8
 	/*
4728c8
 	 * Make sure features is consistent with
4728c8
@@ -414,6 +415,7 @@ overwrite_hwe (struct hwentry * dst, str
4728c8
 	overwrite_num(max_sectors_kb);
4728c8
 	overwrite_num(unpriv_sgio);
4728c8
 	overwrite_num(ghost_delay);
4728c8
+	overwrite_num(all_tg_pt);
4728c8
 
4728c8
 	/*
4728c8
 	 * Make sure features is consistent with
4728c8
@@ -700,6 +702,7 @@ load_config (char * file, struct udev *u
4728c8
 	conf->max_sectors_kb = DEFAULT_MAX_SECTORS_KB;
4728c8
 	conf->unpriv_sgio = DEFAULT_UNPRIV_SGIO;
4728c8
 	conf->ghost_delay = DEFAULT_GHOST_DELAY;
4728c8
+	conf->all_tg_pt = DEFAULT_ALL_TG_PT;
4728c8
 
4728c8
 	/*
4728c8
 	 * preload default hwtable
4728c8
Index: multipath-tools-130222-patched/libmultipath/config.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/config.h
4728c8
+++ multipath-tools-130222-patched/libmultipath/config.h
4728c8
@@ -71,6 +71,7 @@ struct hwentry {
4728c8
 	int max_sectors_kb;
4728c8
 	int unpriv_sgio;
4728c8
 	int ghost_delay;
4728c8
+	int all_tg_pt;
4728c8
 	char * bl_product;
4728c8
 };
4728c8
 
4728c8
@@ -162,6 +163,7 @@ struct config {
4728c8
 	int max_sectors_kb;
4728c8
 	int unpriv_sgio;
4728c8
 	int ghost_delay;
4728c8
+	int all_tg_pt;
4728c8
 	unsigned int version[3];
4728c8
 
4728c8
 	char * dev;
4728c8
Index: multipath-tools-130222-patched/libmultipath/dict.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/dict.c
4728c8
+++ multipath-tools-130222-patched/libmultipath/dict.c
4728c8
@@ -1051,6 +1051,29 @@ def_ghost_delay_handler(vector strvec)
4728c8
 	return 0;
4728c8
 }
4728c8
 
4728c8
+static int
4728c8
+def_all_tg_pt_handler(vector strvec)
4728c8
+{
4728c8
+        char * buff;
4728c8
+
4728c8
+        buff = set_value(strvec);
4728c8
+        if (!buff)
4728c8
+                return 1;
4728c8
+
4728c8
+        if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
4728c8
+            (strlen(buff) == 1 && !strcmp(buff, "0")))
4728c8
+                conf->all_tg_pt = ALL_TG_PT_OFF;
4728c8
+        else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
4728c8
+                 (strlen(buff) == 1 && !strcmp(buff, "1")))
4728c8
+                conf->all_tg_pt = ALL_TG_PT_ON;
4728c8
+        else
4728c8
+                conf->all_tg_pt = DEFAULT_ALL_TG_PT;
4728c8
+
4728c8
+        FREE(buff);
4728c8
+        return 0;
4728c8
+}
4728c8
+
4728c8
+
4728c8
 /*
4728c8
  * blacklist block handlers
4728c8
  */
4728c8
@@ -1969,6 +1992,33 @@ hw_ghost_delay_handler(vector strvec)
4728c8
 	return 0;
4728c8
 }
4728c8
 
4728c8
+static int
4728c8
+hw_all_tg_pt_handler(vector strvec)
4728c8
+{
4728c8
+	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
4728c8
+	char * buff;
4728c8
+
4728c8
+	if (!hwe)
4728c8
+		return 1;
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
+		hwe->all_tg_pt = ALL_TG_PT_OFF;
4728c8
+	else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
4728c8
+		 (strlen(buff) == 1 && !strcmp(buff, "1")))
4728c8
+		hwe->all_tg_pt = ALL_TG_PT_ON;
4728c8
+	else
4728c8
+		hwe->all_tg_pt = ALL_TG_PT_UNDEF;
4728c8
+
4728c8
+	FREE(buff);
4728c8
+	return 0;
4728c8
+}
4728c8
+
4728c8
 /*
4728c8
  * multipaths block handlers
4728c8
  */
4728c8
@@ -3325,6 +3375,19 @@ snprint_hw_ghost_delay (char * buff, int
4728c8
 }
4728c8
 
4728c8
 static int
4728c8
+snprint_hw_all_tg_pt(char * buff, int len, void * data)
4728c8
+{
4728c8
+	struct hwentry * hwe = (struct hwentry *)data;
4728c8
+
4728c8
+	if (hwe->all_tg_pt == ALL_TG_PT_ON)
4728c8
+		return snprintf(buff, len, "yes");
4728c8
+	else if (hwe->all_tg_pt == ALL_TG_PT_OFF)
4728c8
+		return snprintf(buff, len, "no");
4728c8
+	else
4728c8
+		return 0;
4728c8
+}
4728c8
+
4728c8
+static int
4728c8
 snprint_def_polling_interval (char * buff, int len, void * data)
4728c8
 {
4728c8
 	return snprintf(buff, len, "%i", conf->checkint);
4728c8
@@ -3829,6 +3892,15 @@ snprint_def_ghost_delay (char * buff, in
4728c8
 }
4728c8
 
4728c8
 static int
4728c8
+snprint_def_all_tg_pt(char * buff, int len, void * data)
4728c8
+{
4728c8
+	if (conf->all_tg_pt == ALL_TG_PT_ON)
4728c8
+		return snprintf(buff, len, "yes");
4728c8
+	else
4728c8
+		return snprintf(buff, len, "no");
4728c8
+}
4728c8
+
4728c8
+static int
4728c8
 snprint_ble_simple (char * buff, int len, void * data)
4728c8
 {
4728c8
 	struct blentry * ble = (struct blentry *)data;
4728c8
@@ -3926,6 +3998,7 @@ init_keywords(void)
4728c8
 	install_keyword("max_sectors_kb", &def_max_sectors_kb_handler, &snprint_def_max_sectors_kb);
4728c8
 	install_keyword("unpriv_sgio", &def_unpriv_sgio_handler, &snprint_def_unpriv_sgio);
4728c8
 	install_keyword("ghost_delay", &def_ghost_delay_handler, &snprint_def_ghost_delay);
4728c8
+	install_keyword("all_tg_pt", &def_all_tg_pt_handler, &snprint_def_all_tg_pt);
4728c8
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
4728c8
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
4728c8
 	__deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
4728c8
@@ -4000,6 +4073,7 @@ init_keywords(void)
4728c8
 	install_keyword("max_sectors_kb", &hw_max_sectors_kb_handler, &snprint_hw_max_sectors_kb);
4728c8
 	install_keyword("unpriv_sgio", &hw_unpriv_sgio_handler, &snprint_hw_unpriv_sgio);
4728c8
 	install_keyword("ghost_delay", &hw_ghost_delay_handler, &snprint_hw_ghost_delay);
4728c8
+	install_keyword("all_tg_pt", &hw_all_tg_pt_handler, &snprint_hw_all_tg_pt);
4728c8
 	install_sublevel_end();
4728c8
 
4728c8
 	install_keyword_root("overrides", &nop_handler);
4728c8
@@ -4031,6 +4105,9 @@ init_keywords(void)
4728c8
 	install_keyword("delay_wait_checks", &nop_handler, &snprint_nop);
4728c8
 	install_keyword("skip_kpartx", &nop_handler, &snprint_nop);
4728c8
 	install_keyword("max_sectors_kb", &nop_handler, &snprint_nop);
4728c8
+	install_keyword("unpriv_sgio", &nop_handler, &snprint_nop);
4728c8
+	install_keyword("ghost_delay", &nop_handler, &snprint_nop);
4728c8
+	install_keyword("all_tg_pt", &nop_handler, &snprint_nop);
4728c8
 
4728c8
 	install_keyword_root("multipaths", &multipaths_handler);
4728c8
 	install_keyword_multi("multipath", &multipath_handler, NULL);
4728c8
Index: multipath-tools-130222-patched/libmultipath/propsel.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/propsel.c
4728c8
+++ multipath-tools-130222-patched/libmultipath/propsel.c
4728c8
@@ -992,3 +992,23 @@ select_ghost_delay (struct multipath * m
4728c8
 	condlog(3, "ghost_delay = DISABLED (internal default)");
4728c8
 	return 0;
4728c8
 }
4728c8
+
4728c8
+extern int
4728c8
+select_all_tg_pt (struct multipath *mp)
4728c8
+{
4728c8
+	if (mp->hwe && mp->hwe->all_tg_pt != ALL_TG_PT_UNDEF) {
4728c8
+		mp->all_tg_pt = mp->hwe->all_tg_pt;
4728c8
+		condlog(3, "all_tg_pt = %i (controller setting)",
4728c8
+			mp->all_tg_pt);
4728c8
+		return 0;
4728c8
+	}
4728c8
+	if (conf->all_tg_pt != GHOST_DELAY_UNDEF) {
4728c8
+		mp->all_tg_pt = conf->all_tg_pt;
4728c8
+		condlog(3, "all_tg_pt = %i (config file default)",
4728c8
+			mp->all_tg_pt);
4728c8
+		return 0;
4728c8
+	}
4728c8
+	mp->all_tg_pt = DEFAULT_ALL_TG_PT;
4728c8
+	condlog(3, "all_tg_pt = %i (internal default)", mp->all_tg_pt);
4728c8
+	return 0;
4728c8
+}
4728c8
Index: multipath-tools-130222-patched/libmultipath/structs.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/structs.h
4728c8
+++ multipath-tools-130222-patched/libmultipath/structs.h
4728c8
@@ -154,6 +154,12 @@ enum unpriv_sgio_states {
4728c8
 	UNPRIV_SGIO_ON,
4728c8
 };
4728c8
 
4728c8
+enum all_tg_pt_states {
4728c8
+	ALL_TG_PT_UNDEF,
4728c8
+	ALL_TG_PT_OFF,
4728c8
+	ALL_TG_PT_ON,
4728c8
+};
4728c8
+
4728c8
 enum scsi_protocol {
4728c8
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
4728c8
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
4728c8
@@ -324,6 +330,7 @@ struct multipath {
4728c8
 	int prkey_source;
4728c8
 	struct be64 reservation_key;
4728c8
 	unsigned char prflag;
4728c8
+	int all_tg_pt;
4728c8
 };
4728c8
 
4728c8
 struct pathgroup {
4728c8
Index: multipath-tools-130222-patched/libmultipath/propsel.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/propsel.h
4728c8
+++ multipath-tools-130222-patched/libmultipath/propsel.h
4728c8
@@ -28,3 +28,4 @@ int select_skip_kpartx (struct multipath
4728c8
 int select_max_sectors_kb (struct multipath * mp);
4728c8
 int select_unpriv_sgio (struct multipath * mp);
4728c8
 int select_ghost_delay (struct multipath * mp);
4728c8
+int select_all_tg_pt (struct multipath *mp);
4728c8
Index: multipath-tools-130222-patched/libmultipath/defaults.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/libmultipath/defaults.h
4728c8
+++ multipath-tools-130222-patched/libmultipath/defaults.h
4728c8
@@ -29,6 +29,7 @@
4728c8
 #define DEFAULT_MAX_SECTORS_KB	MAX_SECTORS_KB_UNDEF
4728c8
 #define DEFAULT_UNPRIV_SGIO UNPRIV_SGIO_OFF
4728c8
 #define DEFAULT_GHOST_DELAY GHOST_DELAY_OFF
4728c8
+#define DEFAULT_ALL_TG_PT ALL_TG_PT_OFF
4728c8
 
4728c8
 #define DEFAULT_CHECKINT	5
4728c8
 #define MAX_CHECKINT(a)		(a << 2)
4728c8
Index: multipath-tools-130222-patched/multipath/multipath.conf.5
4728c8
===================================================================
4728c8
--- multipath-tools-130222-patched.orig/multipath/multipath.conf.5
4728c8
+++ multipath-tools-130222-patched/multipath/multipath.conf.5
4728c8
@@ -449,6 +449,13 @@ registration is removed, the RESERVATION
4728c8
 It is unset by default.
4728c8
 .RE
4728c8
 .TP
4728c8
+.B all_tg_pt
4728c8
+This must be set to \fIyes\fR to successfully use mpathpersist on arrays that
4728c8
+automatically set and clear registration keys on all target ports from a
4728c8
+host, instead of per target port per host.
4728c8
+Default is
4728c8
+.I no
4728c8
+.TP
4728c8
 .B retain_attached_hw_handler
4728c8
 If set to
4728c8
 .I yes