Skip to contentSkip to conversation

multipath cleanup patches

PATCH In review Benjamin Marzinski 2 participants 12 messages Mar 30, 2018 – Apr 4, 2018 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover multipath cleanup patches

The first four of these patches are minor fixes from Martin Wilck's review of my recently merged patchset. The fifth patch is a license clarification for libmpathcmd, and the sixth is is minor bugfix for multipathd config value printing

Benjamin Marzinski (6):
multipathd: remove incorrect pthread_testcancel
multipath: add comments
multipathd: minor dmevents polling code cleanups
multipathd: remove unneeded function parameter
mpathcmd: fix libmpathcmd license
libmultipath: don't print undefined values

 libmpathcmd/mpath_cmd.c | 19 +++++++++++++
 libmpathcmd/mpath_cmd.h |  2 +-
 libmultipath/dict.c     |  8 ++++++
 multipathd/dmevents.c   | 10 ++++---
 multipathd/main.c       | 15 +++++------
 multipathd/waiter.c     |  1 -
 tests/dmevents.c        | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-
 tests/util.c            |  2 ++
 8 files changed, 114 insertions(+), 15 deletions(-)
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 1/6 multipathd: remove incorrect pthread_testcancel

As Martin Wilck pointed out, a thread that's trying to stop the waiter thread should not cancel itself before it gets a chance to do so

Cc Martin Wilck <[email protected]>
Fixes c7625f92 "multipathd: fix waiter thread cancelling"
---
 multipathd/waiter.c | 1 -
 1 file changed, 1 deletion(-)
multipathd/waiter.c +0 -1
index 595c69a..0ef8b25 100644
@@ -68,7 +68,6 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
 	mpp->waiter = (pthread_t)0;
 	pthread_cleanup_push(cleanup_lock, &waiter_lock);
 	lock(&waiter_lock);
-	pthread_testcancel();
 	pthread_kill(thread, SIGUSR2);
 	pthread_cancel(thread);
 	lock_cleanup_pop(&waiter_lock);
Signature · 1 line
2.7.4
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] multipathd: remove incorrect pthread_testcancel

Quoted 7 lines · Benjamin Marzinski

As Martin Wilck pointed out, a thread that's trying to stop the waiter
thread should not cancel itself before it gets a chance to do so

Cc Martin Wilck <[email protected]>
Fixes c7625f92 "multipathd: fix waiter thread cancelling"
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

PATCH 2/6 multipath: add comments

In reply to Benjamin Marzinski

This commit simply adds a number of comments based on suggestions by Martin Wilck.

---
 multipathd/dmevents.c |  4 ++-
 tests/dmevents.c      | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 tests/util.c          |  2 ++
 3 files changed, 76 insertions(+), 2 deletions(-)
multipathd/dmevents.c +3 -1
index 2281a10..0b0d0ce 100644
@@ -122,6 +122,8 @@ static int arm_dm_event_poll(int fd)
 	dmi.version[0] = DM_VERSION_MAJOR;
 	dmi.version[1] = DM_VERSION_MINOR;
 	dmi.version[2] = DM_VERSION_PATCHLEVEL;
+	/* This flag currently does nothing. It simply exists to
+	 * duplicate the behavior of libdevmapper */
 	dmi.flags = 0x4;
 	dmi.data_start = offsetof(struct dm_ioctl, data);
 	dmi.data_size = sizeof(dmi);
@@ -189,7 +191,7 @@ fail:
 	return -1;
 }
 
-/* You must call update_multipath() after calling this function, to
+/* You must call __setup_multipath() after calling this function, to
  * deal with any events that came in before the device was added */
 int watch_dmevents(char *name)
 {
tests/dmevents.c +71 -1

298 lines not on this page · raw message

tests/util.c +2 -0
index e9a004f..113b134 100644
@@ -74,6 +74,8 @@ static void test_basenamecpy_good5(void **state)
 	assert_string_equal(dst, "bar");
 }
 
+/* multipath expects any trailing whitespace to be stripped off the basename,
+ * so that it will match pp->dev */
 static void test_basenamecpy_good6(void **state)
 {
         char dst[6];
Signature · 1 line
2.7.4
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] multipath: add comments

Quoted 5 lines · Benjamin Marzinski

This commit simply adds a number of comments based on suggestions by Martin Wilck.

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

PATCH 3/6 multipathd: minor dmevents polling code cleanups

In reply to Benjamin Marzinski

Change strncpy to strlcpy and lock_cleanup_pop to pthread_cleanup_pop, based on suggestions by Martin Wilck

---
 multipathd/dmevents.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
multipathd/dmevents.c +3 -3
index 0b0d0ce..e98a974 100644
@@ -24,6 +24,7 @@
 #include "debug.h"
 #include "main.h"
 #include "dmevents.h"
+#include "util.h"
 
 #ifndef DM_DEV_ARM_POLL
 #define DM_DEV_ARM_POLL _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD + 1, struct dm_ioctl)
@@ -214,8 +215,7 @@ int watch_dmevents(char *name)
 		return -1;
 	}
 
-	strncpy(dev_evt->name, name, WWID_SIZE);
-	dev_evt->name[WWID_SIZE - 1] = 0;
+	strlcpy(dev_evt->name, name, WWID_SIZE);
 	dev_evt->evt_nr = event_nr;
 	dev_evt->action = EVENT_NOTHING;
 
@@ -350,7 +350,7 @@ static int dmevent_loop (void)
 			remove_map_by_alias(curr_dev.name, waiter->vecs, 1);
 		else
 			r = update_multipath(waiter->vecs, curr_dev.name, 1);
-		lock_cleanup_pop(&waiter->vecs->lock);
+		pthread_cleanup_pop(1);
 
 		if (r) {
 			condlog(2, "%s: stopped watching dmevents",
Signature · 1 line
2.7.4
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] multipathd: minor dmevents polling code cleanups

Quoted 6 lines · Benjamin Marzinski

Change strncpy to strlcpy and lock_cleanup_pop to
pthread_cleanup_pop,
based on suggestions by Martin Wilck

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

PATCH 4/6 multipathd: remove unneeded function parameter

In reply to Benjamin Marzinski

remove_map_and_stop_waiter was always called with purge_vecs = 1, so it can simply be removed, as suggested by Martin Wilck

---
 multipathd/main.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
multipathd/main.c +7 -8
index 9a4f671..841d3e9 100644
@@ -311,14 +311,13 @@ wait_for_events(struct multipath *mpp, struct vectors *vecs)
 }
 
 static void
-remove_map_and_stop_waiter(struct multipath *mpp, struct vectors *vecs,
-			   int purge_vec)
+remove_map_and_stop_waiter(struct multipath *mpp, struct vectors *vecs)
 {
 	/* devices are automatically removed by the dmevent polling code,
 	 * so they don't need to be manually removed here */
 	if (!poll_dmevents)
 		stop_waiter_thread(mpp, vecs);
-	remove_map(mpp, vecs, purge_vec);
+	remove_map(mpp, vecs, PURGE_VEC);
 }
 
 static void
@@ -400,7 +399,7 @@ int __setup_multipath(struct vectors *vecs, struct multipath *mpp,
 
 	return 0;
 out:
-	remove_map_and_stop_waiter(mpp, vecs, PURGE_VEC);
+	remove_map_and_stop_waiter(mpp, vecs);
 	return 1;
 }
 
@@ -637,7 +636,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)
 	}
 
 	orphan_paths(vecs->pathvec, mpp);
-	remove_map_and_stop_waiter(mpp, vecs, 1);
+	remove_map_and_stop_waiter(mpp, vecs);
 
 	return 0;
 }
@@ -769,7 +768,7 @@ uev_remove_map (struct uevent * uev, struct vectors * vecs)
 	}
 
 	orphan_paths(vecs->pathvec, mpp);
-	remove_map_and_stop_waiter(mpp, vecs, 1);
+	remove_map_and_stop_waiter(mpp, vecs);
 out:
 	lock_cleanup_pop(vecs->lock);
 	FREE(alias);
@@ -1154,7 +1153,7 @@ out:
 	return retval;
 
 fail:
-	remove_map_and_stop_waiter(mpp, vecs, 1);
+	remove_map_and_stop_waiter(mpp, vecs);
 	return 1;
 }
 
@@ -1612,7 +1611,7 @@ mpvec_garbage_collector (struct vectors * vecs)
 	vector_foreach_slot (vecs->mpvec, mpp, i) {
 		if (mpp && mpp->alias && !dm_map_present(mpp->alias)) {
 			condlog(2, "%s: remove dead map", mpp->alias);
-			remove_map_and_stop_waiter(mpp, vecs, 1);
+			remove_map_and_stop_waiter(mpp, vecs);
 			i--;
 		}
 	}
Signature · 1 line
2.7.4
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] multipathd: remove unneeded function parameter

Quoted 5 lines · Benjamin Marzinski

remove_map_and_stop_waiter was always called with purge_vecs = 1, so it can simply be removed, as suggested by Martin Wilck

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

PATCH 5/6 mpathcmd: fix libmpathcmd license

In reply to Benjamin Marzinski

There is no version 2 of the GNU Lesser General Public License, so change the license header to version 2.1, which does exist. Also copy the license header to mpath_cmd.c. I've CC'ed everyone who has contributed code to libmpathcmd.

Cc Xose Vazquez Perez <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Martin Wilck <[email protected]>
Cc tang.junhui <[email protected]>
Cc Gris Ge <[email protected]>
---
 libmpathcmd/mpath_cmd.c | 19 +++++++++++++++++++
 libmpathcmd/mpath_cmd.h |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)
libmpathcmd/mpath_cmd.c +19 -0
index 29d148c..61e6a98 100644
@@ -1,3 +1,22 @@
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This file is part of the device-mapper multipath userspace tools.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
libmpathcmd/mpath_cmd.h +1 -1
index b57b708..aaa8da9 100644
@@ -5,7 +5,7 @@
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
Signature · 1 line
2.7.4
Acked-by on v1 5/6
#10 lore raw

Re: [PATCH 5/6] mpathcmd: fix libmpathcmd license

Quoted 5 lines · Benjamin Marzinski

There is no version 2 of the GNU Lesser General Public License, so change the license header to version 2.1, which does exist. Also copy the license header to mpath_cmd.c. I've CC'ed everyone who has contributed code to libmpathcmd.

Quoted 7 lines
Cc Xose Vazquez Perez <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Martin Wilck <[email protected]>
Cc tang.junhui <[email protected]>
Cc Gris Ge <[email protected]>
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

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

PATCH 6/6 libmultipath: don't print undefined values

In reply to Benjamin Marzinski

commit 48e9fd9f ("libmultipath: parser: use call-by-value for "snprint" methods") removed some of the code that checked for undefined values to avoid printing them. This lead to device configurations that printed out values for parameters that they hadn't configured. This patch adds that code back in.

Fixes 48e9fd9f ("libmultipath: parser: use call-by-value for "snprint" methods")
Cc Martin Wilck <[email protected]>
---
 libmultipath/dict.c | 8 ++++++++
 1 file changed, 8 insertions(+)
libmultipath/dict.c +8 -0
index ac9216c..1a18337 100644
@@ -101,12 +101,16 @@ print_int (char *buff, int len, long v)
 static int
 print_nonzero (char *buff, int len, long v)
 {
+	if (!v)
+		return 0;
 	return snprintf(buff, len, "%li", v);
 }
 
 static int
 print_str (char *buff, int len, const char *ptr)
 {
+	if (!ptr)
+		return 0;
 	return snprintf(buff, len, "\"%s\"", ptr);
 }
 
@@ -120,6 +124,8 @@ print_yes_no (char *buff, int len, long v)
 static int
 print_yes_no_undef (char *buff, int len, long v)
 {
+	if (!v)
+		return 0;
 	return snprintf(buff, len, "\"%s\"",
 			(v == YNU_NO)? "no" : "yes");
 }
@@ -665,6 +671,8 @@ set_dev_loss(vector strvec, void *ptr)
 int
 print_dev_loss(char * buff, int len, unsigned long v)
 {
+	if (!v)
+		return 0;
 	if (v >= MAX_DEV_LOSS_TMO)
 		return snprintf(buff, len, "\"infinity\"");
 	return snprintf(buff, len, "%lu", v);
Signature · 1 line
2.7.4