Skip to contentSkip to conversation

Fix false removes

PATCH In review Benjamin Marzinski 2 participants 3 messages Nov 29, 2018 – Dec 3, 2018 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

v2 cover Fix false removes

This is a resend of my previous patch 2/2, incorporating both of Martin's suggestions.

Benjamin Marzinski (1):
libmultipath: fix false removes in dmevents polling code

 libmpathpersist/mpath_persist.c |  4 ++--
 libmultipath/devmapper.c        | 41 +++++++++++++++++++++++++++++------------
 multipath/main.c                |  2 +-
 multipathd/dmevents.c           |  8 ++++++--
 multipathd/main.c               |  2 +-
 5 files changed, 39 insertions(+), 18 deletions(-)
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v2 1/1 libmultipath: fix false removes in dmevents polling code

dm_is_mpath() would return 0 if either a device was not a multipath device or if the libdevmapper command failed. Because dm_is_mpath() didn't distinguish between these situations, dm_get_events() could assume that a device was not really a multipath device, when in fact it was, and the libdevmapper command simply failed. This would cause the dmevents polling waiter to stop monitoring the device.

In reality, the call to dm_is_mpath() isn't necessary, because dm_get_events() will already verify that the device name is on the list of devices to wait for. However, if there are a large number of non-multipath devices on the system, ignoring them can be useful. Thus, if dm_is_mpath() successfully runs the libdevmapper command and verifies that the device is not a multipath device, dm_get_events() should skip it. But if the libdevmapper command fails, dm_get_events() should still check the device list, to see if the device should be monitored.

This commit makes dm_is_mpath() return -1 for situations where the libdevmapper command failed, and makes dm_get_events() only ignore the device on a return of 0.

---
 libmpathpersist/mpath_persist.c |  4 ++--
 libmultipath/devmapper.c        | 41 +++++++++++++++++++++++++++++------------
 multipath/main.c                |  2 +-
 multipathd/dmevents.c           |  8 ++++++--
 multipathd/main.c               |  2 +-
 5 files changed, 39 insertions(+), 18 deletions(-)
libmpathpersist/mpath_persist.c +2 -2
index 2ffe56e..7e8a676 100644
@@ -188,7 +188,7 @@ int mpath_persistent_reserve_in (int fd, int rq_servact,
 
 	condlog(3, "alias = %s", alias);
 	map_present = dm_map_present(alias);
-	if (map_present && !dm_is_mpath(alias)){
+	if (map_present && dm_is_mpath(alias) != 1){
 		condlog( 0, "%s: not a multipath device.", alias);
 		ret = MPATH_PR_DMMP_ERROR;
 		goto out;
@@ -283,7 +283,7 @@ int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
 	condlog(3, "alias = %s", alias);
 	map_present = dm_map_present(alias);
 
-	if (map_present && !dm_is_mpath(alias)){
+	if (map_present && dm_is_mpath(alias) != 1){
 		condlog(3, "%s: not a multipath device.", alias);
 		ret = MPATH_PR_DMMP_ERROR;
 		goto out;
libmultipath/devmapper.c +29 -12

85 lines not on this page · raw message

multipath/main.c +1 -1
index 05b7bf0..98fee1c 100644
@@ -319,7 +319,7 @@ static int check_usable_paths(struct config *conf,
 		goto out;
 	}
 
-	if (!dm_is_mpath(mapname)) {
+	if (dm_is_mpath(mapname) != 1) {
 		condlog(1, "%s is not a multipath map", devpath);
 		goto free;
 	}
multipathd/dmevents.c +6 -2
index 31e64a7..0034892 100644
@@ -168,7 +168,9 @@ static int dm_get_events(void)
 	while (names->dev) {
 		uint32_t event_nr;
 
-		if (!dm_is_mpath(names->name))
+		/* Don't delete device if dm_is_mpath() fails without
+		 * checking the device type */
+		if (dm_is_mpath(names->name) == 0)
 			goto next;
 
 		event_nr = dm_event_nr(names);
@@ -204,7 +206,9 @@ int watch_dmevents(char *name)
 	struct dev_event *dev_evt, *old_dev_evt;
 	int i;
 
-	if (!dm_is_mpath(name)) {
+	/* We know that this is a multipath device, so only fail if
+	 * device-mapper tells us that we're wrong */
+	if (dm_is_mpath(name) == 0) {
 		condlog(0, "%s: not a multipath device. can't watch events",
 			name);
 		return -1;
multipathd/main.c +1 -1
index 2e5f9ed..c781115 100644
@@ -699,7 +699,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs)
 	int delayed_reconfig, reassign_maps;
 	struct config *conf;
 
-	if (!dm_is_mpath(alias)) {
+	if (dm_is_mpath(alias) != 1) {
 		condlog(4, "%s: not a multipath map", alias);
 		return 0;
 	}
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] libmultipath: fix false removes in dmevents polling code

Quoted 22 lines · Benjamin Marzinski

dm_is_mpath() would return 0 if either a device was not a multipath device or if the libdevmapper command failed. Because dm_is_mpath() didn't distinguish between these situations, dm_get_events() could assume that a device was not really a multipath device, when in fact it
was, and the libdevmapper command simply failed. This would cause the dmevents polling waiter to stop monitoring the device.

In reality, the call to dm_is_mpath() isn't necessary, because dm_get_events() will already verify that the device name is on the list
of devices to wait for. However, if there are a large number of non-multipath devices on the system, ignoring them can be useful. Thus,
if dm_is_mpath() successfully runs the libdevmapper command and verifies
that the device is not a multipath device, dm_get_events() should skip
it. But if the libdevmapper command fails, dm_get_events() should still
check the device list, to see if the device should be monitored.

Quoted 6 lines

This commit makes dm_is_mpath() return -1 for situations where the libdevmapper command failed, and makes dm_get_events() only ignore
the device on a return of 0.

Quoted 8 lines
---
 libmpathpersist/mpath_persist.c |  4 ++--
 libmultipath/devmapper.c        | 41 +++++++++++++++++++++++++++++
------------
 multipath/main.c                |  2 +-
 multipathd/dmevents.c           |  8 ++++++--
 multipathd/main.c               |  2 +-
 5 files changed, 39 insertions(+), 18 deletions(-)