Blame SOURCES/0265-RHBZ-1721855-mpathpersist-speedup.patch

4728c8
---
4728c8
 libmpathpersist/mpath_persist.c |  230 +++++++++++------------
4728c8
 libmpathpersist/mpath_persist.h |   40 ++++
4728c8
 mpathpersist/main.c             |  223 ++++++++++++++++++-----
4728c8
 mpathpersist/main.h             |    1 
4728c8
 mpathpersist/mpathpersist.8     |  385 ++++++++++++++++++++++++++++++----------
4728c8
 5 files changed, 616 insertions(+), 263 deletions(-)
4728c8
4728c8
Index: multipath-tools-130222/mpathpersist/main.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/mpathpersist/main.c
4728c8
+++ multipath-tools-130222/mpathpersist/main.c
4728c8
@@ -18,6 +18,7 @@
4728c8
 #include <pthread.h>
4728c8
 #include <ctype.h>
4728c8
 #include <string.h>
4728c8
+#include <errno.h>
4728c8
 
4728c8
 static const char * pr_type_strs[] = {
4728c8
 	"obsolete [0]",
4728c8
@@ -46,9 +47,101 @@ int construct_transportid(const char * i
4728c8
 int logsink;
4728c8
 unsigned int mpath_mx_alloc_len;
4728c8
 
4728c8
-int main (int argc, char * argv[])
4728c8
+static int verbose, loglevel, noisy;
4728c8
+
4728c8
+static int handle_args(int argc, char * argv[], int line);
4728c8
+
4728c8
+static int do_batch_file(const char *batch_fn)
4728c8
 {
4728c8
-	int fd, c, res;
4728c8
+	char command[] = "mpathpersist";
4728c8
+	const int ARGV_CHUNK = 2;
4728c8
+	const char delims[] = " \t\n";
4728c8
+	size_t len = 0;
4728c8
+	char *line = NULL;
4728c8
+	ssize_t n;
4728c8
+	int nline = 0;
4728c8
+	int argl = ARGV_CHUNK;
4728c8
+	FILE *fl;
4728c8
+	char **argv = calloc(argl, sizeof(*argv));
4728c8
+	int ret = MPATH_PR_SUCCESS;
4728c8
+
4728c8
+	if (argv == NULL)
4728c8
+		return MPATH_PR_OTHER;
4728c8
+
4728c8
+	fl = fopen(batch_fn, "r");
4728c8
+	if (fl == NULL) {
4728c8
+		fprintf(stderr, "unable to open %s: %s\n",
4728c8
+			batch_fn, strerror(errno));
4728c8
+		free(argv);
4728c8
+		return MPATH_PR_SYNTAX_ERROR;
4728c8
+	} else {
4728c8
+		if (verbose >= 2)
4728c8
+			fprintf(stderr, "running batch file %s\n",
4728c8
+				batch_fn);
4728c8
+	}
4728c8
+
4728c8
+	while ((n = getline(&line, &len, fl)) != -1) {
4728c8
+		char *_token, *token;
4728c8
+		int argc = 0;
4728c8
+		int rv;
4728c8
+
4728c8
+		nline++;
4728c8
+		argv[argc++] = command;
4728c8
+
4728c8
+		if (line[n-1] == '\n')
4728c8
+			line[n-1] = '\0';
4728c8
+		if (verbose >= 3)
4728c8
+			fprintf(stderr, "processing line %d: %s\n",
4728c8
+				nline, line);
4728c8
+
4728c8
+		for (token = strtok_r(line, delims, &_token);
4728c8
+		     token != NULL && *token != '#';
4728c8
+		     token = strtok_r(NULL, delims, &_token)) {
4728c8
+
4728c8
+			if (argc >= argl) {
4728c8
+				int argn = argl + ARGV_CHUNK;
4728c8
+				char **tmp;
4728c8
+
4728c8
+				tmp = realloc(argv, argn * sizeof(*argv));
4728c8
+				if (tmp == NULL)
4728c8
+					break;
4728c8
+				argv = tmp;
4728c8
+				argl = argn;
4728c8
+			}
4728c8
+
4728c8
+			if (argc == 1 && !strcmp(token, command))
4728c8
+				continue;
4728c8
+
4728c8
+			argv[argc++] = token;
4728c8
+		}
4728c8
+
4728c8
+		if (argc <= 1)
4728c8
+			continue;
4728c8
+
4728c8
+		if (verbose >= 2) {
4728c8
+			int i;
4728c8
+
4728c8
+			fprintf(stderr, "## file %s line %d:", batch_fn, nline);
4728c8
+			for (i = 0; i < argc; i++)
4728c8
+				fprintf(stderr, " %s", argv[i]);
4728c8
+			fprintf(stderr, "\n");
4728c8
+		}
4728c8
+
4728c8
+		optind = 0;
4728c8
+		rv = handle_args(argc, argv, nline);
4728c8
+		if (rv != MPATH_PR_SUCCESS)
4728c8
+			ret = rv;
4728c8
+	}
4728c8
+
4728c8
+	fclose(fl);
4728c8
+	free(argv);
4728c8
+	free(line);
4728c8
+	return ret;
4728c8
+}
4728c8
+
4728c8
+static int handle_args(int argc, char * argv[], int nline)
4728c8
+{
4728c8
+	int fd, c;
4728c8
 	const char *device_name = NULL;
4728c8
 	int num_prin_sa = 0;
4728c8
 	int num_prout_sa = 0;
4728c8
@@ -69,45 +162,41 @@ int main (int argc, char * argv[])
4728c8
 	int prin = 1;
4728c8
 	int prin_sa = -1;
4728c8
 	int prout_sa = -1;
4728c8
-	int verbose = 0;
4728c8
-	int loglevel = 0;
4728c8
-	int noisy = 0;
4728c8
 	int num_transport =0;
4728c8
+	char *batch_fn = NULL;
4728c8
 	void *resp = NULL;
4728c8
 	struct transportid * tmp;
4728c8
-	struct udev *udev = NULL;
4728c8
 
4728c8
-	if (optind == argc)
4728c8
-	{
4728c8
-
4728c8
-		fprintf (stderr, "No parameter used\n");
4728c8
-		usage ();
4728c8
-		exit (1);
4728c8
-	}
4728c8
-
4728c8
-	if (getuid () != 0)
4728c8
-	{
4728c8
-		fprintf (stderr, "need to be root\n");
4728c8
-		exit (1);
4728c8
-	}
4728c8
-
4728c8
-	udev = udev_new();
4728c8
-	mpath_lib_init(udev);
4728c8
-	memset(transportids,0,MPATH_MX_TIDS);
4728c8
+ 	memset(transportids, 0, MPATH_MX_TIDS * sizeof(struct transportid));
4728c8
 
4728c8
 	while (1)
4728c8
 	{
4728c8
 		int option_index = 0;
4728c8
 
4728c8
-		c = getopt_long (argc, argv, "v:Cd:hHioZK:S:PAT:skrGILcRX:l:",
4728c8
+		c = getopt_long (argc, argv, "v:Cd:hHioZK:S:PAT:skrGILcRX:l:f:",
4728c8
 				long_options, &option_index);
4728c8
 		if (c == -1)
4728c8
 			break;
4728c8
 
4728c8
 		switch (c)
4728c8
 		{
4728c8
+			case 'f':
4728c8
+				if (nline != 0) {
4728c8
+					fprintf(stderr,
4728c8
+						"ERROR: -f option not allowed in batch file\n");
4728c8
+					ret = MPATH_PR_SYNTAX_ERROR;
4728c8
+					goto out;
4728c8
+				}
4728c8
+				if (batch_fn != NULL) {
4728c8
+					fprintf(stderr,
4728c8
+						"ERROR: -f option can be used at most once\n");
4728c8
+					ret = MPATH_PR_SYNTAX_ERROR;
4728c8
+					goto out;
4728c8
+				}
4728c8
+				batch_fn = strdup(optarg);
4728c8
+				break;
4728c8
 			case 'v':
4728c8
-				if (1 != sscanf (optarg, "%d", &loglevel))
4728c8
+				if (nline == 0 && 1 != sscanf (optarg, "%d", &loglevel))
4728c8
 				{
4728c8
 					fprintf (stderr, "bad argument to '--verbose'\n");
4728c8
 					return MPATH_PR_SYNTAX_ERROR;
4728c8
@@ -241,8 +330,7 @@ int main (int argc, char * argv[])
4728c8
                                 break;
4728c8
 
4728c8
 			default:
4728c8
-				fprintf(stderr, "unrecognised switch " "code 0x%x ??\n", c);	
4728c8
-				usage ();
4728c8
+				fprintf(stderr, "unrecognised switch " "code 0x%x ??\n", c);
4728c8
 				ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 				goto out;
4728c8
 		}
4728c8
@@ -260,27 +348,29 @@ int main (int argc, char * argv[])
4728c8
 		{
4728c8
 			for (; optind < argc; ++optind)
4728c8
 				fprintf (stderr, "Unexpected extra argument: %s\n", argv[optind]);
4728c8
-			usage ();
4728c8
 			ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 			goto out;
4728c8
 		}
4728c8
 	}
4728c8
 
4728c8
-	/* set verbosity */
4728c8
-	noisy = (loglevel >= 3) ? 1 : hex;
4728c8
-	verbose	= (loglevel >= 4)? 4 : loglevel;
4728c8
+	if (nline == 0) {
4728c8
+		/* set verbosity */
4728c8
+		noisy = (loglevel >= 3) ? 1 : hex;
4728c8
+		verbose	= (loglevel >= 4)? 4 : loglevel;
4728c8
+		ret = mpath_persistent_reserve_init_vecs(verbose);
4728c8
+		if (ret != MPATH_PR_SUCCESS)
4728c8
+			goto out;
4728c8
+	}
4728c8
 
4728c8
-	if ((prout_flag + prin_flag) == 0)
4728c8
+	if ((prout_flag + prin_flag) == 0 && batch_fn == NULL)
4728c8
 	{
4728c8
 		fprintf (stderr, "choose either '--in' or '--out' \n");
4728c8
-		usage ();
4728c8
 		ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
 	if ((prout_flag + prin_flag) > 1)
4728c8
 	{
4728c8
 		fprintf (stderr, "choose either '--in' or '--out' \n");
4728c8
-		usage ();
4728c8
 		ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
@@ -311,21 +401,19 @@ int main (int argc, char * argv[])
4728c8
 		{
4728c8
 			fprintf (stderr,
4728c8
 					" No service action given for Persistent Reserve IN\n");
4728c8
-			usage();
4728c8
 			ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		}
4728c8
 		else if (num_prin_sa > 1)
4728c8
 		{
4728c8
 			fprintf (stderr, " Too many service actions given; choose "
4728c8
 					"one only\n");
4728c8
-			usage();
4728c8
 			ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		}
4728c8
 	}
4728c8
 	else
4728c8
 	{
4728c8
-		usage ();
4728c8
-		ret = MPATH_PR_SYNTAX_ERROR;
4728c8
+		if (batch_fn == NULL)
4728c8
+			ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
 
4728c8
@@ -333,7 +421,6 @@ int main (int argc, char * argv[])
4728c8
 	{
4728c8
 		fprintf (stderr, " --relative-target-port"
4728c8
 				" only useful with --register-move\n");
4728c8
-		usage ();
4728c8
 		ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
@@ -355,7 +442,6 @@ int main (int argc, char * argv[])
4728c8
 	if (device_name == NULL)
4728c8
 	{
4728c8
 		fprintf (stderr, "No device name given \n");
4728c8
-		usage ();
4728c8
 		ret = MPATH_PR_SYNTAX_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
@@ -382,7 +468,7 @@ int main (int argc, char * argv[])
4728c8
 			goto out;
4728c8
 		}
4728c8
 
4728c8
-		ret = mpath_persistent_reserve_in (fd, prin_sa, resp, noisy, verbose);
4728c8
+		ret = __mpath_persistent_reserve_in (fd, prin_sa, resp, noisy);
4728c8
 		if (ret != MPATH_PR_SUCCESS )
4728c8
 		{
4728c8
 			fprintf (stderr, "Persistent Reserve IN command failed\n");
4728c8
@@ -442,8 +528,8 @@ int main (int argc, char * argv[])
4728c8
 		}
4728c8
 
4728c8
 		/* PROUT commands other than 'register and move' */
4728c8
-		ret = mpath_persistent_reserve_out (fd, prout_sa, 0, prout_type,
4728c8
-				paramp, noisy, verbose);
4728c8
+		ret = __mpath_persistent_reserve_out (fd, prout_sa, 0, prout_type,
4728c8
+				paramp, noisy);
4728c8
 		for (j = 0 ; j < num_transport; j++)
4728c8
 		{
4728c8
 			tmp = paramp->trnptid_list[j];
4728c8
@@ -466,17 +552,57 @@ int main (int argc, char * argv[])
4728c8
 		printf("PR out: command failed\n");
4728c8
 	}
4728c8
 
4728c8
-	res = close (fd);
4728c8
-	if (res < 0)
4728c8
+	close (fd);
4728c8
+
4728c8
+out :
4728c8
+	if (ret == MPATH_PR_SYNTAX_ERROR) {
4728c8
+		free(batch_fn);
4728c8
+		if (nline == 0)
4728c8
+			usage();
4728c8
+		else
4728c8
+			fprintf(stderr, "syntax error on line %d in batch file\n",
4728c8
+				nline);
4728c8
+	} else if (batch_fn != NULL) {
4728c8
+		int rv = do_batch_file(batch_fn);
4728c8
+
4728c8
+		free(batch_fn);
4728c8
+		ret = ret == 0 ? rv : ret;
4728c8
+	}
4728c8
+	if (nline == 0)
4728c8
+		mpath_persistent_reserve_free_vecs();
4728c8
+	return (ret >= 0) ? ret : MPATH_PR_OTHER;
4728c8
+}
4728c8
+
4728c8
+int main(int argc, char *argv[])
4728c8
+{
4728c8
+	struct udev *udev;
4728c8
+	int ret;
4728c8
+
4728c8
+	if (optind == argc)
4728c8
+	{
4728c8
+
4728c8
+		fprintf (stderr, "No parameter used\n");
4728c8
+		usage ();
4728c8
+		exit (1);
4728c8
+	}
4728c8
+
4728c8
+	if (getuid () != 0)
4728c8
 	{
4728c8
-		mpath_lib_exit();
4728c8
+		fprintf (stderr, "need to be root\n");
4728c8
+		exit (1);
4728c8
+	}
4728c8
+
4728c8
+	udev = udev_new();
4728c8
+	if(mpath_lib_init(udev) != 0) {
4728c8
 		udev_unref(udev);
4728c8
-		return MPATH_PR_FILE_ERROR;
4728c8
+		exit(1);
4728c8
 	}
4728c8
 
4728c8
-out :
4728c8
+	ret = handle_args(argc, argv, 0);
4728c8
+
4728c8
 	mpath_lib_exit();
4728c8
 	udev_unref(udev);
4728c8
+
4728c8
 	return (ret >= 0) ? ret : MPATH_PR_OTHER;
4728c8
 }
4728c8
 
4728c8
@@ -677,6 +803,7 @@ static void usage()
4728c8
 			"                   4           Informational messages with trace enabled\n"
4728c8
 			"    --clear|-C                 PR Out: Clear\n"
4728c8
 			"    --device=DEVICE|-d DEVICE  query or change DEVICE\n"
4728c8
+			"    --batch-file|-f FILE       run commands from FILE\n"
4728c8
 			"    --help|-h                  output this usage message\n"
4728c8
 			"    --hex|-H                   output response in hex\n"
4728c8
 			"    --in|-i                    request PR In command \n"
4728c8
Index: multipath-tools-130222/mpathpersist/main.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/mpathpersist/main.h
4728c8
+++ multipath-tools-130222/mpathpersist/main.h
4728c8
@@ -2,6 +2,7 @@ static struct option long_options[] = {
4728c8
 	{"verbose", 1, 0, 'v'},
4728c8
 	{"clear", 0, 0, 'C'},
4728c8
 	{"device", 1, 0, 'd'},
4728c8
+	{"batch-file", 1, 0, 'f' },
4728c8
 	{"help", 0, 0, 'h'},
4728c8
 	{"hex", 0, 0, 'H'},
4728c8
 	{"in", 0, 0, 'i'},
4728c8
Index: multipath-tools-130222/libmpathpersist/mpath_persist.c
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/libmpathpersist/mpath_persist.c
4728c8
+++ multipath-tools-130222/libmpathpersist/mpath_persist.c
4728c8
@@ -16,6 +16,7 @@
4728c8
 #include <config.h>
4728c8
 #include <switchgroup.h>
4728c8
 #include <discovery.h>
4728c8
+#include <configure.h>
4728c8
 #include <dmparser.h>
4728c8
 #include <ctype.h>
4728c8
 #include <propsel.h>
4728c8
@@ -80,17 +81,21 @@ updatepaths (struct multipath * mpp)
4728c8
 					pp->state = PATH_DOWN;
4728c8
 					continue;
4728c8
 				}
4728c8
-				pp->mpp = mpp;
4728c8
-				pathinfo(pp, conf->hwtable, DI_ALL);
4728c8
-				continue;
4728c8
 			}
4728c8
 			pp->mpp = mpp;
4728c8
+			if (pp->udev == NULL) {
4728c8
+				pp->udev = udev_device_new_from_devnum(conf->udev, 'b', parse_devt(pp->dev_t));
4728c8
+				if (pp->udev == NULL) {
4728c8
+					pp->state = PATH_DOWN;
4728c8
+					continue;
4728c8
+				}
4728c8
+				pathinfo(pp, conf->hwtable,
4728c8
+					 DI_SYSFS|DI_CHECKER);
4728c8
+				continue;
4728c8
+			}
4728c8
 			if (pp->state == PATH_UNCHECKED ||
4728c8
 					pp->state == PATH_WILD)
4728c8
 				pathinfo(pp, conf->hwtable, DI_CHECKER);
4728c8
-
4728c8
-			if (pp->priority == PRIO_UNDEF)
4728c8
-				pathinfo(pp, conf->hwtable, DI_PRIO);
4728c8
 		}
4728c8
 	}
4728c8
 	return 0;
4728c8
@@ -129,45 +134,44 @@ mpath_prin_activepath (struct multipath
4728c8
 
4728c8
 int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp *resp, int noisy, int verbose)
4728c8
 {
4728c8
-	struct stat info;
4728c8
-	vector curmp = NULL;
4728c8
-	vector pathvec = NULL;
4728c8
-	char * alias;
4728c8
-	struct multipath * mpp;
4728c8
-	int map_present;
4728c8
-	int major, minor;
4728c8
-	int ret;
4728c8
+	int ret = mpath_persistent_reserve_init_vecs(verbose);
4728c8
 
4728c8
-	conf->verbosity = verbose;
4728c8
+	if (ret != MPATH_PR_SUCCESS)
4728c8
+		return ret;
4728c8
+	ret = __mpath_persistent_reserve_in(fd, rq_servact, resp, noisy);
4728c8
+	mpath_persistent_reserve_free_vecs();
4728c8
+	return ret;
4728c8
+}
4728c8
 
4728c8
-	if (fstat( fd, &info) != 0){
4728c8
-		condlog(0, "stat error %d", fd);
4728c8
-		return MPATH_PR_FILE_ERROR;
4728c8
-	} 
4728c8
-	if(!S_ISBLK(info.st_mode)){
4728c8
-		condlog(0, "Failed to get major:minor. fd = %d", fd);
4728c8
-		return MPATH_PR_FILE_ERROR;
4728c8
-	}
4728c8
+int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
4728c8
+	unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy, int verbose)
4728c8
+{
4728c8
+	int ret = mpath_persistent_reserve_init_vecs(verbose);
4728c8
 
4728c8
-	major = (int)MAJOR(info.st_rdev);
4728c8
-	minor = (int)MINOR(info.st_rdev);	
4728c8
-	condlog(4, "Device %d:%d:  ", major, minor);
4728c8
+	if (ret != MPATH_PR_SUCCESS)
4728c8
+		return ret;
4728c8
+	ret = __mpath_persistent_reserve_out(fd, rq_servact, rq_scope, rq_type,
4728c8
+					     paramp, noisy);
4728c8
+	mpath_persistent_reserve_free_vecs();
4728c8
+	return ret;
4728c8
+}
4728c8
 
4728c8
-	/* get alias from major:minor*/
4728c8
-	alias = dm_mapname(major, minor);
4728c8
-	if (!alias){
4728c8
-		condlog(0, "%d:%d failed to get device alias.", major, minor);
4728c8
-		return MPATH_PR_DMMP_ERROR;
4728c8
-	}
4728c8
+static vector curmp;
4728c8
+static vector pathvec;
4728c8
 
4728c8
-	condlog(3, "alias = %s", alias);
4728c8
-	map_present = dm_map_present(alias);
4728c8
-	if (map_present && !dm_is_mpath(alias)){
4728c8
-		condlog( 0, "%s: not a multipath device.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out;
4728c8
-	}
4728c8
+void mpath_persistent_reserve_free_vecs(void)
4728c8
+{
4728c8
+	free_multipathvec(curmp, KEEP_PATHS);
4728c8
+	free_pathvec(pathvec, FREE_PATHS);
4728c8
+	curmp = pathvec = NULL;
4728c8
+}
4728c8
+
4728c8
+int mpath_persistent_reserve_init_vecs(int verbose)
4728c8
+{
4728c8
+	conf->verbosity = verbose;
4728c8
 
4728c8
+	if (curmp)
4728c8
+		return MPATH_PR_SUCCESS;
4728c8
 	/*
4728c8
 	 * allocate core vectors to store paths and multipaths
4728c8
 	 */
4728c8
@@ -175,63 +179,32 @@ int mpath_persistent_reserve_in (int fd,
4728c8
 	pathvec = vector_alloc ();
4728c8
 
4728c8
 	if (!curmp || !pathvec){
4728c8
-		condlog (0, "%s: vector allocation failed.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out;
4728c8
-	}
4728c8
-
4728c8
-	if (path_discovery(pathvec, conf, DI_SYSFS | DI_CHECKER) < 0) {
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
-	}
4728c8
-
4728c8
-	/* get info of all paths from the dm device	*/
4728c8
-	if (get_mpvec (curmp, pathvec, alias)){
4728c8
-		condlog(0, "%s: failed to get device info.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
+		condlog (0, "vector allocation failed.");
4728c8
+		goto err;
4728c8
 	}
4728c8
 
4728c8
-	mpp = find_mp_by_alias(curmp, alias);
4728c8
-	if (!mpp){
4728c8
-		condlog(0, "%s: devmap not registered.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
-	}
4728c8
+	if (dm_get_maps(curmp))
4728c8
+		goto err;
4728c8
 
4728c8
-	ret = mpath_prin_activepath(mpp, rq_servact, resp, noisy);
4728c8
+	return MPATH_PR_SUCCESS;
4728c8
 
4728c8
-out1:
4728c8
-	free_multipathvec(curmp, KEEP_PATHS);
4728c8
-	free_pathvec(pathvec, FREE_PATHS);	
4728c8
-out:
4728c8
-	FREE(alias);
4728c8
-	return ret; 						
4728c8
+err:
4728c8
+	mpath_persistent_reserve_free_vecs();
4728c8
+	return MPATH_PR_DMMP_ERROR;
4728c8
 }
4728c8
 
4728c8
-int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
4728c8
-		unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy, int verbose)
4728c8
+static int mpath_get_map(int fd, char **palias, struct multipath **pmpp)
4728c8
 {
4728c8
-
4728c8
+	int ret = MPATH_PR_DMMP_ERROR;
4728c8
 	struct stat info;
4728c8
-
4728c8
-	vector curmp = NULL;
4728c8
-	vector pathvec = NULL;
4728c8
-
4728c8
-	char * alias;
4728c8
-	struct multipath * mpp;
4728c8
-	int map_present;
4728c8
 	int major, minor;
4728c8
-	int ret;
4728c8
-	uint64_t prkey;
4728c8
-
4728c8
-	conf->verbosity = verbose;
4728c8
+	char *alias;
4728c8
+	struct multipath *mpp;
4728c8
 
4728c8
-	if (fstat( fd, &info) != 0){
4728c8
+	if (fstat(fd, &info) != 0){
4728c8
 		condlog(0, "stat error fd=%d", fd);
4728c8
 		return MPATH_PR_FILE_ERROR;
4728c8
 	}
4728c8
-
4728c8
 	if(!S_ISBLK(info.st_mode)){
4728c8
 		condlog(3, "Failed to get major:minor. fd=%d", fd);
4728c8
 		return MPATH_PR_FILE_ERROR;	
4728c8
@@ -241,53 +214,72 @@ int mpath_persistent_reserve_out ( int f
4728c8
 	minor = (int)MINOR(info.st_rdev);
4728c8
 	condlog(4, "Device  %d:%d", major, minor);
4728c8
 
4728c8
-	/* get WWN of the device from major:minor*/
4728c8
+	/* get alias from major:minor*/
4728c8
 	alias = dm_mapname(major, minor);
4728c8
 	if (!alias){
4728c8
+		condlog(0, "%d:%d failed to get device alias.", major, minor);
4728c8
 		return MPATH_PR_DMMP_ERROR;
4728c8
 	}
4728c8
 
4728c8
 	condlog(3, "alias = %s", alias);
4728c8
-	map_present = dm_map_present(alias);
4728c8
 
4728c8
-	if (map_present && !dm_is_mpath(alias)){
4728c8
+	if (dm_map_present(alias) && !dm_is_mpath(alias)){
4728c8
 		condlog(3, "%s: not a multipath device.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out;
4728c8
-	}
4728c8
-
4728c8
-	/*
4728c8
-	 * allocate core vectors to store paths and multipaths
4728c8
-	 */
4728c8
-	curmp = vector_alloc ();
4728c8
-	pathvec = vector_alloc ();
4728c8
-
4728c8
-	if (!curmp || !pathvec){
4728c8
-		condlog (0, "%s: vector allocation failed.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
 		goto out;
4728c8
 	}
4728c8
 
4728c8
-	if (path_discovery(pathvec, conf, DI_SYSFS | DI_CHECKER) < 0) {
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
-	}
4728c8
-
4728c8
 	/* get info of all paths from the dm device     */
4728c8
 	if (get_mpvec(curmp, pathvec, alias)){
4728c8
 		condlog(0, "%s: failed to get device info.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
+		goto out;
4728c8
 	}
4728c8
 
4728c8
 	mpp = find_mp_by_alias(curmp, alias);
4728c8
 
4728c8
 	if (!mpp) {
4728c8
 		condlog(0, "%s: devmap not registered.", alias);
4728c8
-		ret = MPATH_PR_DMMP_ERROR;
4728c8
-		goto out1;
4728c8
+		goto out;
4728c8
 	}
4728c8
 
4728c8
+	ret = MPATH_PR_SUCCESS;
4728c8
+	if (pmpp)
4728c8
+		*pmpp = mpp;
4728c8
+	if (palias) {
4728c8
+		*palias = alias;
4728c8
+		alias = NULL;
4728c8
+	}
4728c8
+out:
4728c8
+	FREE(alias);
4728c8
+	return ret;
4728c8
+}
4728c8
+
4728c8
+int __mpath_persistent_reserve_in (int fd, int rq_servact,
4728c8
+	struct prin_resp *resp, int noisy)
4728c8
+{
4728c8
+	struct multipath *mpp;
4728c8
+	int ret;
4728c8
+
4728c8
+	ret = mpath_get_map(fd, NULL, &mpp;;
4728c8
+	if (ret != MPATH_PR_SUCCESS)
4728c8
+		return ret;
4728c8
+
4728c8
+	ret = mpath_prin_activepath(mpp, rq_servact, resp, noisy);
4728c8
+
4728c8
+	return ret;
4728c8
+}
4728c8
+
4728c8
+int __mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
4728c8
+	unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy)
4728c8
+{
4728c8
+	struct multipath *mpp;
4728c8
+	char *alias;
4728c8
+	int ret;
4728c8
+	uint64_t prkey;
4728c8
+
4728c8
+	ret = mpath_get_map(fd, &alias, &mpp;;
4728c8
+	if (ret != MPATH_PR_SUCCESS)
4728c8
+		return ret;
4728c8
+
4728c8
 	select_reservation_key(mpp);
4728c8
 	select_all_tg_pt(mpp);
4728c8
 
4728c8
@@ -350,10 +342,6 @@ int mpath_persistent_reserve_out ( int f
4728c8
 		}
4728c8
 	}
4728c8
 out1:
4728c8
-	free_multipathvec(curmp, KEEP_PATHS);
4728c8
-	free_pathvec(pathvec, FREE_PATHS);
4728c8
-
4728c8
-out:
4728c8
 	FREE(alias);
4728c8
 	return ret; 
4728c8
 }
4728c8
@@ -365,21 +353,22 @@ get_mpvec (vector curmp, vector pathvec,
4728c8
 	struct multipath *mpp;
4728c8
 	char params[PARAMS_SIZE], status[PARAMS_SIZE];
4728c8
 
4728c8
-	if (dm_get_maps (curmp)){
4728c8
-		return 1;
4728c8
-	}
4728c8
-
4728c8
 	vector_foreach_slot (curmp, mpp, i){
4728c8
 		/*
4728c8
 		 * discard out of scope maps
4728c8
 		 */
4728c8
-		if (mpp->alias && refwwid && strncmp (mpp->alias, refwwid, WWID_SIZE)){
4728c8
-			free_multipath (mpp, KEEP_PATHS);
4728c8
-			vector_del_slot (curmp, i);
4728c8
-			i--;
4728c8
+		if (!mpp->alias) {
4728c8
+			condlog(0, "%s: map with empty alias!", __func__);
4728c8
 			continue;
4728c8
 		}
4728c8
 
4728c8
+		if (mpp->pg != NULL)
4728c8
+			/* Already seen this one */
4728c8
+			continue;
4728c8
+
4728c8
+		if (refwwid && strncmp (mpp->alias, refwwid, WWID_SIZE - 1))
4728c8
+			continue;
4728c8
+
4728c8
 		dm_get_map(mpp->alias, &mpp->size, params);
4728c8
 		condlog(3, "params = %s", params);
4728c8
 		dm_get_status(mpp->alias, status);
4728c8
@@ -392,7 +381,6 @@ get_mpvec (vector curmp, vector pathvec,
4728c8
 		 * about them
4728c8
 		 */
4728c8
 		updatepaths(mpp);
4728c8
-		mpp->bestpg = select_path_group (mpp);
4728c8
 		disassemble_status (status, mpp);
4728c8
 
4728c8
 	}
4728c8
Index: multipath-tools-130222/libmpathpersist/mpath_persist.h
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/libmpathpersist/mpath_persist.h
4728c8
+++ multipath-tools-130222/libmpathpersist/mpath_persist.h
4728c8
@@ -212,6 +212,15 @@ extern int mpath_persistent_reserve_in (
4728c8
 
4728c8
 /*
4728c8
  * DESCRIPTION :
4728c8
+ * This function is like mpath_persistent_reserve_in(), except that it doesn't call
4728c8
+ * mpath_persistent_reserve_init_vecs() and mpath_persistent_reserve_free_vecs()
4728c8
+ * before and after the actual PR call.
4728c8
+ */
4728c8
+extern int __mpath_persistent_reserve_in(int fd, int rq_servact,
4728c8
+		struct prin_resp *resp, int noisy);
4728c8
+
4728c8
+/*
4728c8
+ * DESCRIPTION :
4728c8
  * This function sends PROUT command to the DM device and get the response.
4728c8
  *
4728c8
  * @fd: The file descriptor of a multipath device. Input argument.
4728c8
@@ -235,6 +244,37 @@ extern int mpath_persistent_reserve_in (
4728c8
 extern int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
4728c8
 		unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy,
4728c8
 		int verbose);
4728c8
+/*
4728c8
+ * DESCRIPTION :
4728c8
+ * This function is like mpath_persistent_reserve_out(), except that it doesn't call
4728c8
+ * mpath_persistent_reserve_init_vecs() and mpath_persistent_reserve_free_vecs()
4728c8
+ * before and after the actual PR call.
4728c8
+ */
4728c8
+extern int __mpath_persistent_reserve_out( int fd, int rq_servact, int rq_scope,
4728c8
+		unsigned int rq_type, struct prout_param_descriptor *paramp,
4728c8
+		int noisy);
4728c8
+
4728c8
+/*
4728c8
+ * DESCRIPTION :
4728c8
+ * This function allocates data structures and performs basic initialization and
4728c8
+ * device discovery for later calls of __mpath_persistent_reserve_in() or
4728c8
+ * __mpath_persistent_reserve_out().
4728c8
+ * @verbose: Set verbosity level. Input argument. value:0 to 3. 0->disabled, 3->Max verbose
4728c8
+ *
4728c8
+ * RESTRICTIONS:
4728c8
+ *
4728c8
+ * RETURNS: MPATH_PR_SUCCESS if successful else returns any of the status specified
4728c8
+ *       above in RETURN_STATUS.
4728c8
+ */
4728c8
+int mpath_persistent_reserve_init_vecs(int verbose);
4728c8
+
4728c8
+/*
4728c8
+ * DESCRIPTION :
4728c8
+ * This function frees data structures allocated by
4728c8
+ * mpath_persistent_reserve_init_vecs().
4728c8
+ */
4728c8
+void mpath_persistent_reserve_free_vecs(void);
4728c8
+
4728c8
 
4728c8
 #ifdef __cplusplus
4728c8
 }
4728c8
Index: multipath-tools-130222/mpathpersist/mpathpersist.8
4728c8
===================================================================
4728c8
--- multipath-tools-130222.orig/mpathpersist/mpathpersist.8
4728c8
+++ multipath-tools-130222/mpathpersist/mpathpersist.8
4728c8
@@ -1,99 +1,296 @@
4728c8
-.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.39.2.
4728c8
-.TH MPATHPERSIST  "8" "April 2011" "mpathpersist" "User Commands"
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.\" Update the date below if you make any significant change.
4728c8
+.\" Make sure there are no errors with:
4728c8
+.\" groff -z -wall -b -e -t mpathpersist/mpathpersist.8
4728c8
+.\"
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+.TH MPATHPERSIST 8 2019-05-27 "Linux"
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
 .SH NAME
4728c8
-mpathpersist
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+mpathpersist \- Manages SCSI persistent reservations on dm multipath devices.
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
 .SH SYNOPSIS
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
 .B mpathpersist
4728c8
-[\fIOPTIONS\fR] [\fIDEVICE\fR]
4728c8
+.RB [\| OPTIONS \|]
4728c8
+.I device
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
 .SH DESCRIPTION
4728c8
-.IP
4728c8
-Options:
4728c8
-.TP
4728c8
-\fB\-\-verbose\fR|\-v level
4728c8
-verbosity level
4728c8
-.TP
4728c8
-0
4728c8
-Critical and error messages
4728c8
-.TP
4728c8
-1
4728c8
-Warning messages
4728c8
-.TP
4728c8
-2
4728c8
-Informational messages
4728c8
-.TP
4728c8
-3
4728c8
-Informational messages with trace enabled
4728c8
-.TP
4728c8
-\fB\-\-clear\fR|\-C
4728c8
-PR Out: Clear
4728c8
-.TP
4728c8
-\fB\-\-device\fR=\fIDEVICE\fR|\-d DEVICE
4728c8
-query or change DEVICE
4728c8
-.TP
4728c8
-\fB\-\-help\fR|\-h
4728c8
-output this usage message
4728c8
-.TP
4728c8
-\fB\-\-hex\fR|\-H
4728c8
-output response in hex
4728c8
-.TP
4728c8
-\fB\-\-in\fR|\-i
4728c8
-request PR In command
4728c8
-.TP
4728c8
-\fB\-\-out\fR|\-o
4728c8
-request PR Out command
4728c8
-.TP
4728c8
-\fB\-\-param\-aptpl\fR|\-Z
4728c8
-PR Out parameter 'APTPL'
4728c8
-.TP
4728c8
-\fB\-\-read\-keys\fR|\-k
4728c8
-PR In: Read Keys
4728c8
-.TP
4728c8
-\fB\-\-param\-rk\fR=\fIRK\fR|\-K RK
4728c8
-PR Out parameter reservation key (RK is in hex)
4728c8
-.TP
4728c8
-\fB\-\-param\-sark\fR=\fISARK\fR|\-S SARK
4728c8
-PR Out parameter service action
4728c8
-reservation key (SARK is in hex)
4728c8
-.TP
4728c8
-\fB\-\-preempt\fR|\-P
4728c8
-PR Out: Preempt
4728c8
-.TP
4728c8
-\fB\-\-preempt\-abort\fR|\-A
4728c8
-PR Out: Preempt and Abort
4728c8
-.TP
4728c8
-\fB\-\-prout\-type\fR=\fITYPE\fR|\-T TYPE
4728c8
-PR Out command type
4728c8
-.TP
4728c8
-\fB\-\-read\-status\fR|\-s
4728c8
-PR In: Read Full Status
4728c8
-.TP
4728c8
-\fB\-\-read\-keys\fR|\-k
4728c8
-PR In: Read Keys
4728c8
-.TP
4728c8
-\fB\-\-read\-reservation\fR|\-r
4728c8
-PR In: Read Reservation
4728c8
-.TP
4728c8
-\fB\-\-register\fR|\-G
4728c8
-PR Out: Register
4728c8
-.TP
4728c8
-\fB\-\-register\-ignore\fR|\-I
4728c8
-PR Out: Register and Ignore
4728c8
-.TP
4728c8
-\fB\-\-release\fR|\-L
4728c8
-PR Out: Release
4728c8
-.TP
4728c8
-\fB\-\-report\-capabilities\fR|\-c
4728c8
-PR In: Report Capabilities
4728c8
-.TP
4728c8
-\fB\-\-reserve\fR|\-R
4728c8
-PR Out: Reserve
4728c8
-.TP
4728c8
-\fB\-\-transport\-id\fR=\fITIDS\fR|\-X TIDS
4728c8
-TransportIDs can be mentioned
4728c8
-in several forms
4728c8
-.IP
4728c8
-Examples:
4728c8
-.IP
4728c8
-mpathpersist \fB\-\-out\fR \fB\-\-register\fR \fB\-\-param\-sark\fR=\fI123abc\fR \fB\-\-prout\-type\fR=\fI5\fR /dev/mapper/mpath9
4728c8
-mpathpersist \fB\-i\fR \fB\-k\fR /dev/mapper/mpath9
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+This utility is used to manage SCSI persistent reservations on Device Mapper
4728c8
+Multipath devices. To be able to use this functionality, the \fIreservation_key\fR
4728c8
+attribute must be defined in the \fI/etc/multipath.conf\fR file. Otherwise the
4728c8
+\fBmultipathd\fR daemon will not check for persistent reservation for newly
4728c8
+discovered paths or reinstated paths.
4728c8
+.
4728c8
+.LP
4728c8
+\fBmpathpersist\fR supports the same command-line options as the
4728c8
+\fBsg_persist\fR utility.
4728c8
+.
4728c8
+Consult the \fBsg_persist (8)\fR manual page for an in-depth discussion of the
4728c8
+various options.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.SH OPTIONS
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+.TP
4728c8
+.BI \-verbose|\-v " level"
4728c8
+Verbosity:
4728c8
+.RS
4728c8
+.TP 5
4728c8
+.I 0
4728c8
+Critical messages.
4728c8
+.TP
4728c8
+.I 1
4728c8
+Error messages.
4728c8
+.TP
4728c8
+.I 2
4728c8
+Warning messages.
4728c8
+.TP
4728c8
+.I 3
4728c8
+Informational messages.
4728c8
+.TP
4728c8
+.I 4
4728c8
+Informational messages with trace enabled.
4728c8
+.RE
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--device=\fIDEVICE\fB|\-d " DEVICE"
4728c8
+Query or change DEVICE.
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--batch-file=\fIDEVICE\fB|\-f " FILE"
4728c8
+Read commands from \fIFILE\fR. See section \(dqBATCH FILES\(dq below. This
4728c8
+option can be given at most once.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--help|\-h
4728c8
+Output this usage message.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--hex|\-H
4728c8
+Output response in hex.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--in|\-i
4728c8
+Request PR In command.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--out|\-o
4728c8
+Request PR Out command.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--param-aptpl|\-Z
4728c8
+PR Out parameter 'APTPL'.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--read-keys|\-k
4728c8
+PR In: Read Keys.
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--param-rk=\fIRK\fB|\-K " RK"
4728c8
+PR Out parameter reservation key (RK is in hex, up to 8 bytes).
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--param-sark=\fISARK\fB|\-S " SARK"
4728c8
+PR Out parameter service action reservation key (SARK is in hex).
4728c8
+.
4728c8
+.TP
4728c8
+.B \--preempt|\-P
4728c8
+PR Out: Preempt.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--clear|\-C
4728c8
+PR Out: Clear registrations.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--preempt-abort|\-A
4728c8
+PR Out: Preempt and Abort.
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--prout-type=\fITYPE\fB|\-T " TYPE"
4728c8
+PR Out command type.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--read-full-status|\-s
4728c8
+PR In: Read Full Status.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--read-keys|\-k
4728c8
+PR In: Read Keys.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--read-reservation|\-r
4728c8
+PR In: Read Reservation.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--register|\-G
4728c8
+PR Out: Register.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--register-ignore|\-I
4728c8
+PR Out: Register and Ignore.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--release|\-L
4728c8
+PR Out: Release.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--report-capabilities|\-c
4728c8
+PR In: Report Capabilities.
4728c8
+.
4728c8
+.TP
4728c8
+.B \--reserve|\-R
4728c8
+PR Out: Reserve.
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--transport-id=\fITIDS\fB|\-X " TIDS"
4728c8
+TransportIDs can be mentioned in several forms.
4728c8
+.
4728c8
+.TP
4728c8
+.BI \--alloc-length=\fILEN\fB|\-l " LEN"
4728c8
+PR In: maximum allocation length. LEN is a decimal number between 0 and 8192.
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.SH EXAMPLE
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+.PP
4728c8
+Register the key \(dq123abc\(dq for the /dev/mapper/mpath9 device:
4728c8
+.RS
4728c8
+\fBmpathpersist --out --register --param-sark=\fI123abc /dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Read registered reservation keys for the /dev/mapper/mpath9 device:
4728c8
+.RS
4728c8
+\fBmpathpersist -i -k \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Create a reservation for the /dev/mapper/mpath9 device with the given
4728c8
+reservation key:
4728c8
+.RS
4728c8
+\fBmpathpersist --out --reserve --param-rk=\fI123abc \fB--prout-type=\fI8 \fB-d \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Read the reservation status of the /dev/mapper/mpath9 device:
4728c8
+.RS
4728c8
+\fBmpathpersist -i -s -d \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Release the previously created reservation (note that the prout-type needs to
4728c8
+be the same as above):
4728c8
+.RS
4728c8
+\fBmpathpersist --out --release --param-rk=\fI123abc \fB--prout-type=\fI8 \fB-d \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Remove the current key registered for this host (i.e. reset it to 0):
4728c8
+.RS
4728c8
+\fBmpathpersist --out --register-ignore -K \fI123abc\fB -S \fI0\fB \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.PP
4728c8
+Remove current reservation, and unregister all registered keys from all I_T nexuses:
4728c8
+.RS
4728c8
+\fBmpathpersist -oCK \fI123abc \fI/dev/mapper/mpath9\fR
4728c8
+.RE
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.SH BATCH FILES
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+.PP
4728c8
+The option \fI--batch-file\fR (\fI-f\fR) sets an input file to be processed
4728c8
+by \fBmpathpersist\fR. Grouping commands in batch files can provide a speed
4728c8
+improvement in particular on large installments, because \fBmpathpersist\fR
4728c8
+needs to scan existing paths and maps only once during startup.
4728c8
+.
4728c8
+.PP
4728c8
+The input file is a text file that is parsed
4728c8
+line by line. Every line of the file is interpreted as a command line
4728c8
+(i.e. list of options and parameters) for \fBmpathpersist\fR. Options
4728c8
+and parameters are separated by one or more whitespace characters (space or TAB).
4728c8
+Lines can, but do not have to, begin with the word \(dqmpathpersist\(dq.
4728c8
+The \(dq#\(dq character, either at the beginning of the line or following
4728c8
+some whitespace, denotes the start of a comment that lasts until the end of the
4728c8
+line. Empty lines are allowed. Continuation of mpathpersist commands over
4728c8
+multiple lines is not supported.
4728c8
+.
4728c8
+.PP
4728c8
+All options listed in this man page, except \fI-f\fR and
4728c8
+\fI-v\fR, are allowed in batch files. Both short and long option formats may be used.
4728c8
+Using the  \fI-f\fR option inside the batch file is an error. The \fI-v\fR
4728c8
+option is ignored in batch files.
4728c8
+.
4728c8
+.PP
4728c8
+The multipath map on which to act must be specified on every input line, e.g. using the \fI-d\fR option.
4728c8
+Commands acting on different multipath maps may be combined in a
4728c8
+batch file, and multiple commands may act on the same multipath
4728c8
+map. Commands are executed one by one, so
4728c8
+that commands further down in the file see status changes caused by previous
4728c8
+commands.
4728c8
+If \fBmpathpersist\fR encounters an error while processing a line in the
4728c8
+batch file, batch file processing is \fBnot\fR aborted; subsequent commands
4728c8
+are executed nonetheless. The exit status of \fBmpathpersist\fR is the status
4728c8
+of the first failed command, or 0 if all commands succeeded.
4728c8
+.
4728c8
+.PP
4728c8
+If other options and parameters are used along with
4728c8
+\fI-f\fR on the \fBmpathpersist\fR command line, the command line will be executed first, followed
4728c8
+by the commands from the the batch file.
4728c8
+.
4728c8
+.PP
4728c8
+Below is an example of a valid batch input file.
4728c8
+.
4728c8
 .PP
4728c8
+.RS
4728c8
+.EX
4728c8
+# This is an mpathpersist input file.
4728c8
+# Short and long forms of the same command
4728c8
+-i -k /dev/dm-1 # short form, this comment is ignored
4728c8
+mpathpersist --in --read-keys --device=/dev/dm-1
4728c8
+
4728c8
+# Mixing of long and short options, variable white space
4728c8
+  --out  --register    -S  abcde     /dev/dm-1
4728c8
+
4728c8
+# Mixing of commands for different maps
4728c8
+-ir /dev/dm-0
4728c8
+-ir /dev/dm-1
4728c8
+
4728c8
+mpathpersist --out --param-rk abcde --reserve --prout-type 5 /dev/dm-1
4728c8
+# This should now show a reservation
4728c8
+-ir /dev/dm-1
4728c8
+-oCK abcde /dev/dm-1
4728c8
+--in --read-reservation /dev/dm-1
4728c8
+.EE
4728c8
+.RE
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.SH "SEE ALSO"
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+.BR multipath (8),
4728c8
+.BR multipathd (8),
4728c8
+.BR sg_persist (8).
4728c8
+.
4728c8
+.
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.SH AUTHORS
4728c8
+.\" ----------------------------------------------------------------------------
4728c8
+.
4728c8
+\fImultipath-tools\fR was developed by Christophe Varoqui <christophe.varoqui@opensvc.com>
4728c8
+and others.
4728c8
+.\" EOF