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