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

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