Skip to contentSkip to conversation

Multipath path resync

PATCH In review Benjamin Marzinski 2 participants 12 messages May 15, 2015 – Jun 3, 2015 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover Multipath path resync

The first patch is just a resend of earlier patches. The rest are a mix of bug fixes and features. "retrigger uevents to try and get the uid through udev" is one that I'm open to a number of changes to, if anyone feels strongly that it should work differently. I'm also not sure if the new location I'm moved the multipath rules to works for everyone. If not, I have no problem with dropping it. Lastly, I like I mentioned in the "Fix issues with user_friendly_names initramfs binding", if anyone has a better way of making multipathd run differently in the initramfs, I'd be happy to consider that instead of my existing patch.

Benjamin Marzinski (10):
libmultipath: Add prioritizer context data
fix memory leaks on realloc failures
multipathd: use /run instead of /var/run retrigger uevents to try and get the uid through udev update multipath rules to deal with partition devices change order of multipath.rules
make kpartx -d remove all partitions
Fix issues with user_friendly_names initramfs bindings Make multipath deactivate devices before iscsi shutdown resize reply buffer for mutipathd help message

 kpartx/kpartx.c                          |  4 +-
 libmultipath/config.c                    |  6 +++
 libmultipath/config.h                    |  3 ++
 libmultipath/configure.c                 |  3 ++
 libmultipath/defaults.h                  |  4 +-
 libmultipath/dict.c                      | 12 +++++
 libmultipath/discovery.c                 | 28 +++++-----
 libmultipath/dmparser.c                  |  6 ++-
 libmultipath/prio.c                      | 34 +++++++++++-
 libmultipath/prio.h                      |  7 +++
 libmultipath/prioritizers/alua.c         | 58 ++++++++++++++++-----
 libmultipath/prioritizers/alua_rtpg.c    | 22 ++++++--
 libmultipath/prioritizers/alua_rtpg.h    |  4 +-
 libmultipath/prioritizers/const.c        |  4 ++
 libmultipath/prioritizers/datacore.c     |  3 ++
 libmultipath/prioritizers/def_func.h     | 11 ++++
 libmultipath/prioritizers/emc.c          |  4 ++
 libmultipath/prioritizers/hds.c          |  4 ++
 libmultipath/prioritizers/hp_sw.c        |  4 ++
 libmultipath/prioritizers/iet.c          |  4 ++
 libmultipath/prioritizers/ontap.c        |  4 ++
 libmultipath/prioritizers/random.c       |  4 ++
 libmultipath/prioritizers/rdac.c         |  4 ++
 libmultipath/prioritizers/weightedpath.c |  3 ++
 libmultipath/propsel.c                   |  4 +-
 libmultipath/structs.h                   |  8 +++
 libmultipath/util.c                      | 30 +++++++++++
 libmultipath/util.h                      |  1 +
 multipath/Makefile                       |  4 +-
 multipath/main.c                         |  9 ++--
 multipath/multipath.rules                | 16 ++++--
 multipathd/cli.c                         | 88 +++++++++++++++++++++++---------
 multipathd/cli.h                         | 16 +++++-
 multipathd/cli_handlers.c                | 58 ++++-----------------
 multipathd/main.c                        | 49 ++++++++++++------
 multipathd/multipathd.init.suse          |  2 +-
 multipathd/multipathd.service            |  1 +
 multipathd/uxlsnr.c                      | 19 ++++++-
 38 files changed, 406 insertions(+), 139 deletions(-)
 create mode 100644 libmultipath/prioritizers/def_func.h
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH 1/10 libmultipath: Add prioritizer context data

Currently, running the alua prioritizer on a path causes 5 ioctls on many devices. get_target_port_group_support() returns whether alua is supported. get_target_port_group() gets the TPG id. This often takes two ioctls because 128 bytes is not a large enough buffer size on many devices. Finally, get_asymmetric_access_state() also often takes two ioctls because of the buffer size. This can get to be problematic when there are thousands of paths. The goal of this patch to to cut this down to one call in the usual case.

In order to do this, I've added a context pointer to the prio structure, similar to what exists for the checker structure, and initprio() and freeprio() functions to the prioritizers. The only one that currently uses these is the alua prioritizer. It caches the type of alua support, the TPG id, and the necessary buffer size. The only thing I'm worried about with this patch is whether the first two values could change. In order to deal with that possibility, whenever a path gets a change event, or becomes valid again after a failure, it resets the context structure values, which forces all of them to get checked the next time the prioritizer is called.

---
 libmultipath/prio.c                      | 34 ++++++++++++++++++-
 libmultipath/prio.h                      |  7 ++++
 libmultipath/prioritizers/alua.c         | 58 +++++++++++++++++++++++++-------
 libmultipath/prioritizers/alua_rtpg.c    | 22 +++++++++---
 libmultipath/prioritizers/alua_rtpg.h    |  4 +--
 libmultipath/prioritizers/const.c        |  4 +++
 libmultipath/prioritizers/datacore.c     |  3 ++
 libmultipath/prioritizers/def_func.h     | 11 ++++++
 libmultipath/prioritizers/emc.c          |  4 +++
 libmultipath/prioritizers/hds.c          |  4 +++
 libmultipath/prioritizers/hp_sw.c        |  4 +++
 libmultipath/prioritizers/iet.c          |  4 +++
 libmultipath/prioritizers/ontap.c        |  4 +++
 libmultipath/prioritizers/random.c       |  4 +++
 libmultipath/prioritizers/rdac.c         |  4 +++
 libmultipath/prioritizers/weightedpath.c |  3 ++
 libmultipath/propsel.c                   |  4 +--
 multipathd/main.c                        | 24 ++++++++-----
 18 files changed, 171 insertions(+), 31 deletions(-)
 create mode 100644 libmultipath/prioritizers/def_func.h
libmultipath/prio.c +33 -1
index ab8eca9..c8fe252 100644
@@ -115,9 +115,24 @@ struct prio * add_prio (char * name)
 	p->getprio = (int (*)(struct path *, char *)) dlsym(p->handle, "getprio");
 	errstr = dlerror();
 	if (errstr != NULL)
-		condlog(0, "A dynamic linking error occurred: (%s)", errstr);
+		condlog(0, "A dynamic linking error occurred with getprio: (%s)", errstr);
 	if (!p->getprio)
 		goto out;
+
+	p->initprio = (int (*)(struct prio *)) dlsym(p->handle, "initprio");
+	errstr = dlerror();
+	if (errstr != NULL)
+		condlog(0, "A dynamic linking error occurred with initprio: (%s)", errstr);
+	if (!p->initprio)
+		goto out;
+
+	p->freeprio = (int (*)(struct prio *)) dlsym(p->handle, "freeprio");
+	errstr = dlerror();
+	if (errstr != NULL)
+		condlog(0, "A dynamic linking error occurred with freeprio: (%s)", errstr);
+	if (!p->freeprio)
+		goto out;
+
 	list_add(&p->node, &prioritizers);
 	return p;
 out:
@@ -125,6 +140,13 @@ out:
 	return NULL;
 }
 
+int prio_init (struct prio * p)
+{
+	if (!p || !p->initprio)
+		return 1;
+	return p->initprio(p);
+}
+
 int prio_getprio (struct prio * p, struct path * pp)
 {
 	return p->getprio(pp, p->args);
@@ -159,8 +181,16 @@ void prio_get (struct prio * dst, char * name, char * args)
 	strncpy(dst->name, src->name, PRIO_NAME_LEN);
 	if (args)
 		strncpy(dst->args, args, PRIO_ARGS_LEN);
+	dst->initprio = src->initprio;
 	dst->getprio = src->getprio;
+	dst->freeprio = src->freeprio;
 	dst->handle = NULL;
+	dst->context = NULL;
+
+	if (dst->initprio(dst) != 0){
+		memset(dst, 0x0, sizeof(struct prio));
+		return;
+	}
 
 	src->refcount++;
 }
@@ -173,6 +203,8 @@ void prio_put (struct prio * dst)
 		return;
 
 	src = prio_lookup(dst->name);
+	if (dst->freeprio)
+		dst->freeprio(dst);
 	memset(dst, 0x0, sizeof(struct prio));
 	free_prio(src);
 }
libmultipath/prio.h +7 -0
index 495688f..6d57ecd 100644
@@ -46,9 +46,15 @@ struct prio {
 	void *handle;
 	int refcount;
 	struct list_head node;
+	void * context;
 	char name[PRIO_NAME_LEN];
 	char args[PRIO_ARGS_LEN];
+	int (*initprio)(struct prio * p);
+	/* You are allowed to call initprio multiple times without calling
+	 * freeprio. Doing so will reinitialize it (possibly skipping
+	 * allocations) */
 	int (*getprio)(struct path *, char *);
+	int (*freeprio)(struct prio * p);
 };
 
 unsigned int get_prio_timeout(unsigned int default_timeout);
@@ -57,6 +63,7 @@ void cleanup_prio (void);
 struct prio * add_prio (char *);
 struct prio * prio_lookup (char *);
 int prio_getprio (struct prio *, struct path *);
+int prio_init (struct prio *);
 void prio_get (struct prio *, char *, char *);
 void prio_put (struct prio *);
 int prio_selected (struct prio *);
libmultipath/prioritizers/alua.c +45 -13

85 lines not on this page · raw message

libmultipath/prioritizers/alua_rtpg.c +18 -4
index 6d04fc1..7ef2ef5 100644
@@ -171,7 +171,7 @@ get_target_port_group_support(int fd)
 }
 
 int
-get_target_port_group(int fd)
+get_target_port_group(int fd, int *buflen_ptr)
 {
 	unsigned char		*buf;
 	struct vpd83_data *	vpd83;
@@ -179,7 +179,12 @@ get_target_port_group(int fd)
 	int			rc;
 	int			buflen, scsi_buflen;
 
-	buflen = 128; /* Lets start from 128 */
+	if (!buflen_ptr || *buflen_ptr == 0) {
+		buflen = 128; /* Lets start from 128 */
+		if (buflen_ptr)
+			*buflen_ptr = 128;
+	} else
+		buflen = *buflen_ptr;
 	buf = (unsigned char *)malloc(buflen);
 	if (!buf) {
 		PRINT_DEBUG("malloc failed: could not allocate"
@@ -202,6 +207,8 @@ get_target_port_group(int fd)
 			return -RTPG_RTPG_FAILED;
 		}
 		buflen = scsi_buflen;
+		if (buflen_ptr)
+			*buflen_ptr = buflen;
 		memset(buf, 0, buflen);
 		rc = do_inquiry(fd, 1, 0x83, buf, buflen);
 		if (rc < 0)
@@ -269,7 +276,7 @@ do_rtpg(int fd, void* resp, long resplen)
 }
 
 int
-get_asymmetric_access_state(int fd, unsigned int tpg)
+get_asymmetric_access_state(int fd, unsigned int tpg, int *buflen_ptr)
 {
 	unsigned char		*buf;
 	struct rtpg_data *	tpgd;
@@ -278,7 +285,12 @@ get_asymmetric_access_state(int fd, unsigned int tpg)
 	int			buflen;
 	uint32_t		scsi_buflen;
 
-	buflen = 128; /* Initial value from old code */
+	if (!buflen_ptr || *buflen_ptr == 0) {
+		buflen = 128; /* Initial value from old code */
+		if (buflen_ptr)
+			*buflen_ptr = 128;
+	} else
+		buflen = *buflen_ptr;
 	buf = (unsigned char *)malloc(buflen);
 	if (!buf) {
 		PRINT_DEBUG ("malloc failed: could not allocate"
@@ -299,6 +311,8 @@ get_asymmetric_access_state(int fd, unsigned int tpg)
 			return -RTPG_RTPG_FAILED;
 		}
 		buflen = scsi_buflen;
+		if (buflen_ptr)
+			*buflen_ptr = buflen;
 		memset(buf, 0, buflen);
 		rc = do_rtpg(fd, buf, buflen);
 		if (rc < 0)
libmultipath/prioritizers/alua_rtpg.h +2 -2
index c43e0a9..cade64d 100644
@@ -23,8 +23,8 @@
 #define RTPG_TPG_NOT_FOUND			4
 
 int get_target_port_group_support(int fd);
-int get_target_port_group(int fd);
-int get_asymmetric_access_state(int fd, unsigned int tpg);
+int get_target_port_group(int fd, int *buflen_ptr);
+int get_asymmetric_access_state(int fd, unsigned int tpg, int *buflen_ptr);
 
 #endif /* __RTPG_H__ */
 
libmultipath/prioritizers/const.c +4 -0
index bf689cd..362d4e1 100644
@@ -1,8 +1,12 @@
 #include <stdio.h>
 
 #include <prio.h>
+#include "def_func.h"
 
 int getprio (struct path * pp, char * args)
 {
 	return 1;
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/datacore.c +3 -0
index e3e6a51..c2f0d0b 100644
@@ -25,6 +25,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define INQ_REPLY_LEN 255
 #define INQ_CMD_CODE 0x12
@@ -111,3 +112,5 @@ int getprio (struct path * pp, char * args)
         return datacore_prio(pp->dev, pp->fd, args);
 }
 
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/def_func.h new file +11 -0
new file mode 100644
index 0000000..8976b3f
@@ -0,0 +1,11 @@
+#ifndef _DEF_FUNC_H
+#define _DEF_FUNC_H
+
+#include "prio.h"
+
+#define declare_nop_prio(name)						\
+int name (struct prio *p)						\
+{									\
+	return 0;							\
+}
+#endif /* _DEF_FUNC_H */
libmultipath/prioritizers/emc.c +4 -0
index e49809c..448528f 100644
@@ -6,6 +6,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define INQUIRY_CMD     0x12
 #define INQUIRY_CMDLEN  6
@@ -85,3 +86,6 @@ int getprio (struct path * pp, char * args)
 {
 	return emc_clariion_prio(pp->dev, pp->fd);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/hds.c +4 -0
index 8043b5b..292fe1c 100644
@@ -76,6 +76,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define INQ_REPLY_LEN 255
 #define INQ_CMD_CODE 0x12
@@ -170,3 +171,6 @@ int getprio (struct path * pp, char * args)
 {
 	return hds_modular_prio(pp->dev, pp->fd);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/hp_sw.c +4 -0
index 4950cf7..371d766 100644
@@ -16,6 +16,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define TUR_CMD_LEN		6
 #define SCSI_CHECK_CONDITION	0x2
@@ -99,3 +100,6 @@ int getprio (struct path * pp, char * args)
 {
 	return hp_sw_prio(pp->dev, pp->fd);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/iet.c +4 -0
index 0bcc48b..a6b73d5 100644
@@ -9,6 +9,7 @@
 #include <debug.h>
 #include <unistd.h>
 #include <structs.h>
+#include "def_func.h"
 
 //
 // This prioritizer suits iSCSI needs, makes it possible to prefer one path.
@@ -141,3 +142,6 @@ int getprio(struct path * pp, char * args)
 {
 	return iet_prio(pp->dev, args);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/ontap.c +4 -0
index 5e82a17..c556e3b 100644
@@ -23,6 +23,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define INQUIRY_CMD	0x12
 #define INQUIRY_CMDLEN	6
@@ -245,3 +246,6 @@ int getprio (struct path * pp, char * args)
 {
 	return ontap_prio(pp->dev, pp->fd);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/random.c +4 -0
index 281a0d1..c38b0f6 100644
@@ -4,6 +4,7 @@
 #include <time.h>
 
 #include <prio.h>
+#include "def_func.h"
 
 int getprio (struct path * pp, char * args)
 {
@@ -13,3 +14,6 @@ int getprio (struct path * pp, char * args)
 	srand((unsigned int)tv.tv_usec);
 	return 1+(int) (10.0*rand()/(RAND_MAX+1.0));
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/rdac.c +4 -0
index a210055..1fc302f 100644
@@ -6,6 +6,7 @@
 #include <debug.h>
 #include <prio.h>
 #include <structs.h>
+#include "def_func.h"
 
 #define INQUIRY_CMD     0x12
 #define INQUIRY_CMDLEN  6
@@ -95,3 +96,6 @@ int getprio (struct path * pp, char * args)
 {
 	return rdac_prio(pp->dev, pp->fd);
 }
+
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/prioritizers/weightedpath.c +3 -0
index 13bc52f..1c3f821 100644
@@ -32,6 +32,7 @@
 #include <memory.h>
 #include <debug.h>
 #include <regex.h>
+#include "def_func.h"
 
 char *get_next_string(char **temp, char *split_char)
 {
@@ -104,3 +105,5 @@ int getprio(struct path *pp, char *args)
 	return prio_path_weight(pp, args);
 }
 
+declare_nop_prio(initprio)
+declare_nop_prio(freeprio)
libmultipath/propsel.c +2 -2
index f64d5e4..347cc66 100644
@@ -376,10 +376,10 @@ detect_prio(struct path * pp)
 
 	if (get_target_port_group_support(pp->fd) <= 0)
 		return;
-	ret = get_target_port_group(pp->fd);
+	ret = get_target_port_group(pp->fd, NULL);
 	if (ret < 0)
 		return;
-	if (get_asymmetric_access_state(pp->fd, ret) < 0)
+	if (get_asymmetric_access_state(pp->fd, ret, NULL) < 0)
 		return;
 	prio_get(p, PRIO_ALUA, DEFAULT_PRIO_ARGS);
 }
multipathd/main.c +15 -9
index f876258..360a584 100644
@@ -721,20 +721,23 @@ static int
 uev_update_path (struct uevent *uev, struct vectors * vecs)
 {
 	int ro, retval = 0;
+	struct path * pp;
+
+	pp = find_path_by_dev(vecs->pathvec, uev->kernel);
+	if (!pp) {
+		condlog(0, "%s: spurious uevent, path not found",
+			uev->kernel);
+		return 1;
+	}
+	/* reinit the prio values on change event, in case something is
+	 * different */
+	prio_init(&pp->prio);
 
 	ro = uevent_get_disk_ro(uev);
 
 	if (ro >= 0) {
-		struct path * pp;
-
 		condlog(2, "%s: update path write_protect to '%d' (uevent)",
 			uev->kernel, ro);
-		pp = find_path_by_dev(vecs->pathvec, uev->kernel);
-		if (!pp) {
-			condlog(0, "%s: spurious uevent, path not found",
-				uev->kernel);
-			return 1;
-		}
 		if (pp->mpp) {
 			retval = reload_map(vecs, pp->mpp, 0);
 
@@ -1272,6 +1275,7 @@ check_path (struct vectors * vecs, struct path * pp)
 		}
 
 		if(newstate == PATH_UP || newstate == PATH_GHOST){
+			prio_init(&pp->prio);
 			if ( pp->mpp && pp->mpp->prflag ){
 				/*
 				 * Check Persistent Reservation.
@@ -1308,7 +1312,9 @@ check_path (struct vectors * vecs, struct path * pp)
 
 		/*
 		 * if at least one path is up in a group, and
-		 * the group is disabled, re-enable it
+		 * the group is disabled, re-enable it.
+		 * Reinitialize the prioritizer, in case something
+		 * changed.
 		 */
 		if (newstate == PATH_UP)
 			enable_group(pp);
Signature · 1 line
1.8.3.1
author maintainer
#2 lore raw

PATCH 2/10 fix memory leaks on realloc failures

In reply to Benjamin Marzinski

When realloc fails, it doesn't free the existing memory. In many places, multipath was just forgetting about that that memory. It needs to free up the existing memory, or to reset back to using it.

---
 libmultipath/dmparser.c   |  6 ++++--
 multipath/main.c          |  9 ++++++---
 multipathd/cli_handlers.c | 50 +++++++++++++----------------------------------
 multipathd/uxlsnr.c       | 19 +++++++++++++++++-
 4 files changed, 42 insertions(+), 42 deletions(-)
libmultipath/dmparser.c +4 -2
index 2562ba1..2209b2d 100644
@@ -20,14 +20,16 @@
 static int
 merge_words (char ** dst, char * word, int space)
 {
-	char * p;
+	char * p = *dst;
 	int len;
 
 	len = strlen(*dst) + strlen(word) + space;
 	*dst = REALLOC(*dst, len + 1);
 
-	if (!*dst)
+	if (!*dst) {
+		free(p);
 		return 1;
+	}
 
 	p = *dst;
 
multipath/main.c +6 -3
index f62dcb1..d761621 100644
@@ -395,7 +395,7 @@ out:
 static int
 dump_config (void)
 {
-	char * c;
+	char * c, * tmp = NULL;
 	char * reply;
 	unsigned int maxlen = 256;
 	int again = 1;
@@ -403,9 +403,12 @@ dump_config (void)
 	reply = MALLOC(maxlen);
 
 	while (again) {
-		if (!reply)
+		if (!reply) {
+			if (tmp)
+				free(tmp);
 			return 1;
-		c = reply;
+		}
+		c = tmp = reply;
 		c += snprint_defaults(c, reply + maxlen - c);
 		again = ((c - reply) == maxlen);
 		if (again) {
multipathd/cli_handlers.c +14 -36

86 lines not on this page · raw message

multipathd/uxlsnr.c +18 -1
index 61ba49a..64bd35c 100644
@@ -65,6 +65,10 @@ static void new_client(int ux_sock)
 		return;
 
 	c = (struct client *)MALLOC(sizeof(*c));
+	if (!c) {
+		close(fd);
+		return;
+	}
 	memset(c, 0, sizeof(*c));
 	INIT_LIST_HEAD(&c->node);
 	c->fd = fd;
@@ -151,6 +155,7 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
 	sigdelset(&mask, SIGHUP);
 	sigdelset(&mask, SIGUSR1);
 	while (1) {
+		struct pollfd *new;
 		struct client *c, *tmp;
 		int i, poll_count, num_clients;
 
@@ -168,7 +173,19 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
 		list_for_each_entry(c, &clients, node) {
 			num_clients++;
 		}
-		polls = REALLOC(polls, (1+num_clients) * sizeof(*polls));
+		new = REALLOC(polls, (1+num_clients) * sizeof(*polls));
+		/* If we can't allocate poliing space for the new client,
+		 * close it */
+		if (!new) {
+			if (!num_clients) {
+				condlog(1, "can't listen for new clients");
+				return NULL;
+			}
+			dead_client(list_entry(clients.prev,
+					       typeof(struct client), node));
+		}
+		else
+			polls = new;		
 		polls[0].fd = ux_sock;
 		polls[0].events = POLLIN;
 
Signature · 1 line
1.8.3.1
author maintainer
#3 lore raw

PATCH 3/10 multipathd: use /run instead of /var/run

In reply to Benjamin Marzinski

/var/run is usually a symlink to /run. If /var is on a separate filesytem, when multipathd starts up, it might end up writing to /var/run before the /var filesytem is mounted and thus not have its pidfile accessible at /var/run afterwards. /run is a tmpfs and should always be available before multipathd is started, so multipath should just write there directly, instead of through the symlink.

---
 libmultipath/defaults.h         | 2 +-
 multipathd/multipathd.init.suse | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libmultipath/defaults.h +1 -1
index 8902f40..79d6b91 100644
@@ -26,7 +26,7 @@
 #define MAX_CHECKINT(a)		(a << 2)
 
 #define MAX_DEV_LOSS_TMO	0x7FFFFFFF
-#define DEFAULT_PIDFILE		"/var/run/multipathd.pid"
+#define DEFAULT_PIDFILE		"/run/multipathd.pid"
 #define DEFAULT_SOCKET		"/org/kernel/linux/storage/multipathd"
 #define DEFAULT_CONFIGFILE	"/etc/multipath.conf"
 #define DEFAULT_BINDINGS_FILE	"/etc/multipath/bindings"
multipathd/multipathd.init.suse +1 -1
index d1319b1..ed699fa 100644
@@ -17,7 +17,7 @@
 
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 DAEMON=/sbin/multipathd
-PIDFILE=/var/run/multipathd.pid
+PIDFILE=/run/multipathd.pid
 MPATH_INIT_TIMEOUT=10
 ARGS=""
 
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH 03/10] multipathd: use /run instead of /var/run

Quoted 7 lines · Benjamin Marzinski

/var/run is usually a symlink to /run. If /var is on a separate filesytem, when multipathd starts up, it might end up writing to /var/run before the /var filesytem is mounted and thus not have its pidfile accessible at /var/run afterwards. /run is a tmpfs and should always be available before multipathd is started, so multipath should just write there directly, instead of through the symlink.

My older openSUSE doesn't have a /run directory. Should this maybe depend on systemd or something else?

Sebastian

author maintainer
#5 lore raw

PATCH 4/10 retrigger uevents to try and get the uid through udev

In reply to Benjamin Marzinski

Ideally, udev will be able to grab the wwid when a path device is discovered, but sometimes this isn't possible. In these cases, the best thing that could happen would be for udev to actually get the information, and add it to its database. This patch makes multipath retrigger uevents a limited number of times before giving up and trying to get the information itself.

There are two configurables that control how it does this, "retrigger_tries" and "retrigger_delay". The first sets the number of times it will try to retrigger a uevent to get the wwid, the second sets the amount of time to wait between retriggers.

This patch currently only tries reinitializing the path on change events after multipathd has triggered a change event, and it only tries once per triggered change event. Now, its possible that other change events could occur on the device without multipathd tirggering them. As the patch stands now, it won't try to initialize the device on those. It will, however still try in the checkerloop, but only after it has finished retriggering the uevents. We could be much more aggressive here, and assume that devices that simply won't have a WWID should already be taken care of by the blacklists, so it would be always a good idea to recheck devices on change events. What would be ideal is if udev would let us know when it had problems or timed out when processing a uevent, so we would know if retiggering the uevent would be useful.

---
 libmultipath/config.c    |  2 ++
 libmultipath/config.h    |  2 ++
 libmultipath/defaults.h  |  2 ++
 libmultipath/dict.c      |  8 ++++++++
 libmultipath/discovery.c | 28 ++++++++++++++++------------
 libmultipath/structs.h   |  8 ++++++++
 multipathd/main.c        | 25 ++++++++++++++++++-------
 7 files changed, 56 insertions(+), 19 deletions(-)
libmultipath/config.c +2 -0
index c788cf6..cfcc685 100644
@@ -619,6 +619,8 @@ load_config (char * file, struct udev *udev)
 	conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
 	conf->uxsock_timeout = DEFAULT_UXSOCK_TIMEOUT;
 	conf->uid_attribute = set_default(DEFAULT_UID_ATTRIBUTE);
+	conf->retrigger_tries = DEFAULT_RETRIGGER_TRIES;
+	conf->retrigger_delay = DEFAULT_RETRIGGER_DELAY;
 
 	/*
 	 * preload default hwtable
libmultipath/config.h +2 -0
index 0183969..372eace 100644
@@ -135,6 +135,8 @@ struct config {
 	int delay_watch_checks;
 	int delay_wait_checks;
 	int uxsock_timeout;
+	int retrigger_tries;
+	int retrigger_delay;
 	unsigned int version[3];
 
 	char * dev;
libmultipath/defaults.h +2 -0
index 79d6b91..025a016 100644
@@ -21,6 +21,8 @@
 #define DEFAULT_DELAY_CHECKS DELAY_CHECKS_OFF
 #define DEFAULT_UEVENT_STACKSIZE 256
 #define DEFAULT_UXSOCK_TIMEOUT  1000
+#define DEFAULT_RETRIGGER_DELAY 10
+#define DEFAULT_RETRIGGER_TRIES 3
 
 #define DEFAULT_CHECKINT	5
 #define MAX_CHECKINT(a)		(a << 2)
libmultipath/dict.c +8 -0
index 5c2da43..e3bc67e 100644
@@ -389,6 +389,12 @@ declare_hw_snprint(deferred_remove, print_yes_no_undef)
 declare_mp_handler(deferred_remove, set_yes_no_undef)
 declare_mp_snprint(deferred_remove, print_yes_no_undef)
 
+declare_def_handler(retrigger_tries, set_int)
+declare_def_snprint(retrigger_tries, print_int)
+
+declare_def_handler(retrigger_delay, set_int)
+declare_def_snprint(retrigger_delay, print_int)
+
 static int
 def_config_dir_handler(vector strvec)
 {
@@ -1365,6 +1371,8 @@ init_keywords(void)
 	install_keyword("delay_wait_checks", &def_delay_wait_checks_handler, &snprint_def_delay_wait_checks);
 	install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
 	install_keyword("uxsock_timeout", &def_uxsock_timeout_handler, &snprint_def_uxsock_timeout);
+	install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
+	install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
 	__deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
libmultipath/discovery.c +16 -12
index 4582a20..bd65354 100644
@@ -1547,7 +1547,7 @@ get_uid (struct path * pp)
 					pp->dev, strerror(-len));
 
 		}
-		if (len <= 0 &&
+		if (len <= 0 && pp->retriggers >= conf->retrigger_tries &&
 		    !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
 			len = get_vpd_uid(pp);
 			origin = "sysfs";
@@ -1651,11 +1651,19 @@ pathinfo (struct path *pp, vector hwtable, int mask)
 		}
 	}
 
-	if ((mask & DI_WWID) && !strlen(pp->wwid))
+	if ((mask & DI_WWID) && !strlen(pp->wwid)) {
 		get_uid(pp);
+		if (!strlen(pp->wwid)) {
+			pp->initialized = INIT_MISSING_UDEV;
+			pp->tick = conf->retrigger_delay;
+			return PATHINFO_OK;
+		}
+		else
+			pp->tick = 1;
+	}
+
 	if (mask & DI_BLACKLIST && mask & DI_WWID) {
-		if (!strlen(pp->wwid) ||
-		    filter_wwid(conf->blist_wwid, conf->elist_wwid,
+		if (filter_wwid(conf->blist_wwid, conf->elist_wwid,
 				pp->wwid, pp->dev) > 0) {
 			return PATHINFO_SKIPPED;
 		}
@@ -1665,17 +1673,13 @@ pathinfo (struct path *pp, vector hwtable, int mask)
 	  * Retrieve path priority, even for PATH_DOWN paths if it has never
 	  * been successfully obtained before.
 	  */
-	if ((mask & DI_PRIO) && path_state == PATH_UP) {
+	if ((mask & DI_PRIO) && path_state == PATH_UP && strlen(pp->wwid)) {
 		if (pp->state != PATH_DOWN || pp->priority == PRIO_UNDEF) {
-			if (!strlen(pp->wwid))
-				get_uid(pp);
-			if (!strlen(pp->wwid))
-				return PATHINFO_SKIPPED;
 			get_prio(pp);
 		}
 	}
 
-	pp->initialized = 1;
+	pp->initialized = INIT_OK;
 	return PATHINFO_OK;
 
 blank:
@@ -1684,7 +1688,7 @@ blank:
 	 */
 	memset(pp->wwid, 0, WWID_SIZE);
 	pp->chkrstate = pp->state = PATH_DOWN;
-	pp->initialized = 0;
+	pp->initialized = INIT_FAILED;
 
-	return 0;
+	return PATHINFO_OK;
 }
libmultipath/structs.h +8 -0
index c1fce04..85a8fdc 100644
@@ -145,6 +145,13 @@ enum delay_checks_states {
 	DELAY_CHECKS_UNDEF = 0,
 };
 
+enum initialized_states {
+	INIT_FAILED,
+	INIT_MISSING_UDEV,
+	INIT_REQUESTED_UDEV,
+	INIT_OK,
+};
+
 struct sg_id {
 	int host_no;
 	int channel;
@@ -201,6 +208,7 @@ struct path {
 	struct multipath * mpp;
 	int fd;
 	int initialized;
+	int retriggers;
 
 	/* configlet pointers */
 	struct hwentry * hwe;
multipathd/main.c +18 -7
index 360a584..ea67324 100644
@@ -457,11 +457,6 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
 		condlog(3, "%s: failed to get path info", uev->kernel);
 		return 1;
 	}
-	if (!strlen(pp->wwid)) {
-		condlog(3, "%s: Failed to get path wwid", uev->kernel);
-		free_path(pp);
-		return 1;
-	}
 	ret = store_path(vecs->pathvec, pp);
 	if (!ret) {
 		pp->checkint = conf->checkint;
@@ -729,6 +724,10 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
 			uev->kernel);
 		return 1;
 	}
+
+	if (pp->initialized == INIT_REQUESTED_UDEV)
+		return uev_add_path(uev, vecs);
+
 	/* reinit the prio values on change event, in case something is
 	 * different */
 	prio_init(&pp->prio);
@@ -1164,12 +1163,24 @@ check_path (struct vectors * vecs, struct path * pp)
 	int add_active;
 	int oldchkrstate = pp->chkrstate;
 
-	if (pp->initialized && !pp->mpp)
+	if ((pp->initialized == INIT_OK ||
+	     pp->initialized == INIT_REQUESTED_UDEV) && !pp->mpp)
 		return 0;
 
 	if (pp->tick && --pp->tick)
 		return 0; /* don't check this path yet */
 
+	if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV &&
+	    pp->retriggers < conf->retrigger_tries) {
+		condlog(2, "%s: triggering change event to reinitialize",
+			pp->dev);
+		pp->initialized = INIT_REQUESTED_UDEV;
+		pp->retriggers++;
+		sysfs_attr_set_value(pp->udev, "uevent", "change",
+				     strlen("change"));
+		return 0;
+	} 
+
 	/*
 	 * provision a next check soonest,
 	 * in case we exit abnormaly from here
@@ -1196,7 +1207,7 @@ check_path (struct vectors * vecs, struct path * pp)
 		return 1;
 	}
 	if (!pp->mpp) {
-		if (!strlen(pp->wwid) &&
+		if (!strlen(pp->wwid) && pp->initialized != INIT_MISSING_UDEV &&
 		    (newstate == PATH_UP || newstate == PATH_GHOST)) {
 			condlog(2, "%s: add missing path", pp->dev);
 			if (pathinfo(pp, conf->hwtable, DI_ALL) == 0) {
Signature · 1 line
1.8.3.1
author maintainer
#6 lore raw

PATCH 5/10 update multipath rules to deal with partition devices

In reply to Benjamin Marzinski

Partition devices should inherit the DM_MULTIPATH_DEVICE_PATH state of their parents, and if they are part of multipath path devices, they shouldn't have their own ID_FS_TYPE

---
 multipath/multipath.rules | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
multipath/multipath.rules +12 -4
index c76e6b8..c8fb7e6 100644
@@ -1,14 +1,22 @@
 # Set DM_MULTIPATH_DEVICE_PATH if the device should be handled by multipath
 SUBSYSTEM!="block", GOTO="end_mpath"
+ACTION!="add|change", GOTO="end_mpath"
+KERNEL!="sd*|dasd*", GOTO="end_mpath"
+
+ENV{DEVTYPE}!="partition", GOTO="test_dev"
+IMPORT{parent}="DM_MULTIPATH_DEVICE_PATH"
+ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{ID_FS_TYPE}="none", \
+	ENV{SYSTEMD_READY}="0"
+GOTO="end_mpath"
+
+LABEL="test_dev"
 
 ENV{MPATH_SBIN_PATH}="/sbin"
 TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
 
-SUBSYSTEM=="block", ACTION=="add|change", KERNEL=="sd*|dasd*", \
-	ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
+ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
 	PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -u %k", \
-	ENV{DM_MULTIPATH_DEVICE_PATH}="1" \
-	ENV{ID_FS_TYPE}="none" \
+	ENV{DM_MULTIPATH_DEVICE_PATH}="1", ENV{ID_FS_TYPE}="none", \
 	ENV{SYSTEMD_READY}="0"
 
 LABEL="end_mpath"
Signature · 1 line
1.8.3.1
author maintainer
#7 lore raw

PATCH 6/10 change order of multipath.rules

In reply to Benjamin Marzinski

At least for RedHat, the rule that calls scsi_id is 60-persistent-storage.rules, so the multipath rule needs to come after this.

---
 multipath/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
multipath/Makefile +2 -2
index 7f18e9a..4b3de81 100644
@@ -23,7 +23,7 @@ install:
 	$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)/
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(udevrulesdir)
 	$(INSTALL_PROGRAM) -m 644 11-dm-mpath.rules $(DESTDIR)$(udevrulesdir)
-	$(INSTALL_PROGRAM) -m 644 $(EXEC).rules $(DESTDIR)$(libudevdir)/rules.d/56-multipath.rules
+	$(INSTALL_PROGRAM) -m 644 $(EXEC).rules $(DESTDIR)$(libudevdir)/rules.d/62-multipath.rules
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(mandir)
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(mandir)
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man5dir)
@@ -32,7 +32,7 @@ install:
 uninstall:
 	rm $(DESTDIR)$(bindir)/$(EXEC)
 	rm $(DESTDIR)$(udevrulesdir)/11-dm-mpath.rules
-	rm $(DESTDIR)$(libudevdir)/rules.d/56-multipath.rules
+	rm $(DESTDIR)$(libudevdir)/rules.d/62-multipath.rules
 	rm $(DESTDIR)$(mandir)/$(EXEC).8.gz
 	rm $(DESTDIR)$(man5dir)/$(EXEC).conf.5.gz
 
Signature · 1 line
1.8.3.1
author maintainer
#8 lore raw

PATCH 7/10 make kpartx -d remove all partitions

In reply to Benjamin Marzinski

Currently kpartx -d only removes the partitions that have entries in the partition table. If you remove a partition from the device, and then run kpartx -d, it will not delete that partition (kpartx -u will). I don't see any value in leaving partition devices for partitions that don't even exist anymore, so this patch makes -d delete all partitions.

---
 kpartx/kpartx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kpartx/kpartx.c +2 -2
index d69f9af..a9d4c98 100644
@@ -426,7 +426,7 @@ main(int argc, char **argv){
 			break;
 
 		case DELETE:
-			for (j = n-1; j >= 0; j--) {
+			for (j = MAXSLICES-1; j >= 0; j--) {
 				if (safe_sprintf(partname, "%s%s%d",
 					     mapname, delim, j+1)) {
 					fprintf(stderr, "partname too small\n");
@@ -434,7 +434,7 @@ main(int argc, char **argv){
 				}
 				strip_slash(partname);
 
-				if (!slices[j].size || !dm_map_present(partname))
+				if (!dm_map_present(partname))
 					continue;
 
 				if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
Signature · 1 line
1.8.3.1
author maintainer
#9 lore raw

PATCH 8/10 Fix issues with user_friendly_names initramfs bindings

In reply to Benjamin Marzinski

Multipath has an issue with user_friendly_names set in the initramfs. If the bindings are in the initramfs bindings file, it will create them, and it may use bindings that are different than the ones in the regular file system. Once multipathd starts up in the regular file system, it will try to register the existing bindings, but that may (and in many cases, is likely to) fail. If it can't reanme it, will pick a new binding. Since when multipathd starts discovering the existing devices, it obviously doesn't know all of the existing devices yet, it may very well pick a binding that's already in use by a device that it hasn't discovered yet. In this case multipath will be unable to rename the device to the new binding. Unfortunately, if it fails the rename, it never resets the alias of the device stored in the mpvec to current alias of the actual dm device. So multipath will have devices in the mpvec where the alias and the wwid don't match the actual dm devices that exist. This can cause all sorts of problems.

This patch does two things to deal with this. First, it makes sure that if the rename fails, the device will reset its alias to the one that it currently has.

Second, it adds a new option to help avoid the problem in the first place. There actually already is a solution to this issue. If multipathd is started with -B, it makes the bindings file read-only. If multipathd is started this way in the initramfs, it will never make new bindings for a device. If the device doesn't already have a binding, it will simply be named with its wwid. The problem with this method is that AFAICT it causes a maintenance problem with dracut. At least on RedHat, dracut is simply copying the regular multipathd.service file into the initramfs. I don't see a way in multipathd.service to only start multipathd with the -B option in the initramfs (If there is a way, I'd be happy to use that). So, the only alternative that lets us use -B is to have a separate multipathd.service file that dracut uses for the initramfs. This seems like more work than it's worth.

Instead, this patch pulls some code from systemd to detect if multipathd is running in the initramfs. If it is, and if new_bindings_in_boot is not set, multipathd will set the bindings file to read-only, just like the -B option does.

---
 libmultipath/config.c    |  4 ++++
 libmultipath/config.h    |  1 +
 libmultipath/configure.c |  3 +++
 libmultipath/dict.c      |  4 ++++
 libmultipath/util.c      | 30 ++++++++++++++++++++++++++++++
 libmultipath/util.h      |  1 +
 6 files changed, 43 insertions(+)
libmultipath/config.c +4 -0
index cfcc685..f0aae53 100644
@@ -621,6 +621,7 @@ load_config (char * file, struct udev *udev)
 	conf->uid_attribute = set_default(DEFAULT_UID_ATTRIBUTE);
 	conf->retrigger_tries = DEFAULT_RETRIGGER_TRIES;
 	conf->retrigger_delay = DEFAULT_RETRIGGER_DELAY;
+	conf->new_bindings_in_boot = 0;
 
 	/*
 	 * preload default hwtable
@@ -735,6 +736,9 @@ load_config (char * file, struct udev *udev)
 	    !conf->wwids_file)
 		goto out;
 
+	 if (conf->new_bindings_in_boot == 0 && in_initrd())
+		conf->bindings_read_only = 1;
+
 	return 0;
 out:
 	free_config(conf);
libmultipath/config.h +1 -0
index 372eace..05f1f6d 100644
@@ -137,6 +137,7 @@ struct config {
 	int uxsock_timeout;
 	int retrigger_tries;
 	int retrigger_delay;
+	int new_bindings_in_boot;
 	unsigned int version[3];
 
 	char * dev;
libmultipath/configure.c +3 -0
index 24ad948..3559c01 100644
@@ -421,6 +421,9 @@ select_action (struct multipath * mpp, vector curmp, int force_reload)
 		condlog(2, "%s: unable to rename %s to %s (%s is used by %s)",
 			mpp->wwid, cmpp->alias, mpp->alias,
 			mpp->alias, cmpp_by_name->wwid);
+		/* reset alias to existing alias */
+		FREE(mpp->alias);
+		mpp->alias = STRDUP(cmpp->alias);
 		mpp->action = ACT_NOTHING;
 		return;
 	}
libmultipath/dict.c +4 -0
index e3bc67e..1952b1e 100644
@@ -395,6 +395,9 @@ declare_def_snprint(retrigger_tries, print_int)
 declare_def_handler(retrigger_delay, set_int)
 declare_def_snprint(retrigger_delay, print_int)
 
+declare_def_handler(new_bindings_in_boot, set_yes_no)
+declare_def_snprint(new_bindings_in_boot, print_yes_no)
+
 static int
 def_config_dir_handler(vector strvec)
 {
@@ -1373,6 +1376,7 @@ init_keywords(void)
 	install_keyword("uxsock_timeout", &def_uxsock_timeout_handler, &snprint_def_uxsock_timeout);
 	install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
 	install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
+	install_keyword("new_bindings_in_boot", &def_new_bindings_in_boot_handler, &snprint_def_new_bindings_in_boot);
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
 	__deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
libmultipath/util.c +30 -0
index ac0d1b2..fcab5fc 100644
@@ -3,6 +3,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
 
 #include "debug.h"
 #include "memory.h"
@@ -258,3 +260,31 @@ dev_t parse_devt(const char *dev_t)
 
 	return makedev(maj, min);
 }
+
+/* This define was taken from systemd. src/shared/macro.h */
+#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)
+
+/* This function was taken from systemd. src/shared/util.c */
+int in_initrd(void) {
+	static int saved = -1;
+	struct statfs s;
+
+	if (saved >= 0)
+		return saved;
+
+	/* We make two checks here:
+	 *
+	 * 1. the flag file /etc/initrd-release must exist
+	 * 2. the root file system must be a memory file system
+	 * The second check is extra paranoia, since misdetecting an
+	 * initrd can have bad bad consequences due the initrd
+	 * emptying when transititioning to the main systemd.
+	 */
+
+	saved = access("/etc/initrd-release", F_OK) >= 0 &&
+		statfs("/", &s) >= 0 &&
+		(F_TYPE_EQUAL(s.f_type, TMPFS_MAGIC) ||
+		 F_TYPE_EQUAL(s.f_type, RAMFS_MAGIC));
+
+	return saved;
+}
libmultipath/util.h +1 -0
index 257912c..a1404f2 100644
@@ -10,6 +10,7 @@ size_t strlcat(char *dst, const char *src, size_t size);
 int devt2devname (char *, int, char *);
 dev_t parse_devt(const char *dev_t);
 char *convert_dev(char *dev, int is_path_device);
+int in_initrd(void);
 
 #define safe_sprintf(var, format, args...)	\
 	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
Signature · 1 line
1.8.3.1
author maintainer
#10 lore raw

PATCH 9/10 Make multipath deactivate devices before iscsi shutdown

In reply to Benjamin Marzinski

The multipath devices need to be deactivated before iscsi is shutdown, otherwise the multipath devices will generate a lot of error messages when it loses its iscsi path devices.

---
 multipathd/multipathd.service | 1 +
 1 file changed, 1 insertion(+)
multipathd/multipathd.service +1 -0
index b5b755b..fc2e009 100644
@@ -1,5 +1,6 @@
 [Unit]
 Description=Device-Mapper Multipath Device Controller
+Requires=blk-availability.service
 Before=iscsi.service iscsid.service lvm2-activation-early.service
 Before=local-fs-pre.target
 After=multipathd.socket
Signature · 1 line
1.8.3.1
author maintainer
#11 lore raw

PATCH 10/10 resize reply buffer for mutipathd help message

In reply to Benjamin Marzinski

Unlike the other reply messages from multipathd, the generic help message code couldn't resize the buffer, and the reply had grown too big for the initial buffer size. This was causing memory corruption and crashing multipathd instead of printing a help message. This patch increases the size of the initial reply buffer, and makes the help message code able to resize the buffer so this doesn't happen in the future.

---
 multipathd/cli.c          | 88 +++++++++++++++++++++++++++++++++--------------
 multipathd/cli.h          | 16 ++++++++-
 multipathd/cli_handlers.c | 14 --------
 3 files changed, 78 insertions(+), 40 deletions(-)
multipathd/cli.c +63 -25
index acc4249..8d26956 100644
@@ -320,52 +320,90 @@ alloc_handlers (void)
 }
 
 static int
-genhelp_sprint_aliases (char * reply, vector keys, struct key * refkw)
+genhelp_sprint_aliases (char * reply, int maxlen, vector keys,
+			struct key * refkw)
 {
-	int i, fwd = 0;
+	int i, len = 0;
 	struct key * kw;
 
-	vector_foreach_slot (keys, kw, i)
-		if (kw->code == refkw->code && kw != refkw)
-			fwd += sprintf(reply, "|%s", kw->str);
+	vector_foreach_slot (keys, kw, i) {
+		if (kw->code == refkw->code && kw != refkw) {
+			len += snprintf(reply + len, maxlen - len,
+					"|%s", kw->str);
+			if (len >= maxlen)
+				return len;
+		}
+	}
 
-	return fwd;
+	return len;
 }
 
-static char *
-genhelp_handler (void)
-{
+static int
+do_genhelp(char *reply, int maxlen) {
+	int len = 0;
 	int i, j;
 	unsigned long fp;
 	struct handler * h;
 	struct key * kw;
-	char * reply;
-	char * p;
-
-	reply = MALLOC(INITIAL_REPLY_LEN);
 
-	if (!reply)
-		return NULL;
-
-	p = reply;
-	p += sprintf(p, VERSION_STRING);
-	p += sprintf(p, "CLI commands reference:\n");
+	len += snprintf(reply + len, maxlen - len, VERSION_STRING);
+	if (len >= maxlen)
+		goto out;
+	len += snprintf(reply + len, maxlen - len, "CLI commands reference:\n");
+	if (len >= maxlen)
+		goto out;
 
 	vector_foreach_slot (handlers, h, i) {
 		fp = h->fingerprint;
 		vector_foreach_slot (keys, kw, j) {
 			if ((kw->code & fp)) {
 				fp -= kw->code;
-				p += sprintf(p, " %s", kw->str);
-				p += genhelp_sprint_aliases(p, keys, kw);
-
-				if (kw->has_param)
-					p += sprintf(p, " $%s", kw->str);
+				len += snprintf(reply + len , maxlen - len,
+						" %s", kw->str);
+				if (len >= maxlen)
+					goto out;
+				len += genhelp_sprint_aliases(reply + len,
+							      maxlen - len,
+							      keys, kw);
+				if (len >= maxlen)
+					goto out;
+
+				if (kw->has_param) {
+					len += snprintf(reply + len,
+							maxlen - len,
+							" $%s", kw->str);
+					if (len >= maxlen)
+						goto out;
+				}
 			}
 		}
-		p += sprintf(p, "\n");
+		len += snprintf(reply + len, maxlen - len, "\n");
+		if (len >= maxlen)
+			goto out;
 	}
+out:
+	return len;
+}
+
 
+static char *
+genhelp_handler (void)
+{
+	char * reply;
+	char * p = NULL;
+	int maxlen = INITIAL_REPLY_LEN;
+	int again = 1;
+
+	reply = MALLOC(maxlen);
+
+	while (again) {
+		if (!reply)
+			return NULL;
+		p = reply;
+		p += do_genhelp(reply, maxlen);
+		again = ((p - reply) >= maxlen);
+		REALLOC_REPLY(reply, again, maxlen);
+	}
 	return reply;
 }
 
multipathd/cli.h +15 -1
index 09fdc68..2e0e1da 100644
@@ -71,7 +71,21 @@ enum {
 #define SETPRSTATUS	(1UL << __SETPRSTATUS)
 #define UNSETPRSTATUS	(1UL << __UNSETPRSTATUS)
 
-#define INITIAL_REPLY_LEN	1100
+#define INITIAL_REPLY_LEN	1200
+
+#define REALLOC_REPLY(r, a, m)					\
+	do {							\
+		if ((a)) {					\
+			char *tmp = (r);			\
+			(r) = REALLOC((r), (m) * 2);		\
+			if ((r)) {				\
+				memset((r) + (m), 0, (m));	\
+				(m) *= 2;			\
+			}					\
+			else					\
+				free(tmp);			\
+		}						\
+	} while (0)
 
 struct key {
 	char * str;
multipathd/cli_handlers.c +0 -14
index 305cd7f..8cde810 100644
@@ -23,20 +23,6 @@
 #include "cli.h"
 #include "uevent.h"
 
-#define REALLOC_REPLY(r, a, m)					\
-	do {							\
-		if ((a)) {					\
-			char *tmp = (r);			\
-			(r) = REALLOC((r), (m) * 2);		\
-			if ((r)) {				\
-				memset((r) + (m), 0, (m));	\
-				(m) *= 2;			\
-			}					\
-			else					\
-				free(tmp);			\
-		}						\
-	} while (0)
-
 int
 show_paths (char ** r, int * len, struct vectors * vecs, char * style)
 {
Signature · 1 line
1.8.3.1