Skip to contentSkip to conversation

misc multipath patches

PATCH In review Benjamin Marzinski 2 participants 6 messages Sep 13, 2019 Device mapper

v2 of 4 In review Latest is v4 →

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

v2 cover misc multipath patches

These are a couple of disconnected multipath patches.

Changes in v2:

0003: As Martin suggested, fail immediately on wrong number of prin
actions.

0004: mp_init now is an optional symbol for checker DSOs, and is ignored
if it's missing, again at Martin's suggestion.

Benjamin Marzinski (4):
mpathpersist: remove broken/unused code
libmultipath: EMC PowerMax NVMe device config
mpathpersist: fix leaks
libmultipath: fix mpcontext initialization

 libmpathpersist/mpath_persist.c      | 16 ++++----------
 libmultipath/checkers.c              | 27 +++++++++++++++++++++--
 libmultipath/checkers.h              |  1 +
 libmultipath/checkers/emc_clariion.c |  7 ++++++
 libmultipath/discovery.c             |  2 ++
 libmultipath/hwtable.c               |  6 +++++
 mpathpersist/main.c                  | 33 ++++++++++++++++++----------
 7 files changed, 67 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.2
author maintainer
#1 lore raw

PATCH v2 1/4 mpathpersist: remove broken/unused code

The test for an empty pp->dev in updatepaths() dates back to when disassemble_map() didn't fill in pp->dev for newly added paths, and it was meant to catch paths that got added by disassemble_map(). With the mpathpersist speedup code, all paths get added by disassemble_map(). However, disassemble_map() now calls devt2devname() to set pp->dev if possible. This means that there is no point in calling devt2devname() again in updatepaths(). If for some reason it did return success, the current code would still fail, since it doesn't set pp->udev in this code path. The best thing to do if disassemble_map() couldn't set pp->dev is simply to fail the path.

---
 libmpathpersist/mpath_persist.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
libmpathpersist/mpath_persist.c +4 -12
index 53022f5b..603cfc3b 100644
@@ -82,18 +82,10 @@ updatepaths (struct multipath * mpp)
 
 		vector_foreach_slot (pgp->paths, pp, j){
 			if (!strlen(pp->dev)){
-				if (devt2devname(pp->dev, FILE_NAME_SIZE,
-						 pp->dev_t)){
-					/*
-					 * path is not in sysfs anymore
-					 */
-					pp->state = PATH_DOWN;
-					continue;
-				}
-				pp->mpp = mpp;
-				conf = get_multipath_config();
-				pathinfo(pp, conf, DI_ALL);
-				put_multipath_config(conf);
+				/*
+				 * path is not in sysfs anymore
+				 */
+				pp->state = PATH_DOWN;
 				continue;
 			}
 			pp->mpp = mpp;
Signature · 1 line
2.17.2
author maintainer
#2 lore raw

PATCH v2 2/4 libmultipath: EMC PowerMax NVMe device config

In reply to Benjamin Marzinski

Got this config from Dell.

---
 libmultipath/hwtable.c | 6 ++++++
 1 file changed, 6 insertions(+)
libmultipath/hwtable.c +6 -0
index 96e8b25d..ca217e65 100644
@@ -360,6 +360,12 @@ static struct hwentry default_hw[] = {
 		.pgfailback    = -FAILBACK_IMMEDIATE,
 		.no_path_retry = 30,
 	},
+	{
+		/* EMC PowerMax NVMe */
+		.vendor        = "NVME",
+		.product       = "^EMC PowerMax_",
+		.pgpolicy      = MULTIBUS,
+	},
 	/*
 	 * Fujitsu
 	 */
Signature · 1 line
2.17.2
author maintainer
#3 lore raw

PATCH v2 3/4 mpathpersist: fix leaks

In reply to Benjamin Marzinski

If handle_args() fails while looping through the argument list, it needs to free batch_fn, if it has been set. Also handle_args() needs to make sure to free the file descriptor after it has been opened.

---
 mpathpersist/main.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
mpathpersist/main.c +22 -11
index 5ad06a97..de000b0b 100644
@@ -155,7 +155,8 @@ static int do_batch_file(const char *batch_fn)
 
 static int handle_args(int argc, char * argv[], int nline)
 {
-	int fd, c;
+	int c;
+	int fd = -1;
 	const char *device_name = NULL;
 	int num_prin_sa = 0;
 	int num_prout_sa = 0;
@@ -213,7 +214,8 @@ static int handle_args(int argc, char * argv[], int nline)
 				if (nline == 0 && 1 != sscanf (optarg, "%d", &loglevel))
 				{
 					fprintf (stderr, "bad argument to '--verbose'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 				break;
 
@@ -228,6 +230,7 @@ static int handle_args(int argc, char * argv[], int nline)
 
 			case 'h':
 				usage ();
+				free(batch_fn);
 				return 0;
 
 			case 'H':
@@ -254,7 +257,8 @@ static int handle_args(int argc, char * argv[], int nline)
 				if (1 != sscanf (optarg, "%" SCNx64 "", &param_rk))
 				{
 					fprintf (stderr, "bad argument to '--param-rk'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 				++num_prout_param;
 				break;
@@ -263,7 +267,8 @@ static int handle_args(int argc, char * argv[], int nline)
 				if (1 != sscanf (optarg, "%" SCNx64 "", &param_sark))
 				{
 					fprintf (stderr, "bad argument to '--param-sark'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 				++num_prout_param;
 				break;
@@ -282,7 +287,8 @@ static int handle_args(int argc, char * argv[], int nline)
 				if (1 != sscanf (optarg, "%x", &prout_type))
 				{
 					fprintf (stderr, "bad argument to '--prout-type'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 				++num_prout_param;
 				break;
@@ -330,7 +336,8 @@ static int handle_args(int argc, char * argv[], int nline)
 			case 'X':
 				if (0 != construct_transportid(optarg, transportids, num_transport)) {
 					fprintf(stderr, "bad argument to '--transport-id'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 
 				++num_transport;
@@ -339,11 +346,13 @@ static int handle_args(int argc, char * argv[], int nline)
 			case 'l':
 				if (1 != sscanf(optarg, "%u", &mpath_mx_alloc_len)) {
 					fprintf(stderr, "bad argument to '--alloc-length'\n");
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				} else if (MPATH_MAX_PARAM_LEN < mpath_mx_alloc_len) {
 					fprintf(stderr, "'--alloc-length' argument exceeds maximum"
 							" limit(%d)\n", MPATH_MAX_PARAM_LEN);
-					return MPATH_PR_SYNTAX_ERROR;
+					ret = MPATH_PR_SYNTAX_ERROR;
+					goto out;
 				}
 				break;
 
@@ -420,12 +429,14 @@ static int handle_args(int argc, char * argv[], int nline)
 			fprintf (stderr,
 					" No service action given for Persistent Reserve IN\n");
 			ret = MPATH_PR_SYNTAX_ERROR;
+			goto out;
 		}
 		else if (num_prin_sa > 1)
 		{
 			fprintf (stderr, " Too many service actions given; choose "
 					"one only\n");
 			ret = MPATH_PR_SYNTAX_ERROR;
+			goto out;
 		}
 	}
 	else
@@ -481,14 +492,14 @@ static int handle_args(int argc, char * argv[], int nline)
 		{
 			fprintf (stderr, "failed to allocate PRIN response buffer\n");
 			ret = MPATH_PR_OTHER;
-			goto out;
+			goto out_fd;
 		}
 
 		ret = __mpath_persistent_reserve_in (fd, prin_sa, resp, noisy);
 		if (ret != MPATH_PR_SUCCESS )
 		{
 			fprintf (stderr, "Persistent Reserve IN command failed\n");
-			goto out;
+			goto out_fd;
 		}
 
 		switch(prin_sa)
@@ -568,8 +579,8 @@ static int handle_args(int argc, char * argv[], int nline)
 		printf("PR out: command failed\n");
 	}
 
+out_fd:
 	close (fd);
-
 out :
 	if (ret == MPATH_PR_SYNTAX_ERROR) {
 		free(batch_fn);
Signature · 1 line
2.17.2
author maintainer
#4 lore raw

PATCH v2 4/4 libmultipath: fix mpcontext initialization

In reply to Benjamin Marzinski

If a path is discovered before there is a multipath device for it to belong to, the checker will not have its mpcontext initialized, even if that path later belongs to a multipath device. A checker's mpcontext is only set when the checker is selected, and is set to NULL if there is no multipath device associated with the path. This only impacts the emc checker. However, it makes the emc checker unable to determine if a passive path is connected to an inactive snapshot or not.

This can be solved by adding a new checker class function, mp_init(). This is called when the checker is first initialized, and whenever the checker is called, if the checker's mpcontext hasn't been initialized.

---
 libmultipath/checkers.c              | 27 +++++++++++++++++++++++++--
 libmultipath/checkers.h              |  1 +
 libmultipath/checkers/emc_clariion.c |  7 +++++++
 libmultipath/discovery.c             |  2 ++
 4 files changed, 35 insertions(+), 2 deletions(-)
libmultipath/checkers.c +25 -2
index f4fdcae9..a08bf418 100644
@@ -16,6 +16,7 @@ struct checker_class {
 	char name[CHECKER_NAME_LEN];
 	int (*check)(struct checker *);
 	int (*init)(struct checker *);       /* to allocate the context */
+	int (*mp_init)(struct checker *);    /* to allocate the mpcontext */
 	void (*free)(struct checker *);      /* to free the context */
 	const char **msgtable;
 	short msgtable_size;
@@ -140,6 +141,10 @@ static struct checker_class *add_checker_class(const char *multipath_dir,
 	if (!c->init)
 		goto out;
 
+	c->mp_init = (int (*)(struct checker *)) dlsym(c->handle, "libcheck_mp_init");
+	/* NULL mp_init is o.k. call dlerror() to clear out any error string */
+	dlerror();
+
 	c->free = (void (*)(struct checker *)) dlsym(c->handle, "libcheck_free");
 	errstr = dlerror();
 	if (errstr != NULL)
@@ -212,8 +217,26 @@ int checker_init (struct checker * c, void ** mpctxt_addr)
 	if (!c || !c->cls)
 		return 1;
 	c->mpcontext = mpctxt_addr;
-	if (c->cls->init)
-		return c->cls->init(c);
+	if (c->cls->init && c->cls->init(c) != 0)
+		return 1;
+	if (mpctxt_addr && *mpctxt_addr == NULL && c->cls->mp_init &&
+	    c->cls->mp_init(c) != 0) /* continue even if mp_init fails */
+		c->mpcontext = NULL;
+	return 0;
+}
+
+int checker_mp_init(struct checker * c, void ** mpctxt_addr)
+{
+	if (!c || !c->cls)
+		return 1;
+	if (c->mpcontext || !mpctxt_addr)
+		return 0;
+	c->mpcontext = mpctxt_addr;
+	if (*mpctxt_addr == NULL && c->cls->mp_init &&
+	    c->cls->mp_init(c) != 0) {
+		c->mpcontext = NULL;
+		return 1;
+	}
 	return 0;
 }
 
libmultipath/checkers.h +1 -0
index dab197f9..5237e7ec 100644
@@ -138,6 +138,7 @@ const char *checker_state_name(int);
 int init_checkers(const char *);
 void cleanup_checkers (void);
 int checker_init (struct checker *, void **);
+int checker_mp_init(struct checker *, void **);
 void checker_clear (struct checker *);
 void checker_put (struct checker *);
 void checker_reset (struct checker *);
libmultipath/checkers/emc_clariion.c +7 -0
index 6fc89113..5cd63aca 100644
@@ -107,11 +107,18 @@ int libcheck_init (struct checker * c)
 		return 1;
 	((struct emc_clariion_checker_path_context *)c->context)->wwn_set = 0;
 
+	return 0;
+}
+
+int libcheck_mp_init (struct checker * c)
+{
 	/*
 	 * Allocate and initialize the multi-path global context.
 	 */
 	if (c->mpcontext && *c->mpcontext == NULL) {
 		void * mpctxt = malloc(sizeof(int));
+		if (!mpctxt)
+			return 1;
 		*c->mpcontext = mpctxt;
 		CLR_INACTIVE_SNAP(c);
 	}
libmultipath/discovery.c +2 -0
index acca466c..72f455e8 100644
@@ -1608,6 +1608,8 @@ get_state (struct path * pp, struct config *conf, int daemon, int oldstate)
 			return PATH_UNCHECKED;
 		}
 	}
+	if (pp->mpp && !c->mpcontext)
+		checker_mp_init(c, &pp->mpp->mpcontext);
 	checker_clear_message(c);
 	if (daemon) {
 		if (conf->force_sync == 0)
Signature · 1 line
2.17.2
Reviewed-by on the v2 series
#5 lore raw
In reply to Benjamin Marzinski
Quoted 17 lines · Benjamin Marzinski

These are a couple of disconnected multipath patches.

Changes in v2:

0003: As Martin suggested, fail immediately on wrong number of prin
actions.

0004: mp_init now is an optional symbol for checker DSOs, and is ignored
if it's missing, again at Martin's suggestion.

Benjamin Marzinski (4):
mpathpersist: remove broken/unused code
libmultipath: EMC PowerMax NVMe device config
mpathpersist: fix leaks
libmultipath: fix mpcontext initialization

Quoted 10 lines
 libmpathpersist/mpath_persist.c      | 16 ++++----------
 libmultipath/checkers.c              | 27 +++++++++++++++++++++--
 libmultipath/checkers.h              |  1 +
 libmultipath/checkers/emc_clariion.c |  7 ++++++
 libmultipath/discovery.c             |  2 ++
 libmultipath/hwtable.c               |  6 +++++
 mpathpersist/main.c                  | 33 ++++++++++++++++++------
----
 7 files changed, 67 insertions(+), 25 deletions(-)

For this v2 series: