Skip to contentSkip to conversation

Multipath Follow-up patches

PATCH In review Benjamin Marzinski 3 participants 9 messages Feb 19, 2020 – Dec 3, 2020 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

v2 cover Multipath Follow-up patches

These patches resolve various minor issues that Martin had with my previous patch set.

Changes in v2:

0001: now uses memcmp() instead of strncmp(), and safe_sprintf()
instead of strlcpy(), as suggested by Martin Wilck.

Benjamin Marzinski (5):
multipath: fix issues found by compiling with gcc 10
libmultipath: turn pp->vpd_data into a pointer
libmultipath: change loading and resetting in directio
libmultipath: change directio get_events() timeout handling
libmultipath: cleanup old issues with directio checker

 kpartx/dasd.c                    |   6 +-
 libmultipath/checkers.c          |  26 ++---
 libmultipath/checkers.h          |   2 +-
 libmultipath/checkers/directio.c |  66 ++----------
 libmultipath/discovery.c         |  17 ++-
 libmultipath/print.c             |  20 ++--
 libmultipath/structs.c           |   3 +
 libmultipath/structs.h           |   2 +-
 multipath/main.c                 |   2 +-
 tests/directio.c                 | 178 ++++++++++++-------------------
 tests/vpd.c                      |   3 +-
 11 files changed, 125 insertions(+), 200 deletions(-)
Signature · 1 line
2.17.2
author maintainer
#1 lore raw

PATCH v2 1/5 multipath: fix issues found by compiling with gcc 10

---
 kpartx/dasd.c        |  6 +++---
 libmultipath/print.c | 16 ++++++++--------
 multipath/main.c     |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)
kpartx/dasd.c +3 -3
index 1486ccaa..14b9d3aa 100644
@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
 		goto out;
 	}
 
-	if ((!info.FBA_layout) && (!strcmp(info.type, "ECKD")))
+	if ((!info.FBA_layout) && (!memcmp(info.type, "ECKD", 4)))
 		memcpy (&vlabel, data, sizeof(vlabel));
 	else {
 		bzero(&vlabel,4);
@@ -216,7 +216,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
 		sp[0].size  = size - sp[0].start;
 		retval = 1;
 	} else if ((strncmp(type, "VOL1", 4) == 0) &&
-		(!info.FBA_layout) && (!strcmp(info.type, "ECKD"))) {
+		(!info.FBA_layout) && (!memcmp(info.type, "ECKD",4))) {
 		/*
 		 * New style VOL1 labeled disk
 		 */
@@ -265,7 +265,7 @@ read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
 			if (vlabel.ldl_version == 0xf2) {
 				fmt_size = sectors512(vlabel.formatted_blocks,
 						      blocksize);
-			} else if (!strcmp(info.type, "ECKD")) {
+			} else if (!memcmp(info.type, "ECKD",4)) {
 				/* formatted w/o large volume support */
 				fmt_size = geo.cylinders * geo.heads
 					* geo.sectors * (blocksize >> 9);
libmultipath/print.c +8 -8
index 1858d8ea..56f86b2f 100644
@@ -29,6 +29,7 @@
 #include "uevent.h"
 #include "debug.h"
 #include "discovery.h"
+#include "util.h"
 
 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
 #define MIN(x,y) (((x) > (y)) ? (y) : (x))
@@ -2032,7 +2033,6 @@ int snprint_devices(struct config *conf, char * buff, int len,
 	struct dirent *blkdev;
 	struct stat statbuf;
 	char devpath[PATH_MAX];
-	char *devptr;
 	int threshold = MAX_LINE_LEN;
 	int fwd = 0;
 	int r;
@@ -2048,15 +2048,14 @@ int snprint_devices(struct config *conf, char * buff, int len,
 	}
 	fwd += snprintf(buff + fwd, len - fwd, "available block devices:\n");
 
-	strcpy(devpath,"/sys/block/");
 	while ((blkdev = readdir(blkdir)) != NULL) {
 		if ((strcmp(blkdev->d_name,".") == 0) ||
 		    (strcmp(blkdev->d_name,"..") == 0))
 			continue;
 
-		devptr = devpath + 11;
-		*devptr = '\0';
-		strncat(devptr, blkdev->d_name, PATH_MAX-12);
+		if (safe_sprintf(devpath, "/sys/block/%s", blkdev->d_name))
+			continue;
+
 		if (stat(devpath, &statbuf) < 0)
 			continue;
 
@@ -2068,11 +2067,12 @@ int snprint_devices(struct config *conf, char * buff, int len,
 			return len;
 		}
 
-		fwd += snprintf(buff + fwd, len - fwd, "    %s", devptr);
-		pp = find_path_by_dev(vecs->pathvec, devptr);
+		fwd += snprintf(buff + fwd, len - fwd, "    %s",
+				blkdev->d_name);
+		pp = find_path_by_dev(vecs->pathvec, blkdev->d_name);
 		if (!pp) {
 			r = filter_devnode(conf->blist_devnode,
-					   conf->elist_devnode, devptr);
+					   conf->elist_devnode, blkdev->d_name);
 			if (r > 0)
 				fwd += snprintf(buff + fwd, len - fwd,
 						" devnode blacklisted, unmonitored");
multipath/main.c +1 -1
index 15007752..cf9d2a28 100644
@@ -1025,7 +1025,7 @@ main (int argc, char *argv[])
 		if (!dev)
 			goto out;
 
-		strncpy(dev, argv[optind], FILE_NAME_SIZE);
+		strlcpy(dev, argv[optind], FILE_NAME_SIZE);
 		if (dev_type != DEV_UEVENT)
 			dev_type = get_dev_type(dev);
 		if (dev_type == DEV_NONE) {
Signature · 1 line
2.17.2
#3 lore raw

Re: [dm-devel] [PATCH v2 1/5] multipath: fix issues found by compiling with gcc 10

In reply to Benjamin Marzinski

Hi Ben,

Quoted 20 lines · Benjamin Marzinski
---
 kpartx/dasd.c        |  6 +++---
 libmultipath/print.c | 16 ++++++++--------
 multipath/main.c     |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)
kpartx/dasd.c +1 -1
index 1486ccaa..14b9d3aa 100644
@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused))
 struct slice all,
 		goto out;
 	}
 
-	if ((!info.FBA_layout) && (!strcmp(info.type, "ECKD")))
+	if ((!info.FBA_layout) && (!memcmp(info.type, "ECKD", 4)))
 		memcpy (&vlabel, data, sizeof(vlabel));
 	else {
Quoted 1 line

bzero(&vlabel,4);

are you using different compiler / warning flags here than we usually do?

I just found that with the standard flags, gcc 10 does *not* complain about the old (badly broken, noting that info.type is declared as char[4]) code. Nor has any other compiler so far, although we're using pretty verbose warning options.

Regards
Martin

Signature · 11 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE  Software Solutions Germany GmbH
HRB 36809, AG Nürnberg GF: Felix
Imendörffer



--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
author maintainer
#4 lore raw

Re: [dm-devel] [PATCH v2 1/5] multipath: fix issues found by compiling with gcc 10

Quoted 19 lines · Martin Wilck

Hi Ben,

Quoted 16 lines · Benjamin Marzinski
---
 kpartx/dasd.c        |  6 +++---
 libmultipath/print.c | 16 ++++++++--------
 multipath/main.c     |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)
kpartx/dasd.c +0 -0
index 1486ccaa..14b9d3aa 100644
@@ -186,7 +186,7 @@ read_dasd_pt(int fd, __attribute__((unused))
 struct slice all,
 		goto out;
 	}
 
Quoted 7 lines
Quoted 5 lines
kpartx/dasd.c +1 -1
-	if ((!info.FBA_layout) && (!strcmp(info.type, "ECKD")))
+	if ((!info.FBA_layout) && (!memcmp(info.type, "ECKD", 4)))
 		memcpy (&vlabel, data, sizeof(vlabel));
 	else {

bzero(&vlabel,4);

are you using different compiler / warning flags here than we usually do?

When building rhel and fedora packages, there are some flags that differ from the upstream set. Unfortunately, when I just tried rebuilding the package with these fixes removed, I didn't hit any compiler errors. Perhaps I just noticed these while working on something else, and they got included in this commit on accident. Sadly I don't remember the details anymore.

-Ben

Quoted 15 lines

I just found that with the standard flags, gcc 10 does *not* complain about the old (badly broken, noting that info.type is declared as char[4]) code. Nor has any other compiler so far, although we're using pretty verbose warning options.

Regards
Martin

Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE  Software Solutions Germany GmbH
HRB 36809, AG Nürnberg GF: Felix
Imendörffer

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

author maintainer
#5 lore raw

PATCH v2 2/5 libmultipath: turn pp->vpd_data into a pointer

In reply to Benjamin Marzinski

Instead of always allocating space in the path structure for vpd_data, only allocte it when necessary.

Also, fix comments on vpd tests

---
 libmultipath/discovery.c | 17 +++++++++++++++--
 libmultipath/print.c     |  4 ++--
 libmultipath/structs.c   |  3 +++
 libmultipath/structs.h   |  2 +-
 tests/vpd.c              |  3 ++-
 5 files changed, 23 insertions(+), 6 deletions(-)
libmultipath/discovery.c +15 -2
index 23a7889c..ee3290cd 100644
@@ -1649,8 +1649,21 @@ scsi_ioctl_pathinfo (struct path * pp, int mask)
 	select_vpd_vendor_id(pp);
 	vpd_id = pp->vpd_vendor_id;
 
-	if (vpd_id != VPD_VP_UNDEF && get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id, pp->vpd_data, sizeof(pp->vpd_data)) < 0)
-		condlog(3, "%s: failed to get extra vpd data", pp->dev);
+	if (vpd_id != VPD_VP_UNDEF) {
+		char vpd_data[VPD_DATA_SIZE] = {0};
+
+		if (get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id,
+		    vpd_data, sizeof(vpd_data)) < 0)
+			condlog(3, "%s: failed to get extra vpd data", pp->dev);
+		else {
+			vpd_data[VPD_DATA_SIZE - 1] = '\0';
+			if (pp->vpd_data)
+				free(pp->vpd_data);
+			pp->vpd_data = strdup(vpd_data);
+			if (!pp->vpd_data)
+				condlog(0, "%s: failed to allocate space for vpd data", pp->dev);
+		}
+	}
 
 	parent = pp->udev;
 	while (parent) {
libmultipath/print.c +2 -2
index 56f86b2f..b944ef32 100644
@@ -371,7 +371,7 @@ snprint_multipath_vpd_data(char * buff, size_t len,
 
 	vector_foreach_slot(mpp->pg, pgp, i)
 		vector_foreach_slot(pgp->paths, pp, j)
-			if (strlen(pp->vpd_data))
+			if (pp->vpd_data)
 				return snprintf(buff, len, "%s", pp->vpd_data);
 	return snprintf(buff, len, "[undef]");
 }
@@ -710,7 +710,7 @@ snprint_path_marginal(char * buff, size_t len, const struct path * pp)
 static int
 snprint_path_vpd_data(char * buff, size_t len, const struct path * pp)
 {
-	if (strlen(pp->vpd_data) > 0)
+	if (pp->vpd_data)
 		return snprintf(buff, len, "%s", pp->vpd_data);
 	return snprintf(buff, len, "[undef]");
 }
libmultipath/structs.c +3 -0
index cc931e4e..2dd378c4 100644
@@ -131,6 +131,9 @@ free_path (struct path * pp)
 		udev_device_unref(pp->udev);
 		pp->udev = NULL;
 	}
+	if (pp->vpd_data)
+		free(pp->vpd_data);
+
 	vector_free(pp->hwe);
 
 	FREE(pp);
libmultipath/structs.h +1 -1
index b7a01220..9bd39eb1 100644
@@ -269,7 +269,7 @@ struct path {
 	char rev[PATH_REV_SIZE];
 	char serial[SERIAL_SIZE];
 	char tgt_node_name[NODE_NAME_SIZE];
-	char vpd_data[VPD_DATA_SIZE];
+	char *vpd_data;
 	unsigned long long size;
 	unsigned int checkint;
 	unsigned int tick;
tests/vpd.c +2 -1
index 0331c487..3cbad811 100644
@@ -520,8 +520,9 @@ static void test_vpd_eui_ ## len ## _ ## wlen ## _ ## sml(void **state)	\
 	n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id,	\
 			 2, 0, len);					\
 	if (sml) {							\
-		/* overwrite the page side to DEFAULT_SGIO_LEN + 1 */	\
+		/* overwrite the page size to DEFAULT_SGIO_LEN + 1 */	\
 		put_unaligned_be16(255, vt->vpdbuf + 2);		\
+		/* this causes get_vpd_sgio to do a second ioctl */	\
 		will_return(__wrap_ioctl, n);				\
 		will_return(__wrap_ioctl, vt->vpdbuf);			\
 	}								\
Signature · 1 line
2.17.2
author maintainer
#6 lore raw

PATCH v2 3/5 libmultipath: change loading and resetting in directio

In reply to Benjamin Marzinski

The directio checker previously made sure to always keep an aio_group around after loading or resetting the checker. There is no need to do this, and removing this code simplifies the checker. With this change, there is no longer a need for a load or unload checker function, only a reset function which is run when the checker is reset or unloaded. Changing this broke a number of tests, so the unit tests have been updated as well.

---
 libmultipath/checkers.c          |  26 ++---
 libmultipath/checkers.h          |   2 +-
 libmultipath/checkers/directio.c |  43 +-------
 tests/directio.c                 | 177 +++++++++++++------------------
 4 files changed, 81 insertions(+), 167 deletions(-)
libmultipath/checkers.c +7 -19
index 5c7d3004..8d2be8a9 100644
@@ -18,9 +18,7 @@ struct checker_class {
 	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 */
-	int (*load)(void);                   /* to allocate global variables */
-	void (*unload)(void);                /* to free global variables */
-	int (*reset)(void);		     /* to reset the global variables */
+	void (*reset)(void);		     /* to reset the global variables */
 	const char **msgtable;
 	short msgtable_size;
 };
@@ -69,8 +67,8 @@ void free_checker_class(struct checker_class *c)
 	}
 	condlog(3, "unloading %s checker", c->name);
 	list_del(&c->node);
-	if (c->unload)
-		c->unload();
+	if (c->reset)
+		c->reset();
 	if (c->handle) {
 		if (dlclose(c->handle) != 0) {
 			condlog(0, "Cannot unload checker %s: %s",
@@ -103,16 +101,14 @@ static struct checker_class *checker_class_lookup(const char *name)
 	return NULL;
 }
 
-int reset_checker_classes(void)
+void reset_checker_classes(void)
 {
-	int ret = 0;
 	struct checker_class *c;
 
 	list_for_each_entry(c, &checkers, node) {
 		if (c->reset)
-			ret = ret? ret : c->reset();
+			c->reset();
 	}
-	return ret;
 }
 
 static struct checker_class *add_checker_class(const char *multipath_dir,
@@ -159,10 +155,8 @@ static struct checker_class *add_checker_class(const char *multipath_dir,
 		goto out;
 
 	c->mp_init = (int (*)(struct checker *)) dlsym(c->handle, "libcheck_mp_init");
-	c->load = (int (*)(void)) dlsym(c->handle, "libcheck_load");
-	c->unload = (void (*)(void)) dlsym(c->handle, "libcheck_unload");
-	c->reset = (int (*)(void)) dlsym(c->handle, "libcheck_reset");
-	/* These 4 functions can be NULL. call dlerror() to clear out any
+	c->reset = (void (*)(void)) dlsym(c->handle, "libcheck_reset");
+	/* These 2 functions can be NULL. call dlerror() to clear out any
 	 * error string */
 	dlerror();
 
@@ -189,12 +183,6 @@ static struct checker_class *add_checker_class(const char *multipath_dir,
 	condlog(3, "checker %s: message table size = %d",
 		c->name, c->msgtable_size);
 
-	if (c->load && c->load() != 0) {
-		condlog(0, "%s: failed to load checker", c->name);
-		c->unload = NULL;
-		goto out;
-	}
-
 done:
 	c->sync = 1;
 	list_add(&c->node, &checkers);
libmultipath/checkers.h +1 -1
index d9930467..b458118d 100644
@@ -150,7 +150,7 @@ void checker_disable (struct checker *);
 int checker_check (struct checker *, int);
 int checker_is_sync(const struct checker *);
 const char *checker_name (const struct checker *);
-int reset_checker_classes(void);
+void reset_checker_classes(void);
 /*
  * This returns a string that's best prepended with "$NAME checker",
  * where $NAME is the return value of checker_name().
libmultipath/checkers/directio.c +2 -41

58 lines not on this page · raw message

tests/directio.c +71 -106

377 lines not on this page · raw message

Signature · 1 line
2.17.2
author maintainer
#7 lore raw

PATCH v2 4/5 libmultipath: change directio get_events() timeout handling

In reply to Benjamin Marzinski

get_events() used a NULL or a zeroed timeout to mean "don't wait". io_getevents() uses a NULL timeout to mean "wait forever" and a zeroed timeout to mean "don't wait". Make get_events() work like io_getevents().

---
 libmultipath/checkers/directio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
libmultipath/checkers/directio.c +5 -5
index 6ad7c885..649961a4 100644
@@ -262,7 +262,7 @@ get_events(struct aio_group *aio_grp, struct timespec *timeout)
 	struct io_event events[128];
 	int i, nr, got_events = 0;
 	struct timespec zero_timeout = {0};
-	struct timespec *timep = (timeout)? timeout : &zero_timeout;
+	struct timespec *timep = timeout;
 
 	do {
 		errno = 0;
@@ -303,7 +303,6 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)
 	int		rc;
 	long		r;
 	struct timespec currtime, endtime;
-	struct timespec *timep = &timeout;
 
 	if (fstat(fd, &sb) == 0) {
 		LOG(4, "called for %x", (unsigned) sb.st_rdev);
@@ -339,18 +338,19 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)
 	endtime.tv_nsec += timeout.tv_nsec;
 	normalize_timespec(&endtime);
 	while(1) {
-		r = get_events(ct->aio_grp, timep);
+		r = get_events(ct->aio_grp, &timeout);
 
 		if (ct->req->state != PATH_PENDING) {
 			ct->running = 0;
 			return ct->req->state;
-		} else if (r == 0 || !timep)
+		} else if (r == 0 ||
+			   (timeout.tv_sec == 0 && timeout.tv_nsec == 0))
 			break;
 
 		get_monotonic_time(&currtime);
 		timespecsub(&endtime, &currtime, &timeout);
 		if (timeout.tv_sec < 0)
-			timep = NULL;
+			timeout.tv_sec = timeout.tv_nsec = 0;
 	}
 	if (ct->running > timeout_secs || sync) {
 		struct io_event event;
Signature · 1 line
2.17.2
author maintainer
#8 lore raw

PATCH v2 5/5 libmultipath: cleanup old issues with directio checker

In reply to Benjamin Marzinski

The directio checker manually aligns its directio buffer, instead of using posix_memalign(). It also defaults the block size for the read to 512, which may be too small for 4k devices, and it only waits for 5 ns for IO completion before giving up and setting the path to pending, which means that in will virtually always set the path to pending on the check when the IO is issued.

---
 libmultipath/checkers/directio.c | 13 ++++---------
 tests/directio.c                 |  1 -
 2 files changed, 4 insertions(+), 10 deletions(-)
libmultipath/checkers/directio.c +4 -9
index 649961a4..503519e2 100644
@@ -38,7 +38,6 @@ struct async_req {
 	struct iocb io;
 	unsigned int blksize;
 	unsigned char *	buf;
-	unsigned char * ptr;
 	struct list_head node;
 	int state; /* PATH_REMOVED means this is an orphan */
 };
@@ -174,7 +173,7 @@ int libcheck_init (struct checker * c)
 
 	if (ioctl(c->fd, BLKBSZGET, &req->blksize) < 0) {
 		c->msgid = MSG_DIRECTIO_BLOCKSIZE;
-		req->blksize = 512;
+		req->blksize = 4096;
 	}
 	if (req->blksize > 4096) {
 		/*
@@ -185,8 +184,7 @@ int libcheck_init (struct checker * c)
 	if (!req->blksize)
 		goto out;
 
-	req->buf = (unsigned char *)malloc(req->blksize + pgsize);
-	if (!req->buf)
+	if (posix_memalign((void **)&req->buf, pgsize, req->blksize) != 0)
 		goto out;
 
 	flags = fcntl(c->fd, F_GETFL);
@@ -199,9 +197,6 @@ int libcheck_init (struct checker * c)
 		ct->reset_flags = 1;
 	}
 
-	req->ptr = (unsigned char *) (((unsigned long)req->buf + pgsize - 1) &
-		  (~(pgsize - 1)));
-
 	/* Successfully initialized, return the context. */
 	ct->req = req;
 	c->context = (void *) ct;
@@ -298,7 +293,7 @@ get_events(struct aio_group *aio_grp, struct timespec *timeout)
 static int
 check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)
 {
-	struct timespec	timeout = { .tv_nsec = 5 };
+	struct timespec	timeout = { .tv_nsec = 1000 };
 	struct stat	sb;
 	int		rc;
 	long		r;
@@ -323,7 +318,7 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs)
 
 		LOG(3, "starting new request");
 		memset(&ct->req->io, 0, sizeof(struct iocb));
-		io_prep_pread(&ct->req->io, fd, ct->req->ptr,
+		io_prep_pread(&ct->req->io, fd, ct->req->buf,
 			      ct->req->blksize, 0);
 		ct->req->state = PATH_PENDING;
 		if (io_submit(ct->aio_grp->ioctx, 1, ios) != 1) {
tests/directio.c +0 -1
index 23fd2da9..3cd7a520 100644
@@ -23,7 +23,6 @@
 #include <stddef.h>
 #include <setjmp.h>
 #include <stdlib.h>
-#define UNIT_TESTING /* enable memory testing in directio.c */
 #include <cmocka.h>
 #include "globals.c"
 #include "../libmultipath/checkers/directio.c"
Signature · 1 line
2.17.2