Skip to contentSkip to conversation

multipath cleanups

PATCH Superseded Benjamin Marzinski 2 participants 11 messages Jul 27, 2020 – Aug 10, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover multipath cleanups

Patches 0003 & 0004 fix an issue that I've seen with paths whose checker takes too long when multipathd is starting up and creating devices.

The others are minor build fixes or small cleanups to my previous patchset.

Benjamin Marzinski (6):
Makefile.inc: trim extra information from systemd version
kpartx: fix -Wsign-compare error
libmultipath: remove code duplication in path counting
libmultipath: count pending paths as active on loads
libmultipath: deal with flushing no maps
multipath: deal with delegation failures correctly

 Makefile.inc                    |  2 +-
 kpartx/kpartx.c                 |  2 +-
 libmpathpersist/mpath_persist.c |  4 +--
 libmultipath/devmapper.c        |  5 ++--
 libmultipath/structs.c          | 52 ++++++++++++++++-----------------
 libmultipath/structs.h          |  2 +-
 multipath/main.c                |  9 ++++--
 7 files changed, 39 insertions(+), 37 deletions(-)
Signature · 1 line
2.17.2
author maintainer
#1 lore raw

PATCH 1/6 Makefile.inc: trim extra information from systemd version

Some systemd versions print extra information in the "pkg-config --modversion" output, which confuses make. Trim this off.

---
 Makefile.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
index e7256e3a..8ea3352d 100644
@@ -37,7 +37,7 @@ endif
 
 ifndef SYSTEMD
 	ifeq ($(shell pkg-config --modversion libsystemd >/dev/null 2>&1 && echo 1), 1)
-		SYSTEMD = $(shell pkg-config --modversion libsystemd)
+		SYSTEMD = $(shell pkg-config --modversion libsystemd | awk '{print $$1}')
 	else
 		ifeq ($(shell systemctl --version >/dev/null 2>&1 && echo 1), 1)
 			SYSTEMD = $(shell systemctl --version 2> /dev/null | \
Signature · 1 line
2.17.2
author maintainer
#2 lore raw

PATCH 2/6 kpartx: fix -Wsign-compare error

In reply to Benjamin Marzinski
---
 kpartx/kpartx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kpartx/kpartx.c +1 -1
index c24ad6d9..653ce0c8 100644
@@ -738,7 +738,7 @@ struct block {
 /* blknr is always in 512 byte blocks */
 char *
 getblock (int fd, unsigned int blknr) {
-	unsigned int secsz = get_sector_size(fd);
+	int secsz = get_sector_size(fd);
 	unsigned int blks_per_sec = secsz / 512;
 	unsigned int secnr = blknr / blks_per_sec;
 	unsigned int blk_off = (blknr % blks_per_sec) * 512;
Signature · 1 line
2.17.2
#3 lore raw

Re: [PATCH 2/6] kpartx: fix -Wsign-compare error

Quoted 10 lines · Benjamin Marzinski
---
 kpartx/kpartx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kpartx/kpartx.c +0 -0
index c24ad6d9..653ce0c8 100644

kpartx/kpartx.c struct block { · line 744

Quoted 8 lines
kpartx/kpartx.c +1 -1
@@ -738,7 +738,7 @@ struct block {
 /* blknr is always in 512 byte blocks */
 char *
 getblock (int fd, unsigned int blknr) {
-	unsigned int secsz = get_sector_size(fd);
+	int secsz = get_sector_size(fd);
 	unsigned int blks_per_sec = secsz / 512;
 	unsigned int secnr = blknr / blks_per_sec;
 	unsigned int blk_off = (blknr % blks_per_sec) * 512;

I was wondering why I didn't see this one. Turns out that it occurs only for 32bit compilations. It looks like sort of an overzealous compiler warning to me, as it's only about a "!=" comparison that can hardly produce a wrong or unexpected result.

Btw, not that it would matter much, but the value of he BLKSSZGET ioctl is actually unsigned.

Anyway, ack.

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
author maintainer
#4 lore raw

PATCH 3/6 libmultipath: remove code duplication in path counting

In reply to Benjamin Marzinski

pathcountgr() is never used except by pathcount(), and neither is the special case for PATH_WILD. Simplify this and make one function that is used by both pathcount() and count_active_paths(). This will be used again in a future patch.

Also use count_active_paths() in mpath_persist.

---
 libmpathpersist/mpath_persist.c |  4 +--
 libmultipath/structs.c          | 47 +++++++++++++--------------------
 libmultipath/structs.h          |  1 -
 3 files changed, 21 insertions(+), 31 deletions(-)
libmpathpersist/mpath_persist.c +2 -2
index 3da7a6cf..a132f4e9 100644
@@ -436,7 +436,7 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope,
 
 	all_tg_pt = (mpp->all_tg_pt == ALL_TG_PT_ON ||
 		     paramp->sa_flags & MPATH_F_ALL_TG_PT_MASK);
-	active_pathcount = pathcount(mpp, PATH_UP) + pathcount(mpp, PATH_GHOST);
+	active_pathcount = count_active_paths(mpp);
 
 	if (active_pathcount == 0) {
 		condlog (0, "%s: no path available", mpp->wwid);
@@ -648,7 +648,7 @@ int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope,
 	if (!mpp)
 		return MPATH_PR_DMMP_ERROR;
 
-	active_pathcount = pathcount (mpp, PATH_UP) + pathcount (mpp, PATH_GHOST);
+	active_pathcount = count_active_paths(mpp);
 
 	struct threadinfo thread[active_pathcount];
 	memset(thread, 0, sizeof(thread));
libmultipath/structs.c +19 -28

68 lines not on this page · raw message

libmultipath/structs.h +0 -1
index d69bc2e9..0c03e711 100644
@@ -446,7 +446,6 @@ struct path * find_path_by_devt (const struct _vector *pathvec, const char *devt
 struct path * find_path_by_dev (const struct _vector *pathvec, const char *dev);
 struct path * first_path (const struct multipath *mpp);
 
-int pathcountgr (const struct pathgroup *, int);
 int pathcount (const struct multipath *, int);
 int count_active_paths(const struct multipath *);
 int pathcmp (const struct pathgroup *, const struct pathgroup *);
Signature · 1 line
2.17.2
#5 lore raw

Re: [PATCH 3/6] libmultipath: remove code duplication in path counting

Quoted 7 lines · Benjamin Marzinski

pathcountgr() is never used except by pathcount(), and neither is the special case for PATH_WILD. Simplify this and make one function that is
used by both pathcount() and count_active_paths(). This will be used again in a future patch.

Also use count_active_paths() in mpath_persist.

The patch looks correct. I had thought about something like it as well when I first introduced count_active_paths(). But count_active_paths() is used a *lot*, and often in critical situations. I wonder whether it deserves an optimized version. The compiler can surely optimize better with two constant expressions than with the additional for-loop over an array with variable size. That's why back then I decided against implementing it as a special case of a generic function. I actually considered inlining count_active_paths().

It's hard to quantify the effect, and I haven't done any benchmarks. But still, can we perhaps keep the optimized version of count_active_paths() itself?

Martin

author maintainer
#6 lore raw

Re: [PATCH 3/6] libmultipath: remove code duplication in path counting

Quoted 18 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski

pathcountgr() is never used except by pathcount(), and neither is the special case for PATH_WILD. Simplify this and make one function that is
used by both pathcount() and count_active_paths(). This will be used again in a future patch.

Also use count_active_paths() in mpath_persist.

The patch looks correct. I had thought about something like it as well when I first introduced count_active_paths(). But count_active_paths() is used a *lot*, and often in critical situations. I wonder whether it deserves an optimized version. The compiler can surely optimize better with two constant expressions than with the additional for-loop over an array with variable size. That's why back then I decided against implementing it as a special case of a generic function. I actually considered inlining count_active_paths().

Quoted 3 lines

It's hard to quantify the effect, and I haven't done any benchmarks. But still, can we perhaps keep the optimized version of count_active_paths() itself?

Sure.

-Ben

Quoted 3 lines

Martin

author maintainer
#7 lore raw

PATCH 4/6 libmultipath: count pending paths as active on loads

In reply to Benjamin Marzinski

When multipath loads a table, it signals to udev if there are no active paths. Multipath wasn't counting pending paths as active. This meant that if all the paths were pending, udev would treat the device as not ready, and not run kpartx on it. Even if the pending paths later because active and were reinstated, the kernel would not send a new uevent, because from its point of view, they were always up.

The alternative would be to continue to treat them as failed in the udev rules, but then also tell the kernel that they were down, so that it would trigger a uevent when they were reinstated. However, this could lead to newly created multipath devices failing IO, simply because the path checkers hadn't returned yet. Having udev assume that the the device is up, like the kernel does, seems like the safer option.

---
 libmultipath/devmapper.c | 3 ++-
 libmultipath/structs.c   | 7 +++++++
 libmultipath/structs.h   | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
libmultipath/devmapper.c +2 -1
index f597ff8b..126cd728 100644
@@ -417,7 +417,8 @@ static uint16_t build_udev_flags(const struct multipath *mpp, int reload)
 	/* DM_UDEV_DISABLE_LIBRARY_FALLBACK is added in dm_addmap */
 	return	(mpp->skip_kpartx == SKIP_KPARTX_ON ?
 		 MPATH_UDEV_NO_KPARTX_FLAG : 0) |
-		((count_active_paths(mpp) == 0 || mpp->ghost_delay_tick > 0) ?
+		((count_active_pending_paths(mpp) == 0 ||
+		  mpp->ghost_delay_tick > 0) ?
 		 MPATH_UDEV_NO_PATHS_FLAG : 0) |
 		(reload && !mpp->force_udev_reload ?
 		 MPATH_UDEV_RELOAD_FLAG : 0);
libmultipath/structs.c +7 -0
index 3eac3d61..0d1f969d 100644
@@ -491,6 +491,13 @@ int count_active_paths(const struct multipath *mpp)
 	return do_pathcount(mpp, states, 2);
 }
 
+int count_active_pending_paths(const struct multipath *mpp)
+{
+	int states[] = {PATH_UP, PATH_GHOST, PATH_PENDING};
+
+	return do_pathcount(mpp, states, 3);
+}
+
 int pathcmp(const struct pathgroup *pgp, const struct pathgroup *cpgp)
 {
 	int i, j;
libmultipath/structs.h +1 -0
index 0c03e711..917e4083 100644
@@ -448,6 +448,7 @@ struct path * first_path (const struct multipath *mpp);
 
 int pathcount (const struct multipath *, int);
 int count_active_paths(const struct multipath *);
+int count_active_pending_paths(const struct multipath *);
 int pathcmp (const struct pathgroup *, const struct pathgroup *);
 int add_feature (char **, const char *);
 int remove_feature (char **, const char *);
Signature · 1 line
2.17.2
author maintainer
#8 lore raw

PATCH 5/6 libmultipath: deal with flushing no maps

In reply to Benjamin Marzinski

dm_flush_maps() was failing if there were no device-mapper devices at all, instead of returning success, since there is nothing to do.

Fixes "libmultipath: make dm_flush_maps only return 0 on success"
---
 libmultipath/devmapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/devmapper.c +1 -1
index 126cd728..b8199cb5 100644
@@ -1024,10 +1024,10 @@ int dm_flush_maps (int need_suspend, int retries)
 	if (!(names = dm_task_get_names (dmt)))
 		goto out;
 
+	r = 0;
 	if (!names->dev)
 		goto out;
 
-	r = 0;
 	do {
 		if (need_suspend)
 			r |= dm_suspend_and_flush_map(names->name, retries);
Signature · 1 line
2.17.2
author maintainer
#9 lore raw

PATCH 6/6 multipath: deal with delegation failures correctly

In reply to Benjamin Marzinski

delegate_to_multipathd() was returning success, even if the multipathd command failed. Also, if the command was set to fail with NOT_DELEGATED, it shouldn't print any errors, since multipath will try to issue to command itself.

Fixes "multipath: delegate flushing maps to multipathd"
---
 multipath/main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
multipath/main.c +6 -3
index 4c43314e..3da692dc 100644
@@ -861,9 +861,12 @@ int delegate_to_multipathd(enum mpath_cmds cmd,
 		goto out;
 	}
 
-	if (reply != NULL && *reply != '\0' && strcmp(reply, "ok\n"))
-		printf("%s", reply);
-	r = DELEGATE_OK;
+	if (reply != NULL && *reply != '\0') {
+		if (strcmp(reply, "fail\n"))
+			r = DELEGATE_OK;
+		if (r != NOT_DELEGATED && strcmp(reply, "ok\n"))
+			printf("%s", reply);
+	}
 
 out:
 	FREE(reply);
Signature · 1 line
2.17.2
Reviewed-by on the v1 series
#10 lore raw
In reply to Benjamin Marzinski
Quoted 15 lines · Benjamin Marzinski

Patches 0003 & 0004 fix an issue that I've seen with paths whose checker
takes too long when multipathd is starting up and creating devices.

The others are minor build fixes or small cleanups to my previous patchset.

Benjamin Marzinski (6):
Makefile.inc: trim extra information from systemd version
kpartx: fix -Wsign-compare error
libmultipath: remove code duplication in path counting
libmultipath: count pending paths as active on loads
libmultipath: deal with flushing no maps
multipath: deal with delegation failures correctly

Quoted 10 lines
 Makefile.inc                    |  2 +-
 kpartx/kpartx.c                 |  2 +-
 libmpathpersist/mpath_persist.c |  4 +--
 libmultipath/devmapper.c        |  5 ++--
 libmultipath/structs.c          | 52 ++++++++++++++++---------------
--
 libmultipath/structs.h          |  2 +-
 multipath/main.c                |  9 ++++--
 7 files changed, 39 insertions(+), 37 deletions(-)

For the series, except 3/6:

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