Skip to contentSkip to conversation

multipath: miscellaneous fixes and features

PATCH New Benjamin Marzinski 1 participant 9 messages Jun 28, 2013 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover multipath: miscellaneous fixes and features

Here's some patches that have been piling up.

Benjamin Marzinski (8):
Add multipath path format wildcard
load the dm-multipath module on multipathd startup Fix multipath rename from user_friendly_name to wwid Turn off user_friendly_names for netapp devices Don't detect prioritizers that don't work
Only load a multipath device RO if RW load fails with EROFS signal waiter thread to stop waiting on dm events fix mutipath -W on empty wwids file

 libmultipath/configure.c      |  7 ----
 libmultipath/devmapper.c      | 98 +++++++++++--------------------------------
 libmultipath/devmapper.h      |  3 --
 libmultipath/hwtable.c        |  1 +
 libmultipath/print.c          | 11 +++++
 libmultipath/propsel.c        | 13 ++++--
 libmultipath/waiter.c         |  9 ++++
 libmultipath/wwids.c          |  6 +++
 multipathd/main.c             |  8 ++++
 multipathd/multipathd.service |  1 +
 10 files changed, 70 insertions(+), 87 deletions(-)
Signature · 1 line
1.8.2
author maintainer
#1 lore raw

PATCH 1/8 Add multipath path format wildcard

This adds a new format wildcard, 'm', to be used with

multipathd show paths format

It prints the multipath device associated with the path.

---
 libmultipath/print.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
libmultipath/print.c +11 -0
index 274f5e7..c00f5d7 100644
@@ -422,6 +422,16 @@ snprint_path_serial (char * buff, size_t len, struct path * pp)
 }
 
 static int
+snprint_path_mpp (char * buff, size_t len, struct path * pp)
+{
+	if (!pp->mpp)
+		return snprintf(buff, len, "[orphan]");
+	if (!pp->mpp->alias)
+		return snprintf(buff, len, "[unknown]");
+	return snprint_str(buff, len, pp->mpp->alias);
+}
+
+static int
 snprint_path_checker (char * buff, size_t len, struct path * pp)
 {
 	struct checker * c = &pp->checker;
@@ -464,6 +474,7 @@ struct path_data pd[] = {
 	{'p', "pri",           0, snprint_pri},
 	{'S', "size",          0, snprint_path_size},
 	{'z', "serial",        0, snprint_path_serial},
+	{'m', "multipath",     0, snprint_path_mpp},
 	{0, NULL, 0 , NULL}
 };
 
Signature · 1 line
1.8.2
author maintainer
#2 lore raw

PATCH 2/8 load the dm-multipath module on multipathd startup

In reply to Benjamin Marzinski

This makes systemd modprobe dm-multipath before starting multipathd

---
 multipathd/multipathd.service | 1 +
 1 file changed, 1 insertion(+)
multipathd/multipathd.service +1 -0
index d6da067..b9f1210 100644
@@ -8,6 +8,7 @@ Conflicts=shutdown.target
 [Service]
 Type=forking
 PIDFile=/var/run/multipathd.pid
+ExecStartPre=/sbin/modprobe dm-multipath
 ExecStart=/sbin/multipathd
 ExecReload=/sbin/multipathd reconfigure
 #ExecStop=/path/to/scrip delete-me if not necessary
Signature · 1 line
1.8.2
author maintainer
#3 lore raw

PATCH 3/8 Fix multipath rename from user_friendly_name to wwid

In reply to Benjamin Marzinski

When multipath was selecting an alias for a device on reload, if it didn't have an explicit alias, and user_friendly_names wasn't set, multipath would use the existing alias, if one existed. This made it impossible to turn off user_friendly_names, and then reconfigure to change the device names back to wwids.

Instead, multipath should just use the wwid as an alias, if that's what it's configured to do, regardless of the existing name.

---
 libmultipath/devmapper.c | 45 ---------------------------------------------
 libmultipath/devmapper.h |  1 -
 libmultipath/propsel.c   |  2 --
 3 files changed, 48 deletions(-)
libmultipath/devmapper.c +0 -45
index 67481c4..1f3b64c 100644
@@ -917,51 +917,6 @@ out:
 	return r;
 }
 
-extern char *
-dm_get_name(char *uuid)
-{
-	struct dm_task *dmt;
-	struct dm_info info;
-	char *prefixed_uuid, *name = NULL;
-	const char *nametmp;
-
-	dmt = dm_task_create(DM_DEVICE_INFO);
-	if (!dmt)
-		return NULL;
-
-	prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1);
-	if (!prefixed_uuid) {
-		condlog(0, "cannot create prefixed uuid : %s",
-			strerror(errno));
-		goto freeout;
-	}
-	sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid);
-	if (!dm_task_set_uuid(dmt, prefixed_uuid))
-		goto freeout;
-
-	if (!dm_task_run(dmt))
-		goto freeout;
-
-	if (!dm_task_get_info(dmt, &info) || !info.exists)
-		goto freeout;
-
-	nametmp = dm_task_get_name(dmt);
-	if (nametmp && strlen(nametmp)) {
-		name = MALLOC(strlen(nametmp) + 1);
-		if (name)
-			strcpy(name, nametmp);
-	} else {
-		condlog(2, "%s: no device-mapper name found", uuid);
-	}
-
-freeout:
-	if (prefixed_uuid)
-		FREE(prefixed_uuid);
-	dm_task_destroy(dmt);
-
-	return name;
-}
-
 int
 dm_geteventnr (char *name)
 {
libmultipath/devmapper.h +0 -1
index bf8ee91..d27fe7f 100644
@@ -40,7 +40,6 @@ int dm_remove_partmaps (const char * mapname, int need_sync);
 int dm_get_uuid(char *name, char *uuid);
 int dm_get_info (char * mapname, struct dm_info ** dmi);
 int dm_rename (char * old, char * new);
-char * dm_get_name(char * uuid);
 int dm_reassign(const char * mapname);
 int dm_reassign_table(const char *name, char *old, char *new);
 int dm_setgeometry(struct multipath *mpp);
libmultipath/propsel.c +0 -2
index a7e1fc2..8ba3b44 100644
@@ -263,8 +263,6 @@ select_alias (struct multipath * mp)
 					conf->bindings_file, mp->alias_prefix, conf->bindings_read_only);
 		}
 		if (mp->alias == NULL)
-			mp->alias = dm_get_name(mp->wwid);
-		if (mp->alias == NULL)
 			mp->alias = STRDUP(mp->wwid);
 	}
 
Signature · 1 line
1.8.2
author maintainer
#4 lore raw

PATCH 4/8 Turn off user_friendly_names for netapp devices

In reply to Benjamin Marzinski

Netapp has requested that even if user friendly names is enabled in the defaults section, they would like it disabled for their devices.

---
 libmultipath/hwtable.c | 1 +
 1 file changed, 1 insertion(+)
libmultipath/hwtable.c +1 -0
index c317cde..197a1d7 100644
@@ -794,6 +794,7 @@ static struct hwentry default_hw[] = {
 		.prio_name     = PRIO_ONTAP,
 		.prio_args     = NULL,
 		.retain_hwhandler = RETAIN_HWHANDLER_ON,
+		.user_friendly_names = USER_FRIENDLY_NAMES_OFF,
 		.detect_prio   = DETECT_PRIO_ON,
 	},
 	/*
Signature · 1 line
1.8.2
author maintainer
#5 lore raw

PATCH 5/8 Don't detect prioritizers that don't work

In reply to Benjamin Marzinski

The current method used by detect_prio was selecting the ALUA prioritizer for devices that didn't have ALUA enabled. This patch makes detect_prio go through all the steps to get a priority with the ALUA prioritizer. If it is able to successfully get a priority, then it selects the ALUA proritizer for the device.

---
 libmultipath/propsel.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
libmultipath/propsel.c +9 -2
index 8ba3b44..079b704 100644
@@ -384,10 +384,17 @@ select_getuid (struct path * pp)
 void
 detect_prio(struct path * pp)
 {
+	int ret;
 	struct prio *p = &pp->prio;
 
-	if (get_target_port_group_support(pp->fd) > 0)
-		prio_get(p, PRIO_ALUA, DEFAULT_PRIO_ARGS);
+	if (get_target_port_group_support(pp->fd) <= 0)
+		return;
+	ret = get_target_port_group(pp->fd);
+	if (ret < 0)
+		return;
+	if (get_asymmetric_access_state(pp->fd, ret) < 0)
+		return;
+	prio_get(p, PRIO_ALUA, DEFAULT_PRIO_ARGS);
 }
 
 extern int
Signature · 1 line
1.8.2
author maintainer
#6 lore raw

PATCH 6/8 Only load a multipath device RO if RW load fails with

In reply to Benjamin Marzinski

If a transient error keeps multipath from being able to reload a multipath device read/write, it will retry the reload with the device set to read-only. This can suddenly turn a read/write multipath device read-only. If device-mapper cannot load the device read/write because a path device can't be opened for writing, it will return EROFS. This is the only time it makes sense to reload the device read-only.

---
 libmultipath/configure.c |  7 -------
 libmultipath/devmapper.c | 53 +++++++++++++++++++++++-------------------------
 libmultipath/devmapper.h |  2 --
 3 files changed, 25 insertions(+), 37 deletions(-)
libmultipath/configure.c +0 -7
index e5048eb..8b1385a 100644
@@ -384,24 +384,17 @@ domap (struct multipath * mpp, char * params)
 
 		r = dm_addmap_create(mpp, params);
 
-		if (!r)
-			r = dm_addmap_create_ro(mpp, params);
-
 		lock_multipath(mpp, 0);
 		break;
 
 	case ACT_RELOAD:
 		r = dm_addmap_reload(mpp, params);
-		if (!r)
-			r = dm_addmap_reload_ro(mpp, params);
 		if (r)
 			r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias);
 		break;
 
 	case ACT_RESIZE:
 		r = dm_addmap_reload(mpp, params);
-		if (!r)
-			r = dm_addmap_reload_ro(mpp, params);
 		if (r)
 			r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1);
 		break;
libmultipath/devmapper.c +25 -28

67 lines not on this page · raw message

libmultipath/devmapper.h +0 -2
index d27fe7f..464ae7b 100644
@@ -12,9 +12,7 @@ int dm_drv_version (unsigned int * version, char * str);
 int dm_simplecmd_flush (int, const char *, int);
 int dm_simplecmd_noflush (int, const char *);
 int dm_addmap_create (struct multipath *mpp, char *params);
-int dm_addmap_create_ro (struct multipath *mpp, char *params);
 int dm_addmap_reload (struct multipath *mpp, char *params);
-int dm_addmap_reload_ro (struct multipath *mpp, char *params);
 int dm_map_present (const char *);
 int dm_get_map(char *, unsigned long long *, char *);
 int dm_get_status(char *, char *);
Signature · 1 line
1.8.2
author maintainer
#7 lore raw

PATCH 7/8 signal waiter thread to stop waiting on dm events

In reply to Benjamin Marzinski

The ioctl syscall is not a pthread cancellation point. So, when device-mapper is waiting on events, pthread_cancel won't cancel the waiter thread. This patch makes the waiter threads handle SIGUSR2, and has stop_waiter_thread() signal it to break out of waiting on dm events. Unfortunately, there is still a possibility of the signal arriving before the ioctl, and the waiter thread still hanging until the devices are reloaded.

---
 libmultipath/waiter.c | 9 +++++++++
 multipathd/main.c     | 8 ++++++++
 2 files changed, 17 insertions(+)
libmultipath/waiter.c +9 -0
index 5094290..7cedd4b 100644
@@ -57,6 +57,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
 	thread = mpp->waiter;
 	mpp->waiter = (pthread_t)0;
 	pthread_cancel(thread);
+	pthread_kill(thread, SIGUSR2);
 }
 
 /*
@@ -65,6 +66,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
  */
 int waiteventloop (struct event_thread *waiter)
 {
+	sigset_t set, oldset;
 	int event_nr;
 	int r;
 
@@ -97,8 +99,15 @@ int waiteventloop (struct event_thread *waiter)
 	dm_task_no_open_count(waiter->dmt);
 
 	/* wait */
+	sigemptyset(&set);
+	sigaddset(&set, SIGUSR2);
+	pthread_sigmask(SIG_UNBLOCK, &set, &oldset);
+
+	pthread_testcancel();
 	r = dm_task_run(waiter->dmt);
+	pthread_testcancel();
 
+	pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 	dm_task_destroy(waiter->dmt);
 	waiter->dmt = NULL;
 
multipathd/main.c +8 -0
index 0fa1b17..82f8577 100644
@@ -1501,6 +1501,12 @@ sigusr1 (int sig)
 }
 
 static void
+sigusr2 (int sig)
+{
+	condlog(3, "SIGUSR2 received");
+}
+
+static void
 signal_init(void)
 {
 	sigset_t set;
@@ -1508,10 +1514,12 @@ signal_init(void)
 	sigemptyset(&set);
 	sigaddset(&set, SIGHUP);
 	sigaddset(&set, SIGUSR1);
+	sigaddset(&set, SIGUSR2);
 	pthread_sigmask(SIG_BLOCK, &set, NULL);
 
 	signal_set(SIGHUP, sighup);
 	signal_set(SIGUSR1, sigusr1);
+	signal_set(SIGUSR2, sigusr2);
 	signal_set(SIGINT, sigend);
 	signal_set(SIGTERM, sigend);
 	signal(SIGPIPE, SIG_IGN);
Signature · 1 line
1.8.2
author maintainer
#8 lore raw

PATCH 8/8 fix mutipath -W on empty wwids file

In reply to Benjamin Marzinski

When multipath tries to open the wwids file and finds it empty or missing, it writes the header to the file. When it tried to wipe the wwids from an empty or missing file, it didn't seek back to the start of the file after truncating it. This caused the the wwids file to have a patch of zeroed bytes at the start. This patch fixes this by always seeking back to the start of the file before rewriting the header.

---
 libmultipath/wwids.c | 6 ++++++
 1 file changed, 6 insertions(+)
libmultipath/wwids.c +6 -0
index 91b07a7..eca1799 100644
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <limits.h>
 #include <stdio.h>
+#include <sys/types.h>
 
 #include "checkers.h"
 #include "vector.h"
@@ -100,6 +101,11 @@ replace_wwids(vector mp)
 		condlog(0, "cannot truncate wwids file : %s", strerror(errno));
 		goto out_file;
 	}
+	if (lseek(fd, 0, SEEK_SET) < 0) {
+		condlog(0, "cannot seek to the start of the file : %s",
+			strerror(errno));
+		goto out_file;
+	}
 	len = strlen(WWIDS_FILE_HEADER);
 	if (write_all(fd, WWIDS_FILE_HEADER, len) != len) {
 		condlog(0, "Can't write wwid file header : %s",
Signature · 1 line
1.8.2