Skip to contentSkip to conversation

multipath: new path validation library

RFC PATCH Superseded Benjamin Marzinski 3 participants 11 messages Mar 31, 2020 – Apr 3, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover multipath: new path validation library

This patchset is for a new library that programs can use to determine if a device belongs to multipath. The primary user that this is intended for is SID, the Storage Instantiation Daemon

https://github.com/sid-project

Right now, this doesn't change our existing code to determine path ownership, and it doesn't do the exact same steps, although it is very close. In the future, it would be possible to pull most of this code entirely into libmultipath, except for some wrappers, and use it for both methods. Obviously, this still needs man pages, and there are some helper functions for things like controlling multipath's logging that are missing, but I want to see if anyone has strong feelings about what this looks like.

I also have two more changes that I want to make to the multipath code, to make path validation do less unnecessary work, which aren't in this patchset.

1. I want to remove the lock file from the failed wwids code. I don't see how it actually stops any races, and it means that simply reading a file, can trigger delays and writes (albeit to a memory base fs).

2. I want to deprecate getuid_callout. Once this is gone, you will be able to call pathinfo and get a path's WWID, without ever needing to open the path.

Benjamin Marzinski (3):
libmultipath: make libmp_dm_init optional
libmultipath: make sysfs_is_multipathed able to return wwid
multipath: add libmpathvalid library

 Makefile                            |   1 +
 Makefile.inc                        |   1 +
 libmpathvalid/Makefile              |  38 +++++++
 libmpathvalid/libmpathvalid.version |   6 +
 libmpathvalid/mpath_valid.c         | 171 ++++++++++++++++++++++++++++
 libmpathvalid/mpath_valid.h         |  53 +++++++++
 libmultipath/Makefile               |   1 +
 libmultipath/devmapper.c            |  66 ++++++++++-
 libmultipath/devmapper.h            |   4 +-
 libmultipath/sysfs.c                |  22 +++-
 libmultipath/sysfs.h                |   2 +-
 multipath/main.c                    |   7 +-
 12 files changed, 360 insertions(+), 12 deletions(-)
 create mode 100644 libmpathvalid/Makefile
 create mode 100644 libmpathvalid/libmpathvalid.version
 create mode 100644 libmpathvalid/mpath_valid.c
 create mode 100644 libmpathvalid/mpath_valid.h
Signature · 1 line
2.17.2
author maintainer
#1 lore raw

RFC PATCH 1/3 libmultipath: make libmp_dm_init optional

Move dm_initialized out of libmp_dm_task_create(), and add a function skip_libmp_dm_init() so that users of libmultipath can skip initializing device-mapper. This is needed for other programs that use libmultipath (or a library that depends on it) but want to control how device-mapper is set up.

Also make dm_prereq a global function.

---
 libmultipath/devmapper.c | 17 +++++++++++++----
 libmultipath/devmapper.h |  3 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)
libmultipath/devmapper.c +13 -4
index 13a1cf53..7ed494a1 100644
@@ -33,6 +33,8 @@
 #define MAX_WAIT 5
 #define LOOPS_PER_SEC 5
 
+static pthread_once_t dm_initialized = PTHREAD_ONCE_INIT;
+
 static int dm_conf_verbosity;
 
 #ifdef LIBDM_API_DEFERRED
@@ -229,7 +231,7 @@ dm_tgt_prereq (unsigned int *ver)
 	return 1;
 }
 
-static int dm_prereq(unsigned int *v)
+int dm_prereq(unsigned int *v)
 {
 	if (dm_lib_prereq())
 		return 1;
@@ -243,7 +245,7 @@ void libmp_udev_set_sync_support(int on)
 	libmp_dm_udev_sync = !!on;
 }
 
-void libmp_dm_init(void)
+static void libmp_dm_init(void)
 {
 	struct config *conf;
 	int verbosity;
@@ -262,11 +264,18 @@ void libmp_dm_init(void)
 	dm_udev_set_sync_support(libmp_dm_udev_sync);
 }
 
+static void _do_skip_libmp_dm_init(void)
+{
+}
+
+void skip_libmp_dm_init(void)
+{
+	pthread_once(&dm_initialized, _do_skip_libmp_dm_init);
+}
+
 struct dm_task*
 libmp_dm_task_create(int task)
 {
-	static pthread_once_t dm_initialized = PTHREAD_ONCE_INIT;
-
 	pthread_once(&dm_initialized, libmp_dm_init);
 	return dm_task_create(task);
 }
libmultipath/devmapper.h +2 -1
index 7557a86b..17fc9faf 100644
@@ -28,7 +28,8 @@
 #define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1)
 
 void dm_init(int verbosity);
-void libmp_dm_init(void);
+int dm_prereq(unsigned int *v);
+void skip_libmp_dm_init(void);
 void libmp_udev_set_sync_support(int on);
 struct dm_task *libmp_dm_task_create(int task);
 int dm_drv_version (unsigned int * version);
Signature · 1 line
2.17.2
Reviewed-by on v1 1/3
#2 lore raw

Re: [RFC Patch 1/3] libmultipath: make libmp_dm_init optional

Quoted 11 lines · Benjamin Marzinski

Move dm_initialized out of libmp_dm_task_create(), and add a function skip_libmp_dm_init() so that users of libmultipath can skip
initializing device-mapper. This is needed for other programs that use libmultipath (or a library that depends on it) but want to control
how device-mapper is set up.

Also make dm_prereq a global function.

author maintainer
#3 lore raw

RFC PATCH 2/3 libmultipath: make sysfs_is_multipathed able to return wwid

In reply to Benjamin Marzinski

sysfs_is_multipathed reads the wwid of the dm device holding a path to check if its a multipath device. Add code to optinally set pp->wwid to that wwid. This will be used by a future patch.

---
 libmultipath/sysfs.c | 22 +++++++++++++++++++---
 libmultipath/sysfs.h |  2 +-
 multipath/main.c     |  7 ++++---
 3 files changed, 24 insertions(+), 7 deletions(-)
libmultipath/sysfs.c +19 -3
index 62ec2ed7..034f082f 100644
@@ -295,7 +295,7 @@ static int select_dm_devs(const struct dirent *di)
 	return fnmatch("dm-*", di->d_name, FNM_FILE_NAME) == 0;
 }
 
-bool sysfs_is_multipathed(const struct path *pp)
+bool sysfs_is_multipathed(struct path *pp, bool set_wwid)
 {
 	char pathbuf[PATH_MAX];
 	struct scandir_result sr;
@@ -342,9 +342,25 @@ bool sysfs_is_multipathed(const struct path *pp)
 		if (nr == sizeof(uuid) && !memcmp(uuid, "mpath-", sizeof(uuid)))
 			found = true;
 		else if (nr < 0) {
-			condlog(1, "%s: error reading from %s: %s",
-				__func__, pathbuf, strerror(errno));
+			condlog(1, "%s: error reading from %s: %m",
+				__func__, pathbuf);
 		}
+		if (found && set_wwid) {
+			nr = read(fd, pp->wwid, WWID_SIZE);
+			if (nr < 0) {
+				condlog(1, "%s: error reading from %s: %m",
+					__func__, pathbuf);
+				pp->wwid[0] = '\0';
+			} else if (nr == WWID_SIZE) {
+				condlog(4, "%s: overflow while reading from %s",
+					__func__, pathbuf);
+				pp->wwid[0] = '\0';
+			} else {
+				pp->wwid[nr] = '\0';
+				strchop(pp->wwid);
+			}
+                }
+
 		pthread_cleanup_pop(1);
 	}
 	pthread_cleanup_pop(1);
libmultipath/sysfs.h +1 -1
index 9ae30b39..72b39ab2 100644
@@ -14,5 +14,5 @@ ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name,
 				 unsigned char * value, size_t value_len);
 int sysfs_get_size (struct path *pp, unsigned long long * size);
 int sysfs_check_holders(char * check_devt, char * new_devt);
-bool sysfs_is_multipathed(const struct path *pp);
+bool sysfs_is_multipathed(struct path *pp, bool set_wwid);
 #endif
multipath/main.c +4 -3
index cf9d2a28..545ead87 100644
@@ -638,7 +638,8 @@ configure (struct config *conf, enum mpath_cmds cmd,
 			 * Shortcut for find_multipaths smart:
 			 * Quick check if path is already multipathed.
 			 */
-			if (sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0))) {
+			if (sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0),
+						 false)) {
 				r = RTVL_YES;
 				goto print_valid;
 			}
@@ -747,8 +748,8 @@ configure (struct config *conf, enum mpath_cmds cmd,
 			/*
 			 * Check if we raced with multipathd
 			 */
-			r = sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0)) ?
-				RTVL_YES : RTVL_NO;
+			r = sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0),
+						 false) ? RTVL_YES : RTVL_NO;
 		}
 		goto print_valid;
 	}
Signature · 1 line
2.17.2
#4 lore raw

Re: [RFC Patch 2/3] libmultipath: make sysfs_is_multipathed able to return wwid

Quoted 29 lines · Benjamin Marzinski

sysfs_is_multipathed reads the wwid of the dm device holding a path to
check if its a multipath device. Add code to optinally set pp->wwid to
that wwid. This will be used by a future patch.

---
 libmultipath/sysfs.c | 22 +++++++++++++++++++---
 libmultipath/sysfs.h |  2 +-
 multipath/main.c     |  7 ++++---
 3 files changed, 24 insertions(+), 7 deletions(-)
libmultipath/sysfs.c +1 -1
index 62ec2ed7..034f082f 100644
@@ -295,7 +295,7 @@ static int select_dm_devs(const struct dirent
 *di)
 	return fnmatch("dm-*", di->d_name, FNM_FILE_NAME) == 0;
 }
 
-bool sysfs_is_multipathed(const struct path *pp)
+bool sysfs_is_multipathed(struct path *pp, bool set_wwid)
 {
 	char pathbuf[PATH_MAX];
libmultipath/sysfs.c +0 -0
 	struct scandir_result sr;
@@ -342,9 +342,25 @@ bool sysfs_is_multipathed(const struct path *pp)
 		if (nr == sizeof(uuid) && !memcmp(uuid, "mpath-",

libmultipath/sysfs.c bool sysfs_is_multipathed(const struct path *pp) · line 350

Quoted 10 lines
libmultipath/sysfs.c +4 -2
 sizeof(uuid)))
 			found = true;
 		else if (nr < 0) {
-			condlog(1, "%s: error reading from %s: %s",
-				__func__, pathbuf, strerror(errno));
+			condlog(1, "%s: error reading from %s: %m",
+				__func__, pathbuf);
 		}
+		if (found && set_wwid) {
+			nr = read(fd, pp->wwid, WWID_SIZE);

I'd rather read the whole UUID in a single syscall (i.e. merge this with the previous read() that fetched the first 6 chars).

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

Re: [RFC Patch 2/3] libmultipath: make sysfs_is_multipathed able to return wwid

Quoted 16 lines · Martin Wilck

libmultipath/sysfs.c bool sysfs_is_multipathed(const struct path *pp) · line 350

Quoted 12 lines · Benjamin Marzinski
libmultipath/sysfs.c +4 -2
@@ -342,9 +342,25 @@ bool sysfs_is_multipathed(const struct path *pp)
 		if (nr == sizeof(uuid) && !memcmp(uuid, "mpath-",
 sizeof(uuid)))
 			found = true;
 		else if (nr < 0) {
-			condlog(1, "%s: error reading from %s: %s",
-				__func__, pathbuf, strerror(errno));
+			condlog(1, "%s: error reading from %s: %m",
+				__func__, pathbuf);
 		}
+		if (found && set_wwid) {
+			nr = read(fd, pp->wwid, WWID_SIZE);

I'd rather read the whole UUID in a single syscall (i.e. merge this with the previous read() that fetched the first 6 chars).

Sure.

-Ben

Quoted 10 lines

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

RFC PATCH 3/3 multipath: add libmpathvalid library

In reply to Benjamin Marzinski

This library allows other programs to check if a path should be claimed by multipath. Currently, it only includes one function, mpath_is_path(), which takes a device name, mode to for checking the path, and an optional info structure, to return the wwid. The modes work mostly like they do for "multipath -c/-u", with a few exceptions.

1. If a device is currently multipathed, it is always VALID. This perhaps should be true for the existing path valid code.

2. There is no seperate "on" mode. It is instead treated like "smart". This is because the library only looks at a single path, so it can only say that a device could be multpathed, if there was another path. It is the caller's job to check if another path exists, or to wait for another path appear.

3. The library does check if there already is an existing multipath device with the same wwid, and if so, will declare the path valid.

In order to act more library-like, libmpathvalid doesn't set its own device-mapper log functions. It leaves this to the caller. It currently keeps condlog() from printing anything, but should eventually include a function to allow the caller set the logging. It also uses a statically compiled version of libmultipath, both to keep that library from polluting the namespace of the caller, and to avoid the caller needing to set up the variables and functions (like logsink, and get_multipath_config) that it expects.

---
 Makefile                            |   1 +
 Makefile.inc                        |   1 +
 libmpathvalid/Makefile              |  38 +++++++
 libmpathvalid/libmpathvalid.version |   6 +
 libmpathvalid/mpath_valid.c         | 171 ++++++++++++++++++++++++++++
 libmpathvalid/mpath_valid.h         |  53 +++++++++
 libmultipath/Makefile               |   1 +
 libmultipath/devmapper.c            |  49 ++++++++
 libmultipath/devmapper.h            |   1 +
 9 files changed, 321 insertions(+)
 create mode 100644 libmpathvalid/Makefile
 create mode 100644 libmpathvalid/libmpathvalid.version
 create mode 100644 libmpathvalid/mpath_valid.c
 create mode 100644 libmpathvalid/mpath_valid.h
Makefile +1 -0
index 1dee3680..462d6655 100644
@@ -9,6 +9,7 @@ BUILDDIRS := \
 	libmultipath/checkers \
 	libmultipath/foreign \
 	libmpathpersist \
+	libmpathvalid \
 	multipath \
 	multipathd \
 	mpathpersist \
Makefile.inc +1 -0
index d4d1e0dd..7e0e8203 100644
@@ -66,6 +66,7 @@ libdir		= $(prefix)/$(LIB)/multipath
 unitdir		= $(prefix)/$(SYSTEMDPATH)/systemd/system
 mpathpersistdir	= $(TOPDIR)/libmpathpersist
 mpathcmddir	= $(TOPDIR)/libmpathcmd
+mpathvaliddir	= $(TOPDIR)/libmpathvalid
 thirdpartydir	= $(TOPDIR)/third-party
 libdmmpdir	= $(TOPDIR)/libdmmp
 nvmedir		= $(TOPDIR)/libmultipath/nvme
libmpathvalid/Makefile new file +38 -0
new file mode 100644
index 00000000..5fc97022
@@ -0,0 +1,38 @@
+include ../Makefile.inc
+
+SONAME = 0
+DEVLIB = libmpathvalid.so
+LIBS = $(DEVLIB).$(SONAME)
+
+CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+
+LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
+	   -lmultipath_nonshared -L$(mpathcmddir) -lmpathcmd -ludev
+
+OBJS = mpath_valid.o
+
+all: $(LIBS)
+
+$(LIBS): $(OBJS)
+	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS) $(LIBDEPS) -Wl,--version-script=libmpathvalid.version
+	$(LN) $(LIBS) $(DEVLIB)
+
+install: $(LIBS)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(syslibdir)
+	$(INSTALL_PROGRAM) -m 755 $(LIBS) $(DESTDIR)$(syslibdir)/$(LIBS)
+	$(LN) $(LIBS) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(includedir)
+	$(INSTALL_PROGRAM) -m 644 mpath_valid.h $(DESTDIR)$(includedir)
+
+uninstall:
+	$(RM) $(DESTDIR)$(syslibdir)/$(LIBS)
+	$(RM) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(RM) $(DESTDIR)$(includedir)/mpath_valid.h
+
+clean: dep_clean
+	$(RM) core *.a *.o *.so *.so.* *.gz
+
+include $(wildcard $(OBJS:.o=.d))
+
+dep_clean:
+	$(RM) $(OBJS:.o=.d)
libmpathvalid/libmpathvalid.version new file +6 -0
new file mode 100644
index 00000000..e8967951
@@ -0,0 +1,6 @@
+MPATH_1.0 {
+	global:
+		mpath_is_path;
+	local:
+		*;
+};
libmpathvalid/mpath_valid.c new file +171 -0

171 lines not on this page · raw message

libmpathvalid/mpath_valid.h new file +53 -0

53 lines not on this page · raw message

libmultipath/Makefile +1 -0
index ad690a49..7e2c00cf 100644
@@ -69,6 +69,7 @@ nvme-ioctl.h: nvme/nvme-ioctl.h
 
 $(LIBS): $(OBJS)
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS) $(LIBDEPS)
+	ar rcs libmultipath_nonshared.a $(OBJS)
 	$(LN) $@ $(DEVLIB)
 
 install:
libmultipath/devmapper.c +49 -0

55 lines not on this page · raw message

libmultipath/devmapper.h +1 -0
index 17fc9faf..fa2513c2 100644
@@ -43,6 +43,7 @@ int dm_get_map(const char *, unsigned long long *, char *);
 int dm_get_status(const char *, char *);
 int dm_type(const char *, char *);
 int dm_is_mpath(const char *);
+int dm_is_mpath_uuid(const char *uuid);
 int _dm_flush_map (const char *, int, int, int, int);
 int dm_flush_map_nopaths(const char * mapname, int deferred_remove);
 #define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0, 0, 0)
Signature · 1 line
2.17.2
#7 lore raw

Re: [RFC Patch 3/3] multipath: add libmpathvalid library

Quoted 10 lines · Benjamin Marzinski

This library allows other programs to check if a path should be claimed
by multipath. Currently, it only includes one function, mpath_is_path(), which takes a device name, mode to for checking the path, and an optional info structure, to return the wwid. The modes work
mostly like they do for "multipath -c/-u", with a few exceptions.

1. If a device is currently multipathed, it is always VALID. This perhaps should be true for the existing path valid code.

AFAICS, this is already the case, except if:

1 WWID_IS_FAILED is set, i.e. dm_addmap() failed to set up
the multipath with this WWID last time we tried. In this case it's unlikely that the path is currently multipathed. But there may be some corner case in which your new code would return "valid" while the current code would not; possibly if someone set up a multipath device with "dmsetup" directly, or because of some race condition. I just realized that we don't check for -EBUSY when we create a map...

I agree that perhaps the "is_multipath" test should be done before the "failed" test in multipath -u, too.

2 ignore_wwids is off, and check_wwids_file returned a negative
result. IMO this logic is correct. But you are the inventor of the wwids file, so fine with me to change it.

And also if multipathd is neither running nor enabled, but see below.

Quoted 10 lines

2. There is no seperate "on" mode. It is instead treated like "smart".
This is because the library only looks at a single path, so it can only
say that a device could be multpathed, if there was another path. It is
the caller's job to check if another path exists, or to wait for another
path appear.

I'm not sure if I like this. Returning "no" for the first path and "yes" for the second and later paths is exactly how "find_multipaths=yes" is supposed to behave. If that's not useful for an application, the application should choose a different mode; and that's what I believe SID should do (assuming that SID will be the main / only user of this API for some time).

Quoted 3 lines

3. The library does check if there already is an existing multipath device with the same wwid, and if so, will declare the path valid.

What if there are other paths, not multipathed (yet) but with the same wwid as the path in question? The current code checks that by calling coalesce_paths() in "dry-run" mode, which would cover both this case and your case 3.

Quoted 13 lines

In order to act more library-like, libmpathvalid doesn't set its own device-mapper log functions. It leaves this to the caller. It currently
keeps condlog() from printing anything, but should eventually include a
function to allow the caller set the logging. It also uses a statically
compiled version of libmultipath, both to keep that library from polluting the namespace of the caller, and to avoid the caller needing
to set up the variables and functions (like logsink, and get_multipath_config) that it expects.

All fair, but I'd prefer a solution where we use as much common code as possible, to avoid bit rot of either code path in the future. Your new function has the advantage to be much better readable than the current code in multipath/main.c. Maybe we can find a way to use it from "multipath -u"? The mentioned semantic changes are minor and could be resolved (not sure about the coalesce_paths() call, I guess you had a reason to skip it).

The namespace issue could be fixed by using "-fvisibility=hidden" and using explicit visibility attributes for those functions we want to export. The logsink and get_multipath_config issues should be solvable by using a sane default implementation and allowing applications to change it.

Both would be improvements for libmultipath that we should have made long ago.

Quoted 210 lines
---
 Makefile                            |   1 +
 Makefile.inc                        |   1 +
 libmpathvalid/Makefile              |  38 +++++++
 libmpathvalid/libmpathvalid.version |   6 +
 libmpathvalid/mpath_valid.c         | 171
++++++++++++++++++++++++++++
 libmpathvalid/mpath_valid.h         |  53 +++++++++
 libmultipath/Makefile               |   1 +
 libmultipath/devmapper.c            |  49 ++++++++
 libmultipath/devmapper.h            |   1 +
 9 files changed, 321 insertions(+)
 create mode 100644 libmpathvalid/Makefile
 create mode 100644 libmpathvalid/libmpathvalid.version
 create mode 100644 libmpathvalid/mpath_valid.c
 create mode 100644 libmpathvalid/mpath_valid.h
Makefile +1 -0
index 1dee3680..462d6655 100644
@@ -9,6 +9,7 @@ BUILDDIRS := \
 	libmultipath/checkers \
 	libmultipath/foreign \
 	libmpathpersist \
+	libmpathvalid \
 	multipath \
 	multipathd \
 	mpathpersist \
Makefile.inc +1 -0
index d4d1e0dd..7e0e8203 100644
@@ -66,6 +66,7 @@ libdir		= $(prefix)/$(LIB)/multipath
 unitdir		= $(prefix)/$(SYSTEMDPATH)/systemd/system
 mpathpersistdir	= $(TOPDIR)/libmpathpersist
 mpathcmddir	= $(TOPDIR)/libmpathcmd
+mpathvaliddir	= $(TOPDIR)/libmpathvalid
 thirdpartydir	= $(TOPDIR)/third-party
 libdmmpdir	= $(TOPDIR)/libdmmp
 nvmedir		= $(TOPDIR)/libmultipath/nvme
libmpathvalid/Makefile new file +17 -0
new file mode 100644
index 00000000..5fc97022
@@ -0,0 +1,38 @@
+include ../Makefile.inc
+
+SONAME = 0
+DEVLIB = libmpathvalid.so
+LIBS = $(DEVLIB).$(SONAME)
+
+CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+
+LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
+	   -lmultipath_nonshared -L$(mpathcmddir) -lmpathcmd -ludev
+
+OBJS = mpath_valid.o
+
+all: $(LIBS)
+
+$(LIBS): $(OBJS)
+	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS)

$(LIBDEPS) -Wl,--version-script=libmpathvalid.version

libmpathvalid/Makefile new file +5 -0
+	$(LN) $(LIBS) $(DEVLIB)
+
+install: $(LIBS)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(syslibdir)
+	$(INSTALL_PROGRAM) -m 755 $(LIBS)

$(DESTDIR)$(syslibdir)/$(LIBS)

libmpathvalid/Makefile new file +16 -0
+	$(LN) $(LIBS) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(includedir)
+	$(INSTALL_PROGRAM) -m 644 mpath_valid.h $(DESTDIR)$(includedir)
+
+uninstall:
+	$(RM) $(DESTDIR)$(syslibdir)/$(LIBS)
+	$(RM) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(RM) $(DESTDIR)$(includedir)/mpath_valid.h
+
+clean: dep_clean
+	$(RM) core *.a *.o *.so *.so.* *.gz
+
+include $(wildcard $(OBJS:.o=.d))
+
+dep_clean:
+	$(RM) $(OBJS:.o=.d)
libmpathvalid/libmpathvalid.version new file +6 -0
new file mode 100644
index 00000000..e8967951
@@ -0,0 +1,6 @@
+MPATH_1.0 {
+	global:
+		mpath_is_path;
+	local:
+		*;
+};
libmpathvalid/mpath_valid.c new file +51 -0
new file mode 100644
index 00000000..3d96c32f
@@ -0,0 +1,171 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <libdevmapper.h>
+#include <libudev.h>
+#include <errno.h>
+
+#include "devmapper.h"
+#include "structs.h"
+#include "util.h"
+#include "config.h"
+#include "discovery.h"
+#include "wwids.h"
+#include "sysfs.h"
+#include "mpath_cmd.h"
+#include "mpath_valid.h"
+
+struct udev *udev;
+int logsink = -1;
+static struct config default_config = { .verbosity = -1 };
+static struct config *multipath_conf;
+
+struct config *get_multipath_config(void)
+{
+	return (multipath_conf)? multipath_conf : &default_config;
+}
+
+void put_multipath_config(__attribute__((unused))void *conf)
+{
+	/* Noop */
+}
+
+static int get_conf_mode(struct config *conf)
+{
+	if (conf->find_multipaths == FIND_MULTIPATHS_ON ||
+	    conf->find_multipaths == FIND_MULTIPATHS_SMART)
+		return MPATH_SMART;
+	if (conf->find_multipaths == FIND_MULTIPATHS_GREEDY)
+		return MPATH_GREEDY;
+	return MPATH_STRICT;
+}
+
+
+/*
+ * Return
+ *  2: possible path (only in MPATH_GREEDY mode)
+ *  1: mpath path
+ *  0: not mpath path
+ * -1: Failure
+ */
+int
+mpath_is_path(const char *name, unsigned int mode, struct mpath_info

*info)

libmpathvalid/mpath_valid.c new file +48 -0
+{
+	struct config *conf;
+	struct path * pp;
+	int r = MPATH_IS_ERROR;
+	int fd = -1;
+	unsigned int version[3];
+	bool already_multipathed = false;
+
+	if (info)
+		memset(info, 0, sizeof(struct mpath_info));
+
+	if (!name || mode >= MPATH_MAX_MODE)
+		return r;
+
+	skip_libmp_dm_init();
+	udev = udev_new();
+	if (!udev)
+		goto out;
+	conf = load_config(DEFAULT_CONFIGFILE);
+	if (!conf)
+		goto out_udev;
+	conf->verbosity = -1;
+	if (mode == MPATH_DEFAULT)
+		mode = get_conf_mode(conf);
+
+	if (dm_prereq(version))
+		goto out_config;
+	memcpy(conf->version, version, sizeof(version));
+	multipath_conf = conf;
+
+	pp = alloc_path();
+	if (!pp)
+		goto out_config;
+
+	if (safe_sprintf(pp->dev, "%s", name))
+		goto out_path;
+
+	if (sysfs_is_multipathed(pp, true)) {
+		if (!info || pp->wwid[0] != '\0') {
+			r = MPATH_IS_VALID;
+			goto out_path;
+		}
+		already_multipathed = true;
+	}
+
+	fd = __mpath_connect(1);
+	if (fd < 0) {
+		if (errno != EAGAIN && !systemd_service_enabled(name))

{

libmpathvalid/mpath_valid.c line 104

Quoted 5 lines
libmpathvalid/mpath_valid.c new file +5 -0
+			r = MPATH_IS_NOT_VALID;
+			goto out_path;
+		}
+	} else
+		mpath_disconnect(fd);

So "multipathd not running" takes precedence over "is already multipathed"? That contradicts your statement 1. above. Would SID (or any other external application using your API) really require multipathd?

Quoted 151 lines
libmpathvalid/mpath_valid.c new file +2 -0
+
+	pp->udev = udev_device_new_from_subsystem_sysname(udev,

"block", name);

libmpathvalid/mpath_valid.c new file +65 -0
+	if (!pp->udev)
+		goto out_path;
+
+	r = pathinfo(pp, conf, DI_SYSFS | DI_WWID | DI_BLACKLIST);
+	if (r) {
+		if (r == PATHINFO_SKIPPED)
+			r = MPATH_IS_NOT_VALID;
+		else
+			r = MPATH_IS_ERROR;
+		goto out_path;
+	}
+
+	if (pp->wwid[0] == '\0') {
+		r = MPATH_IS_NOT_VALID;
+		goto out_path;
+	}
+
+	if (already_multipathed)
+		goto out_path;
+
+	if (dm_is_mpath_uuid(pp->wwid) == 1) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	r = is_failed_wwid(pp->wwid);
+	if (r != WWID_IS_NOT_FAILED) {
+		if (r == WWID_IS_FAILED)
+			r = MPATH_IS_NOT_VALID;
+		else
+			r = MPATH_IS_ERROR;
+		goto out_path;
+	}
+
+	if (mode == MPATH_GREEDY) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	if (check_wwids_file(pp->wwid, 0) == 0) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	if (mode == MPATH_STRICT) {
+		r = MPATH_IS_NOT_VALID;
+		goto out_path;
+	}
+
+	/* mode == SMART */
+	r = MPATH_IS_MAYBE_VALID;
+
+out_path:
+	if (already_multipathed)
+		r = MPATH_IS_VALID;
+	if (info && (r == MPATH_IS_VALID || r == MPATH_IS_MAYBE_VALID))
+		strlcpy(info->wwid, pp->wwid, 128);
+	free_path(pp);
+out_config:
+	free_config(conf);
+out_udev:
+	udev_unref(udev);
+out:
+	return r;
+}
libmpathvalid/mpath_valid.h new file +7 -0
new file mode 100644
index 00000000..b9e420a8
@@ -0,0 +1,53 @@
+/*
+ * 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
+ * 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/>;.
+ */

libmpathvalid/mpath_valid.h new file +28 -0
+
+#ifndef LIB_MPATH_VALID_H
+#define LIB_MPATH_VALID_H
+
+#ifdef __cpluscplus
+extern "C" {
+#endif
+
+enum mpath_valid_mode {
+	MPATH_DEFAULT,
+	MPATH_STRICT,
+	MPATH_SMART,
+	MPATH_GREEDY,
+	MPATH_MAX_MODE,  /* used only for bounds checking */
+};
+
+enum mpath_valid_result {
+	MPATH_IS_ERROR = -1,
+	MPATH_IS_NOT_VALID,
+	MPATH_IS_VALID,
+	MPATH_IS_MAYBE_VALID,
+};
+
+struct mpath_info {
+	char wwid[128];
+};
+
+int mpath_is_path(const char *name, unsigned int mode, struct

mpath_info *info);

libmpathvalid/mpath_valid.h new file +7 -0
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* LIB_PATH_VALID_H */
+
libmultipath/Makefile +1 -0
index ad690a49..7e2c00cf 100644
@@ -69,6 +69,7 @@ nvme-ioctl.h: nvme/nvme-ioctl.h
 
 $(LIBS): $(OBJS)
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS)
 $(LIBDEPS)
+	ar rcs libmultipath_nonshared.a $(OBJS)
 	$(LN) $@ $(DEVLIB)
 

install:

libmultipath/devmapper.c +0 -0
index 7ed494a1..27d4f61f 100644
@@ -770,6 +770,55 @@ out:
 	return r;

libmultipath/devmapper.c out: · line 780

Quoted 10 lines
libmultipath/devmapper.c +8 -0
 }
 
+/*
+ * Return
+ *   1 : map with uuid exists
+ *   0 : map with uuid doesn't exist
+ *  -1 : error
+ */
+int
+dm_is_mpath_uuid(const char *uuid)

We should probably replace our current dm_map_present() implementation with something like this, checking for the UUID. The name of the function irritated me, perhaps it should be called dm_map_present_by_uuid() or so.

Regards,
Martin

Quoted 57 lines
libmultipath/devmapper.c +41 -0
+{
+	struct dm_task *dmt;
+	struct dm_info info;
+	char prefixed_uuid[WWID_SIZE + UUID_PREFIX_LEN];
+	int r = -1;
+
+	if (!uuid || uuid[0] == '\0')
+		return 0;
+
+	if (safe_sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid))
+		goto out;
+
+	if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
+		goto out;
+
+	dm_task_no_open_count(dmt);
+
+	if (!dm_task_set_uuid(dmt, prefixed_uuid))
+		goto out_task;
+
+	if (!dm_task_run(dmt))
+		goto out_task;
+
+	if (!dm_task_get_info(dmt, &info))
+		goto out_task;
+
+	r = 0;
+
+	if (!info.exists)
+		goto out_task;
+
+	r = 1;
+out_task:
+	dm_task_destroy(dmt);
+out:
+	if (r < 0)
+		condlog(3, "%s: dm command failed in %s: %s", uuid,
+			__FUNCTION__, strerror(errno));
+	return r;
+}
+
 static int
 dm_dev_t (const char * mapname, char * dev_t, int len)
 {
libmultipath/devmapper.h +1 -0
index 17fc9faf..fa2513c2 100644
@@ -43,6 +43,7 @@ int dm_get_map(const char *, unsigned long long *,
 char *);
 int dm_get_status(const char *, char *);
 int dm_type(const char *, char *);
 int dm_is_mpath(const char *);
+int dm_is_mpath_uuid(const char *uuid);
 int _dm_flush_map (const char *, int, int, int, int);
 int dm_flush_map_nopaths(const char * mapname, int deferred_remove);

#define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0, 0, 0)

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
#8 lore raw

Re: [RFC Patch 3/3] multipath: add libmpathvalid library

Quoted 23 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski

This library allows other programs to check if a path should be claimed
by multipath. Currently, it only includes one function, mpath_is_path(), which takes a device name, mode to for checking the path, and an optional info structure, to return the wwid. The modes work
mostly like they do for "multipath -c/-u", with a few exceptions.

1. If a device is currently multipathed, it is always VALID. This perhaps should be true for the existing path valid code.

AFAICS, this is already the case, except if:

1 WWID_IS_FAILED is set, i.e. dm_addmap() failed to set up
the multipath with this WWID last time we tried. In this case it's unlikely that the path is currently multipathed. But there may be some corner case in which your new code would return "valid" while the current code would not; possibly if someone set up a multipath device with "dmsetup" directly, or because of some race condition. I just realized that we don't check for -EBUSY when we create a map...

Quoted 8 lines

I agree that perhaps the "is_multipath" test should be done before the "failed" test in multipath -u, too.

2 ignore_wwids is off, and check_wwids_file returned a negative
result. IMO this logic is correct. But you are the inventor of the wwids file, so fine with me to change it.

And also if multipathd is neither running nor enabled, but see below.

See below for my thoughts on its placement

Quoted 12 lines
Quoted 11 lines

2. There is no seperate "on" mode. It is instead treated like "smart".
This is because the library only looks at a single path, so it can only
say that a device could be multpathed, if there was another path. It is
the caller's job to check if another path exists, or to wait for another
path appear.

Quoted 6 lines

I'm not sure if I like this. Returning "no" for the first path and "yes" for the second and later paths is exactly how "find_multipaths=yes" is supposed to behave. If that's not useful for an application, the application should choose a different mode; and that's what I believe SID should do (assuming that SID will be the main / only user of this API for some time).

SID just wants to be able to look at one path at a time. It will be storing the information from previous path runs, so it will be able to check if there are other paths with that wwid. I really don't want to run coalesce_paths in the library, to search repeatedly for all the paths. It's completely unnecessary, since the information will have already been gotten by previous calls to the library.

To deal with SID, I could have the function take an array of path_info structures holding all the known wwids. This would allow the function to return "No" for the first path in the "find_multipaths=yes" case. However, this would make the library worse for use by "multipath -u", since multipath would have to gather the existing path wwids before it knew if it needed them.

Assuming we are moving the main part of this into libmultipath, I could make that run in two modes. One would be like it currently works and not require the array of wwids, which would be for the "multipath -u" code. The other would require the array, and that would be what libmpathvalid used. Perhaps something as simply as passing -1 for the array length could mean make no assumptions about other paths, and return "maybe", if this path needs a second path in order to be claimed. Then the "multipath -u" could run coalesce_paths() later, if necessary.

Quoted 33 lines
Quoted 3 lines

3. The library does check if there already is an existing multipath device with the same wwid, and if so, will declare the path valid.

What if there are other paths, not multipathed (yet) but with the same wwid as the path in question? The current code checks that by calling coalesce_paths() in "dry-run" mode, which would cover both this case and your case 3.

Quoted 13 lines

In order to act more library-like, libmpathvalid doesn't set its own device-mapper log functions. It leaves this to the caller. It currently
keeps condlog() from printing anything, but should eventually include a
function to allow the caller set the logging. It also uses a statically
compiled version of libmultipath, both to keep that library from polluting the namespace of the caller, and to avoid the caller needing
to set up the variables and functions (like logsink, and get_multipath_config) that it expects.

All fair, but I'd prefer a solution where we use as much common code as possible, to avoid bit rot of either code path in the future. Your new function has the advantage to be much better readable than the current code in multipath/main.c. Maybe we can find a way to use it from "multipath -u"? The mentioned semantic changes are minor and could be resolved (not sure about the coalesce_paths() call, I guess you had a reason to skip it).

Quoted 8 lines

The namespace issue could be fixed by using "-fvisibility=hidden" and using explicit visibility attributes for those functions we want to export. The logsink and get_multipath_config issues should be solvable by using a sane default implementation and allowing applications to change it.

Both would be improvements for libmultipath that we should have made long ago.

Having libmultipath store logsink and get_multipath_config, and making getter and setter functions would be great. But I'm worried that making that change might mess with current users of libmpathpersist.

There are still a number of functions that multipath, multipathd, and libmpathpersist need from libmultipath, that libmpathvalid doesn't, but -fvisibility=hidden would fix a large part of my dislike with the namesapce polution. I'm still not crazy about telling people to link against a library with a number of exposed, undocumented functions, but we already been doing it for a while with libmpathpersist.

Quoted 212 lines
Quoted 212 lines
---
 Makefile                            |   1 +
 Makefile.inc                        |   1 +
 libmpathvalid/Makefile              |  38 +++++++
 libmpathvalid/libmpathvalid.version |   6 +
 libmpathvalid/mpath_valid.c         | 171
++++++++++++++++++++++++++++
 libmpathvalid/mpath_valid.h         |  53 +++++++++
 libmultipath/Makefile               |   1 +
 libmultipath/devmapper.c            |  49 ++++++++
 libmultipath/devmapper.h            |   1 +
 9 files changed, 321 insertions(+)
 create mode 100644 libmpathvalid/Makefile
 create mode 100644 libmpathvalid/libmpathvalid.version
 create mode 100644 libmpathvalid/mpath_valid.c
 create mode 100644 libmpathvalid/mpath_valid.h
Makefile +1 -0
index 1dee3680..462d6655 100644
@@ -9,6 +9,7 @@ BUILDDIRS := \
 	libmultipath/checkers \
 	libmultipath/foreign \
 	libmpathpersist \
+	libmpathvalid \
 	multipath \
 	multipathd \
 	mpathpersist \
Makefile.inc +1 -0
index d4d1e0dd..7e0e8203 100644
@@ -66,6 +66,7 @@ libdir		= $(prefix)/$(LIB)/multipath
 unitdir		= $(prefix)/$(SYSTEMDPATH)/systemd/system
 mpathpersistdir	= $(TOPDIR)/libmpathpersist
 mpathcmddir	= $(TOPDIR)/libmpathcmd
+mpathvaliddir	= $(TOPDIR)/libmpathvalid
 thirdpartydir	= $(TOPDIR)/third-party
 libdmmpdir	= $(TOPDIR)/libdmmp
 nvmedir		= $(TOPDIR)/libmultipath/nvme
libmpathvalid/Makefile new file +17 -0
new file mode 100644
index 00000000..5fc97022
@@ -0,0 +1,38 @@
+include ../Makefile.inc
+
+SONAME = 0
+DEVLIB = libmpathvalid.so
+LIBS = $(DEVLIB).$(SONAME)
+
+CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+
+LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
+	   -lmultipath_nonshared -L$(mpathcmddir) -lmpathcmd -ludev
+
+OBJS = mpath_valid.o
+
+all: $(LIBS)
+
+$(LIBS): $(OBJS)
+	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS)

$(LIBDEPS) -Wl,--version-script=libmpathvalid.version

libmpathvalid/Makefile new file +5 -0
+	$(LN) $(LIBS) $(DEVLIB)
+
+install: $(LIBS)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(syslibdir)
+	$(INSTALL_PROGRAM) -m 755 $(LIBS)

$(DESTDIR)$(syslibdir)/$(LIBS)

libmpathvalid/Makefile new file +16 -0
+	$(LN) $(LIBS) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(includedir)
+	$(INSTALL_PROGRAM) -m 644 mpath_valid.h $(DESTDIR)$(includedir)
+
+uninstall:
+	$(RM) $(DESTDIR)$(syslibdir)/$(LIBS)
+	$(RM) $(DESTDIR)$(syslibdir)/$(DEVLIB)
+	$(RM) $(DESTDIR)$(includedir)/mpath_valid.h
+
+clean: dep_clean
+	$(RM) core *.a *.o *.so *.so.* *.gz
+
+include $(wildcard $(OBJS:.o=.d))
+
+dep_clean:
+	$(RM) $(OBJS:.o=.d)
libmpathvalid/libmpathvalid.version new file +6 -0
new file mode 100644
index 00000000..e8967951
@@ -0,0 +1,6 @@
+MPATH_1.0 {
+	global:
+		mpath_is_path;
+	local:
+		*;
+};
libmpathvalid/mpath_valid.c new file +51 -0
new file mode 100644
index 00000000..3d96c32f
@@ -0,0 +1,171 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <libdevmapper.h>
+#include <libudev.h>
+#include <errno.h>
+
+#include "devmapper.h"
+#include "structs.h"
+#include "util.h"
+#include "config.h"
+#include "discovery.h"
+#include "wwids.h"
+#include "sysfs.h"
+#include "mpath_cmd.h"
+#include "mpath_valid.h"
+
+struct udev *udev;
+int logsink = -1;
+static struct config default_config = { .verbosity = -1 };
+static struct config *multipath_conf;
+
+struct config *get_multipath_config(void)
+{
+	return (multipath_conf)? multipath_conf : &default_config;
+}
+
+void put_multipath_config(__attribute__((unused))void *conf)
+{
+	/* Noop */
+}
+
+static int get_conf_mode(struct config *conf)
+{
+	if (conf->find_multipaths == FIND_MULTIPATHS_ON ||
+	    conf->find_multipaths == FIND_MULTIPATHS_SMART)
+		return MPATH_SMART;
+	if (conf->find_multipaths == FIND_MULTIPATHS_GREEDY)
+		return MPATH_GREEDY;
+	return MPATH_STRICT;
+}
+
+
+/*
+ * Return
+ *  2: possible path (only in MPATH_GREEDY mode)
+ *  1: mpath path
+ *  0: not mpath path
+ * -1: Failure
+ */
+int
+mpath_is_path(const char *name, unsigned int mode, struct mpath_info

*info)

libmpathvalid/mpath_valid.c new file +48 -0
+{
+	struct config *conf;
+	struct path * pp;
+	int r = MPATH_IS_ERROR;
+	int fd = -1;
+	unsigned int version[3];
+	bool already_multipathed = false;
+
+	if (info)
+		memset(info, 0, sizeof(struct mpath_info));
+
+	if (!name || mode >= MPATH_MAX_MODE)
+		return r;
+
+	skip_libmp_dm_init();
+	udev = udev_new();
+	if (!udev)
+		goto out;
+	conf = load_config(DEFAULT_CONFIGFILE);
+	if (!conf)
+		goto out_udev;
+	conf->verbosity = -1;
+	if (mode == MPATH_DEFAULT)
+		mode = get_conf_mode(conf);
+
+	if (dm_prereq(version))
+		goto out_config;
+	memcpy(conf->version, version, sizeof(version));
+	multipath_conf = conf;
+
+	pp = alloc_path();
+	if (!pp)
+		goto out_config;
+
+	if (safe_sprintf(pp->dev, "%s", name))
+		goto out_path;
+
+	if (sysfs_is_multipathed(pp, true)) {
+		if (!info || pp->wwid[0] != '\0') {
+			r = MPATH_IS_VALID;
+			goto out_path;
+		}
+		already_multipathed = true;
+	}
+
+	fd = __mpath_connect(1);
+	if (fd < 0) {
+		if (errno != EAGAIN && !systemd_service_enabled(name))

{

libmpathvalid/mpath_valid.c new file +2 -0
+			r = MPATH_IS_NOT_VALID;
+			goto out_path;
Quoted 8 lines

libmpathvalid/mpath_valid.c line 104

Quoted 3 lines
libmpathvalid/mpath_valid.c new file +3 -0
+		}
+	} else
+		mpath_disconnect(fd);

So "multipathd not running" takes precedence over "is already multipathed"? That contradicts your statement 1. above. Would SID (or any other external application using your API) really require multipathd?

I've waffled on this. SID will require multipathd, but if a device actually is part of a multipath device, then the reality of the situation is that it has been claimed by multipath, and there will be things that won't be able to use it. For instance, LVM will not be able to be set up on a partition, and filesystems won't mount. So, should the code return "not a multipath path" for a device that IS a multipath path, just because it shouldn't be, especially when there is nothing that is going to un-multipath it.

I think that the best answer is to report that the path has been, in fact, claimed by multipath, even if we don't know why, or think it shouldn't be. But this is a corner case, and I'm open to being convinced otherwise.

Quoted 153 lines
Quoted 153 lines
libmpathvalid/mpath_valid.c new file +2 -0
+
+	pp->udev = udev_device_new_from_subsystem_sysname(udev,

"block", name);

libmpathvalid/mpath_valid.c new file +65 -0
+	if (!pp->udev)
+		goto out_path;
+
+	r = pathinfo(pp, conf, DI_SYSFS | DI_WWID | DI_BLACKLIST);
+	if (r) {
+		if (r == PATHINFO_SKIPPED)
+			r = MPATH_IS_NOT_VALID;
+		else
+			r = MPATH_IS_ERROR;
+		goto out_path;
+	}
+
+	if (pp->wwid[0] == '\0') {
+		r = MPATH_IS_NOT_VALID;
+		goto out_path;
+	}
+
+	if (already_multipathed)
+		goto out_path;
+
+	if (dm_is_mpath_uuid(pp->wwid) == 1) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	r = is_failed_wwid(pp->wwid);
+	if (r != WWID_IS_NOT_FAILED) {
+		if (r == WWID_IS_FAILED)
+			r = MPATH_IS_NOT_VALID;
+		else
+			r = MPATH_IS_ERROR;
+		goto out_path;
+	}
+
+	if (mode == MPATH_GREEDY) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	if (check_wwids_file(pp->wwid, 0) == 0) {
+		r = MPATH_IS_VALID;
+		goto out_path;
+	}
+
+	if (mode == MPATH_STRICT) {
+		r = MPATH_IS_NOT_VALID;
+		goto out_path;
+	}
+
+	/* mode == SMART */
+	r = MPATH_IS_MAYBE_VALID;
+
+out_path:
+	if (already_multipathed)
+		r = MPATH_IS_VALID;
+	if (info && (r == MPATH_IS_VALID || r == MPATH_IS_MAYBE_VALID))
+		strlcpy(info->wwid, pp->wwid, 128);
+	free_path(pp);
+out_config:
+	free_config(conf);
+out_udev:
+	udev_unref(udev);
+out:
+	return r;
+}
libmpathvalid/mpath_valid.h new file +7 -0
new file mode 100644
index 00000000..b9e420a8
@@ -0,0 +1,53 @@
+/*
+ * 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
+ * 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/>;.
+ */

libmpathvalid/mpath_valid.h new file +28 -0
+
+#ifndef LIB_MPATH_VALID_H
+#define LIB_MPATH_VALID_H
+
+#ifdef __cpluscplus
+extern "C" {
+#endif
+
+enum mpath_valid_mode {
+	MPATH_DEFAULT,
+	MPATH_STRICT,
+	MPATH_SMART,
+	MPATH_GREEDY,
+	MPATH_MAX_MODE,  /* used only for bounds checking */
+};
+
+enum mpath_valid_result {
+	MPATH_IS_ERROR = -1,
+	MPATH_IS_NOT_VALID,
+	MPATH_IS_VALID,
+	MPATH_IS_MAYBE_VALID,
+};
+
+struct mpath_info {
+	char wwid[128];
+};
+
+int mpath_is_path(const char *name, unsigned int mode, struct

mpath_info *info);

libmpathvalid/mpath_valid.h new file +7 -0
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* LIB_PATH_VALID_H */
+
libmultipath/Makefile +1 -0
index ad690a49..7e2c00cf 100644
@@ -69,6 +69,7 @@ nvme-ioctl.h: nvme/nvme-ioctl.h
 
 $(LIBS): $(OBJS)
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -Wl,-soname=$@ -o $@ $(OBJS)
 $(LIBDEPS)
+	ar rcs libmultipath_nonshared.a $(OBJS)
 	$(LN) $@ $(DEVLIB)
 

install:

libmultipath/devmapper.c +0 -0
index 7ed494a1..27d4f61f 100644
@@ -770,6 +770,55 @@ out:
 	return r;
 }
 
Quoted 13 lines

libmultipath/devmapper.c out: · line 780

Quoted 8 lines
libmultipath/devmapper.c +8 -0
+/*
+ * Return
+ *   1 : map with uuid exists
+ *   0 : map with uuid doesn't exist
+ *  -1 : error
+ */
+int
+dm_is_mpath_uuid(const char *uuid)

We should probably replace our current dm_map_present() implementation with something like this, checking for the UUID. The name of the function irritated me, perhaps it should be called dm_map_present_by_uuid() or so.

Sure. There is one thing that I'm conflicted about with this function, and with sysfs_is_multipathed(). They both return success if the wwid looks good. But they don't bother to check the the device target is actually a multipath type. It would add an extra libdm command to both of them to deal with an unlikely corner case, but nothing stops anyone from creating a dm device with the mpath- prefix.

Quoted 68 lines

Regards,
Martin

Quoted 57 lines
libmultipath/devmapper.c +41 -0
+{
+	struct dm_task *dmt;
+	struct dm_info info;
+	char prefixed_uuid[WWID_SIZE + UUID_PREFIX_LEN];
+	int r = -1;
+
+	if (!uuid || uuid[0] == '\0')
+		return 0;
+
+	if (safe_sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid))
+		goto out;
+
+	if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
+		goto out;
+
+	dm_task_no_open_count(dmt);
+
+	if (!dm_task_set_uuid(dmt, prefixed_uuid))
+		goto out_task;
+
+	if (!dm_task_run(dmt))
+		goto out_task;
+
+	if (!dm_task_get_info(dmt, &info))
+		goto out_task;
+
+	r = 0;
+
+	if (!info.exists)
+		goto out_task;
+
+	r = 1;
+out_task:
+	dm_task_destroy(dmt);
+out:
+	if (r < 0)
+		condlog(3, "%s: dm command failed in %s: %s", uuid,
+			__FUNCTION__, strerror(errno));
+	return r;
+}
+
 static int
 dm_dev_t (const char * mapname, char * dev_t, int len)
 {
libmultipath/devmapper.h +1 -0
index 17fc9faf..fa2513c2 100644
@@ -43,6 +43,7 @@ int dm_get_map(const char *, unsigned long long *,
 char *);
 int dm_get_status(const char *, char *);
 int dm_type(const char *, char *);
 int dm_is_mpath(const char *);
+int dm_is_mpath_uuid(const char *uuid);
 int _dm_flush_map (const char *, int, int, int, int);
 int dm_flush_map_nopaths(const char * mapname, int deferred_remove);

#define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0, 0, 0)

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
#9 lore raw

Re: [RFC Patch 3/3] multipath: add libmpathvalid library

Hi Ben,

Quoted 64 lines · Benjamin Marzinski
Quoted 33 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski

This library allows other programs to check if a path should be claimed
by multipath. Currently, it only includes one function, mpath_is_path(), which takes a device name, mode to for checking the
path, and an optional info structure, to return the wwid. The modes
work
mostly like they do for "multipath -c/-u", with a few exceptions.

Quoted 2 lines

1. If a device is currently multipathed, it is always VALID. This perhaps should be true for the existing path valid code.

AFAICS, this is already the case, except if:

1 WWID_IS_FAILED is set, i.e. dm_addmap() failed to set up
the multipath with this WWID last time we tried. In this case
it's
unlikely that the path is currently multipathed. But there may
be
some corner case in which your new code would return "valid" while the current code would not; possibly if someone set up a multipath device with "dmsetup" directly, or because of some
race
condition. I just realized that we don't check for -EBUSY when
we
create a map...

I agree that perhaps the "is_multipath" test should be done
before
the "failed" test in multipath -u, too.

Quoted 6 lines

2 ignore_wwids is off, and check_wwids_file returned a negative
result. IMO this logic is correct. But you are the inventor of the wwids file, so fine with me to change it.

And also if multipathd is neither running nor enabled, but see below.

See below for my thoughts on its placement

Quoted 12 lines
Quoted 11 lines

2. There is no seperate "on" mode. It is instead treated like "smart".
This is because the library only looks at a single path, so it can
only
say that a device could be multpathed, if there was another path. It
is
the caller's job to check if another path exists, or to wait for another
path appear.

Quoted 8 lines

I'm not sure if I like this. Returning "no" for the first path and "yes" for the second and later paths is exactly how "find_multipaths=yes" is supposed to behave. If that's not useful for
an application, the application should choose a different mode; and that's what I believe SID should do (assuming that SID will be the main
/ only user of this API for some time).

Quoted 4 lines

SID just wants to be able to look at one path at a time. It will be storing the information from previous path runs, so it will be able to
check if there are other paths with that wwid.

That's not an argument against returning "false" for the first path (find_multipaths=on). If that's not appropriate for SID, and it depends on "smart" behavior instead, it could just pass mode=MPATH_SMART to mpath_is_path(), could it not?

Quoted 2 lines
Quoted 1 line

I really don't want to

run coalesce_paths in the library,

Sorry, I wrote nonsense. Of course "multipath -u" does not call coalesce_paths(). It just calls path_discovery() and filter_pathvec(), which has basically the same effect as building up a vector of WWIDs.

multipath -u currently does one more thing, the open(O_RDONLY|O_EXCL) test. I recall we had some controversy about that initially, but it doesn't seem to have hurt.

Quoted 3 lines

to search repeatedly for all the
paths. It's completely unnecessary, since the information will have already been gotten by previous calls to the library.

But IIUC this means that for the 2nd path of a given WWID, mpath_is_path() will still return false, because the first path will not be multipathed (yet) when the second one appears and is checked by udev rules. This would happen both if multipathd was not running, and if multipathd was in "find_multipaths=on" or "smart" mode. Even for path 3 and beyond, the functionality depends on multipathd running and doing the right thing.

So I gather that SID will rely only partially on this function. By comparing the path WWID with WWIDs in its stores, it could conclude that a given device was a multipath path, even if mpath_is_path() returned false. Correct?

This bears the risk that the logic of multipathd and SID could diverge. It took us a lot of effort to fix the issues arising from different interpretation of path status between multipathd and multipath -u, and I'd recommend not to resuscitate that beast.

For example, if mpath_is_path() returns false, but SID finds more than one path with the given WWID, how would SID know whether was just a case of "second path always false", or the WWID was blacklisted or failed? Perhaps mpath_is_path() should provide different return codes for different reject reasons?

Thinking about it, the safest bet might be to invent a multipathd cli command for this functionality, and ask multipathd about it's own judgement about the device's status. We don't do that in udev rules in order not to depend on multipathd too much, but for SID it might be an option, if it depends on multipathd anyway.

Quoted 9 lines

To deal with SID, I could have the function take an array of path_info
structures holding all the known wwids. This would allow the function to
return "No" for the first path in the "find_multipaths=yes" case. However, this would make the library worse for use by "multipath -u", since multipath would have to gather the existing path wwids before it
knew if it needed them.

The function could gather this information itself in case it needs it. Which is what "multipath -u" does, by calling path_discovery() and filter_pathvec(). You could pass an optional pathvec argument, and have mpath_is_path() call path_discovery() only if that pathvec was NULL / empty.

Quoted 5 lines

Assuming we are moving the main part of this into libmultipath, I could
make that run in two modes. One would be like it currently works and not
require the array of wwids, which would be for the "multipath -u"

Quoted 9 lines

code.
The other would require the array, and that would be what libmpathvalid
used. Perhaps something as simply as passing -1 for the array length could mean make no assumptions about other paths, and return "maybe", if
this path needs a second path in order to be claimed. Then the "multipath -u" could run coalesce_paths() later, if necessary.

See above.

Quoted 59 lines
Quoted 49 lines
Quoted 4 lines

3. The library does check if there already is an existing multipath
device with the same wwid, and if so, will declare the path valid.

What if there are other paths, not multipathed (yet) but with the same
wwid as the path in question? The current code checks that by calling
coalesce_paths() in "dry-run" mode, which would cover both this case
and your case 3.

Quoted 6 lines

In order to act more library-like, libmpathvalid doesn't set its own
device-mapper log functions. It leaves this to the caller. It currently
keeps condlog() from printing anything, but should eventually include

Quoted 8 lines

a
function to allow the caller set the logging. It also uses a statically
compiled version of libmultipath, both to keep that library from polluting the namespace of the caller, and to avoid the caller needing
to set up the variables and functions (like logsink, and get_multipath_config) that it expects.

All fair, but I'd prefer a solution where we use as much common code
as possible, to avoid bit rot of either code path in the future. Your
new function has the advantage to be much better readable than the current code in multipath/main.c. Maybe we can find a way to use it from "multipath -u"? The mentioned semantic changes are minor and could
be resolved (not sure about the coalesce_paths() call, I guess you had
a reason to skip it).

The namespace issue could be fixed by using "-fvisibility=hidden" and using explicit visibility attributes for those functions we want to export. The logsink and get_multipath_config
issues should be solvable by using a sane default implementation and
allowing applications to change it.

Quoted 3 lines

Both would be improvements for libmultipath that we should have made
long ago.

Having libmultipath store logsink and get_multipath_config, and making
getter and setter functions would be great. But I'm worried that making
that change might mess with current users of libmpathpersist.

Quoted 8 lines

There are still a number of functions that multipath, multipathd, and libmpathpersist need from libmultipath, that libmpathvalid doesn't, but
-fvisibility=hidden would fix a large part of my dislike with the namesapce polution. I'm still not crazy about telling people to link against a library with a number of exposed, undocumented functions, but
we already been doing it for a while with libmpathpersist.

Hm, yes I think libmpathpersist uses quite a bit of libmultipath. And well, multipath and libmultipath use essentially every symbol. So right, a simplistic -fvisibility=hidden won't work.

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

Re: [RFC Patch 3/3] multipath: add libmpathvalid library

Quoted 72 lines · Martin Wilck

Hi Ben,

Quoted 64 lines · Benjamin Marzinski
Quoted 33 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski

This library allows other programs to check if a path should be claimed
by multipath. Currently, it only includes one function, mpath_is_path(), which takes a device name, mode to for checking the
path, and an optional info structure, to return the wwid. The modes
work
mostly like they do for "multipath -c/-u", with a few exceptions.

Quoted 2 lines

1. If a device is currently multipathed, it is always VALID. This perhaps should be true for the existing path valid code.

AFAICS, this is already the case, except if:

1 WWID_IS_FAILED is set, i.e. dm_addmap() failed to set up
the multipath with this WWID last time we tried. In this case
it's
unlikely that the path is currently multipathed. But there may
be
some corner case in which your new code would return "valid" while the current code would not; possibly if someone set up a multipath device with "dmsetup" directly, or because of some
race
condition. I just realized that we don't check for -EBUSY when
we
create a map...

I agree that perhaps the "is_multipath" test should be done
before
the "failed" test in multipath -u, too.

Quoted 6 lines

2 ignore_wwids is off, and check_wwids_file returned a negative
result. IMO this logic is correct. But you are the inventor of the wwids file, so fine with me to change it.

And also if multipathd is neither running nor enabled, but see below.

See below for my thoughts on its placement

Quoted 12 lines
Quoted 11 lines

2. There is no seperate "on" mode. It is instead treated like "smart".
This is because the library only looks at a single path, so it can
only
say that a device could be multpathed, if there was another path. It
is
the caller's job to check if another path exists, or to wait for another
path appear.

Quoted 8 lines

I'm not sure if I like this. Returning "no" for the first path and "yes" for the second and later paths is exactly how "find_multipaths=yes" is supposed to behave. If that's not useful for
an application, the application should choose a different mode; and that's what I believe SID should do (assuming that SID will be the main
/ only user of this API for some time).

Quoted 4 lines

SID just wants to be able to look at one path at a time. It will be storing the information from previous path runs, so it will be able to
check if there are other paths with that wwid.

Quoted 4 lines

That's not an argument against returning "false" for the first path (find_multipaths=on). If that's not appropriate for SID, and it depends on "smart" behavior instead, it could just pass mode=MPATH_SMART to mpath_is_path(), could it not?

SID could very well do that. What not returning "maybe" in this case really does is make it harder use this code for "multipath -u". multipath needs to know when it should search for other paths. It doesn't want to do so before calling mpath_is_path() (or the cut down libmultipath part). It wants to know that if other paths with the same wwid exist, then this path would be valid.

But just looking at the SID case, I don't see the problem. Say SID passed down an array of known wwids, and this paths wwid wasn't on the list. SID needs to know if it should save this WWID for checking against future paths, so there should be a special return code for this. That is exactly what "maybe" means in the SMART case. My v2 code makes is easy for SID to see what the configured mode is. In this case, it could set the delay if multipathd was configured as SMART, and not if it was configured as FIND. In reality, SID will probably treat SMART and FIND the same way. It will eventually have a persistent database, so it can remember between boots if it has seen a device before. When that happens it will probably always treat FIND like SMART. Before that happens, it will probably treat SMART like FIND. So, I'm not totally aginst removing the maybe, but it can see how that doing so will make the code simpler for any user of this library (either SID or multipath -u)

Quoted 10 lines
Quoted 2 lines
Quoted 1 line

I really don't want to

run coalesce_paths in the library,

Sorry, I wrote nonsense. Of course "multipath -u" does not call coalesce_paths(). It just calls path_discovery() and filter_pathvec(), which has basically the same effect as building up a vector of WWIDs.

multipath -u currently does one more thing, the open(O_RDONLY|O_EXCL) test. I recall we had some controversy about that initially, but it doesn't seem to have hurt.

SID's job is to replace all the udev hacks to get devices to be claimed and set up, with a stateful daemon that had modules for each device type, written in C. It's job is specifically to know what is using which device. So these checks were left out intentionally. See below for more explanation.

Quoted 12 lines
Quoted 3 lines

to search repeatedly for all the
paths. It's completely unnecessary, since the information will have already been gotten by previous calls to the library.

But IIUC this means that for the 2nd path of a given WWID, mpath_is_path() will still return false, because the first path will not be multipathed (yet) when the second one appears and is checked by udev rules. This would happen both if multipathd was not running, and if multipathd was in "find_multipaths=on" or "smart" mode. Even for path 3 and beyond, the functionality depends on multipathd running and doing the right thing.

Quoted 4 lines

So I gather that SID will rely only partially on this function. By comparing the path WWID with WWIDs in its stores, it could conclude that a given device was a multipath path, even if mpath_is_path() returned false. Correct?

yes. SID will have a multipath module that calls this library. That will live in the SID project, but they will clearly take patches from multipath developers.

Quoted 4 lines

This bears the risk that the logic of multipathd and SID could diverge. It took us a lot of effort to fix the issues arising from different interpretation of path status between multipathd and multipath -u, and I'd recommend not to resuscitate that beast.

You have to elaborate on this risk, because I don't see it. In the v2 code there are 3 non-error states that can be returns

MPATH_IS_NOT_VALID
MPATH_IS_VALID
MPATH_IS_MAYBE_VALID

I will likely add a fourth state MPATH_IS_CLAIMED, that will only be returned when a path currently is multipathed, to differentiate it from the others, which state multipath's desire. But all SID needs to know is that MPATH_IS_NOT_VALID, means that multipath isn't claiming it now. MPATH_IS_VALID means that multipath wants to claim it now, and MPATH_IS_MAYBE_VALID means that multipath would want to claim the device if another path with the same WWID came around. I admit, SID will likely deal with SMART differently than multipath + udev currently does, but that doesn't effect how it interfaces with multipathd.

Quoted 5 lines

For example, if mpath_is_path() returns false, but SID finds more than one path with the given WWID, how would SID know whether was just a case of "second path always false", or the WWID was blacklisted or failed? Perhaps mpath_is_path() should provide different return codes for different reject reasons?

Perhaps there would be more return states necessary, but aside from MPATH_IS_CLAIMED, I don't see why another state is needed. Maybe I'm misunderstanding what you mean by "second path always false".

Quoted 5 lines

Thinking about it, the safest bet might be to invent a multipathd cli command for this functionality, and ask multipathd about it's own judgement about the device's status. We don't do that in udev rules in order not to depend on multipathd too much, but for SID it might be an option, if it depends on multipathd anyway.

The same issue exists here, where we want to be able to respond quickly. that's why I'm trying to strip even more unnecessary code out (creating a lock file just to read if multipathd failed to create the device).

Quoted 10 lines
Quoted 9 lines

To deal with SID, I could have the function take an array of path_info
structures holding all the known wwids. This would allow the function to
return "No" for the first path in the "find_multipaths=yes" case. However, this would make the library worse for use by "multipath -u", since multipath would have to gather the existing path wwids before it
knew if it needed them.

Quoted 5 lines

The function could gather this information itself in case it needs it. Which is what "multipath -u" does, by calling path_discovery() and filter_pathvec(). You could pass an optional pathvec argument, and have mpath_is_path() call path_discovery() only if that pathvec was NULL / empty.

But that's not necessary to do each time, when we can just return the data to SID, which can store it for future library calls.

I do think that we can move the meat of this library into libmultipath Here's the claiming logic for my v2 code:

If the device is currently multipathed: valid
If multipathd is not running: not valid
If the device is blacklisted: not valid
If the device does not have a wwid: not valid
If the device wwid is multipathed: valid
If the device failed to be multipathed: not valid
If the mode is GREEDY: valid
If the device wwid is in the wwids file: valid
If the mode is STRICT: not valid
If another path with the same wwid exists: valid
else: maybe valid

Here's the claiming logic for multipath -u

If multipathd is not running: not valid
If the device is blacklisted: not valid
If the device does not have a wwid: not valid
If the device failed to be multipathed: not valid
If the mode is STRICT or FIND and the device is in the wwids file: valid If the mode is STRICT or FIND and the device is not in the wwids file:
not valid
If the device is currently multipathed: valid
If the device has been released to systemd: not valid
If the mode is GREEDY: valid
If the device wwid is multipathed: valid
If the device is not in use and another path with the same wwid exists:
valid
If the device is not in use: maybe valid
else: not valid

Differences:

"If the device is currently multipathed" is now first. I think that this is correct, but I would be willing to move it down. If you get multipathd into a state where there is a multipath device with what it thinks are blacklisted paths. When uevent happen on those paths, it doesn't remove the from the device. So the claiming logic should mirror that.

"If the device has been released to systemd" doesn't exist. This is by design, but it could probably use some work. The idea is that SID (or anything calling this library) is smarter than udev. The goal of SID is to move device activation out of udev, and into a daemon that tracks what is using what device without needing udev rules. Since SID keeps track of who has claimed the device, Multipath doesn't need to try and track if something else was allowed to use the device. On the flip side, multipath should communicate its ownship a little better. So, i think it could have a new state MPATH_IS_CLAIMED. This would only be returned if the device is currently multipathed. This will make it easy for SID to know that this device really is claimed by multipath, instead of multipath simply wanting to claim it. This change is probably not necessary, since as soon as the multipath device is created, SID get a uevent for, and could match the WWID with the paths, and claim them for multipath. But it doesn't hurt anything.

"If the device wwid is multipathed" has been moved above "If the device wwid is in the wwids file". This means that STRICT will allow the path event if its not in the wwids file. I think that this is correct on the same grounds that I think "If the device is currently multipathed" should be above "If multipathd is not running". It's simply reporing the actual truth instead of the configured goal. Also, if you look at ev_add_path(), should_multpath() is only called if the multipath device doesn't exist. So this is simply matching the claiming behavior to what multipathd will actually do in this case.

"If the device wwid is multipathed" is also moved above "If the device failed to be multipathed". Again. If there is currently a multipath device with that wwid, the the failed file is simply wrong.

"If the device is not in use" doesn't exist. Again, it is SID (or the calling program's) job to know if a device is already in use.

Aside from those issues, the checks should return the same results, unless I'm overlooking something. To make this work for multipath -u we would have to accept the changes to where "If the device is currently multipathed" and "If the device wwid is multipathed" are, or move them in the library code (but like I said, I think the library placement is more correct to actual multipathd behavior than the multipath -u code is).

To deal with "If the device has been released to systemd", multipath would check this if the library returned MPATH_IS_VALID or MPATH_IS_MAYBE_VALID (but not MPATH_IS_CLAIMED). This would cause a difference for find_multipaths = on or strict. In this case, once a path had been released, it would not be claimed simply because it was in the wwids file. The path would have to be multipathed. This doesn't seem like to big of an issue, but we could always add another return state to the library, to make this work like it currently does.

To deal with "If the device is not in use", we would simply check this for "maybe" paths if find_multipaths is "smart". Since multipath wouldn't pass any wwids in, this is the case where it currently does the open O_EXCL check.

-Ben

Quoted 100 lines
Quoted 5 lines

Assuming we are moving the main part of this into libmultipath, I could
make that run in two modes. One would be like it currently works and not
require the array of wwids, which would be for the "multipath -u"

Quoted 9 lines

code.
The other would require the array, and that would be what libmpathvalid
used. Perhaps something as simply as passing -1 for the array length could mean make no assumptions about other paths, and return "maybe", if
this path needs a second path in order to be claimed. Then the "multipath -u" could run coalesce_paths() later, if necessary.

See above.

Quoted 59 lines
Quoted 49 lines
Quoted 4 lines

3. The library does check if there already is an existing multipath
device with the same wwid, and if so, will declare the path valid.

What if there are other paths, not multipathed (yet) but with the same
wwid as the path in question? The current code checks that by calling
coalesce_paths() in "dry-run" mode, which would cover both this case
and your case 3.

Quoted 6 lines

In order to act more library-like, libmpathvalid doesn't set its own
device-mapper log functions. It leaves this to the caller. It currently
keeps condlog() from printing anything, but should eventually include

Quoted 8 lines

a
function to allow the caller set the logging. It also uses a statically
compiled version of libmultipath, both to keep that library from polluting the namespace of the caller, and to avoid the caller needing
to set up the variables and functions (like logsink, and get_multipath_config) that it expects.

All fair, but I'd prefer a solution where we use as much common code
as possible, to avoid bit rot of either code path in the future. Your
new function has the advantage to be much better readable than the current code in multipath/main.c. Maybe we can find a way to use it from "multipath -u"? The mentioned semantic changes are minor and could
be resolved (not sure about the coalesce_paths() call, I guess you had
a reason to skip it).

The namespace issue could be fixed by using "-fvisibility=hidden" and using explicit visibility attributes for those functions we want to export. The logsink and get_multipath_config
issues should be solvable by using a sane default implementation and
allowing applications to change it.

Quoted 3 lines

Both would be improvements for libmultipath that we should have made
long ago.

Having libmultipath store logsink and get_multipath_config, and making
getter and setter functions would be great. But I'm worried that making
that change might mess with current users of libmpathpersist.

Quoted 8 lines

There are still a number of functions that multipath, multipathd, and libmpathpersist need from libmultipath, that libmpathvalid doesn't, but
-fvisibility=hidden would fix a large part of my dislike with the namesapce polution. I'm still not crazy about telling people to link against a library with a number of exposed, undocumented functions, but
we already been doing it for a while with libmpathpersist.

Hm, yes I think libmpathpersist uses quite a bit of libmultipath. And well, multipath and libmultipath use essentially every symbol. So right, a simplistic -fvisibility=hidden won't work.

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