add library to check if device is a valid path
Subsystems (2)
Benjamin Marzinski
maintainerv3 cover add library to check if device is a valid path
The main part of the this patchset is the first patch, which adds a new library interface to check whether devices are valid paths. This was designed for use in the Storage Instantiation Daemon (SID).
https://github.com/sid-project
The seconds patch adds unit tests for this library. The third patch adds get_uid fallback code for dasd devices. The fourth patch just changes the get_uid log level for devices configured with uid_attribute "". This is because it is currently necessary to configure multipath with
overrides {
uid_attribute ""
}
to claim multipath devices with SID (instead of using multipath.rules), since SID doesn't currently get the UID information itself, and it is called by udev before this information is added to the udev database.
changes from v1 to v2
---------------------
0001: This patch is now rebased on top of, and makes use of Martin's patches that provide a default *_multipath_config, udev, and logsink. Because of this, mpathvalid_init() now has a parameter used to set logsink. There is also a new API function, mpathvalid_reload_config().
0003: This is completely new, since Martin pointed out that adding a new config option to always use the fallback getuid code was unnecessary. It just makes a uid_attribute of "" log at normal levels.
changes from v2 to v3
---------------------
0001: rebased on top of Martin's latest patches, fixed some small bugs
and added documentation to mpath_valid.h
0002: New
0004: was 0003. Untangled the logic, at Martin's suggestion.
Benjamin Marzinski (4):
multipath: add libmpathvalid library multipath-tools tests: and unit tests for libmpathvalid
libmultipath: add uid failback for dasd devices
libmultipath: change log level for null uid_attribute
Makefile | 3 +- Makefile.inc | 1 + libmpathvalid/Makefile | 39 +++ libmpathvalid/libmpathvalid.version | 10 + libmpathvalid/mpath_valid.c | 202 ++++++++++++ libmpathvalid/mpath_valid.h | 155 +++++++++ libmultipath/defaults.h | 1 + libmultipath/discovery.c | 45 ++- libmultipath/libmultipath.version | 6 + tests/Makefile | 5 +- tests/mpathvalid.c | 467 ++++++++++++++++++++++++++++ 11 files changed, 929 insertions(+), 5 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 create mode 100644 tests/mpathvalid.c
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v3 1/4 multipath: add libmpathvalid library
This library allows other programs to check if a path should be claimed by multipath. It exports an init function, that needs to be called before and after all other library calls, an exit function, that needs to be called after all library calls, a function to reread the multipath configuration files, and two more functions.
mpath_get_mode() get the configured find_multipaths mode. mpath_is_path() returns whether the device is claimed by multipath, and optionally returns the wwid. This code works slightly different than the multipath -c/u code for SMART mode. Instead of checking all the existing paths to see if another has the same wwid, it expects the caller to pass in an array of the already known path wwids, and checks if the current path matches any of those.
The library also doesn't set up the device-mapper library. It leaves this up to the caller.
--- Makefile | 3 +- libmpathvalid/Makefile | 39 ++++++ libmpathvalid/libmpathvalid.version | 10 ++ libmpathvalid/mpath_valid.c | 202 ++++++++++++++++++++++++++++ libmpathvalid/mpath_valid.h | 155 +++++++++++++++++++++ libmultipath/libmultipath.version | 6 + 6 files changed, 414 insertions(+), 1 deletion(-) 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 +2 -1
@@ -9,6 +9,7 @@ BUILDDIRS := \ libmultipath/checkers \ libmultipath/foreign \ libmpathpersist \ + libmpathvalid \ multipath \ multipathd \ mpathpersist \
@@ -29,7 +30,7 @@ $(BUILDDIRS): $(MAKE) -C $@ libmultipath libdmmp: libmpathcmd -libmpathpersist multipath multipathd: libmultipath +libmpathpersist libmpathvalid multipath multipathd: libmultipath mpathpersist multipathd: libmpathpersist libmultipath/checkers.install \
libmpathvalid/Makefile new file +39 -0
@@ -0,0 +1,39 @@ +include ../Makefile.inc + +SONAME = 0 +DEVLIB = libmpathvalid.so +LIBS = $(DEVLIB).$(SONAME) +VERSION_SCRIPT := libmpathvalid.version + +CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) + +LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \ + -lmultipath -L$(mpathcmddir) -lmpathcmd -ludev + +OBJS = mpath_valid.o + +all: $(LIBS) + +$(LIBS): $(OBJS) $(VERSION_SCRIPT) + $(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 +10 -0
@@ -0,0 +1,10 @@ +MPATH_1.0 { + global: + mpathvalid_init; + mpathvalid_reload_config; + mpathvalid_exit; + mpathvalid_is_path; + mpathvalid_get_mode; + local: + *; +};
libmpathvalid/mpath_valid.c new file +202 -0
202 lines not on this page · raw message
libmpathvalid/mpath_valid.h new file +155 -0
155 lines not on this page · raw message
libmultipath/libmultipath.version +6 -0
@@ -264,3 +264,9 @@ LIBMULTIPATH_4.1.0 { global: libmp_verbosity; } LIBMULTIPATH_4.0.0; + +LIBMULTIPATH_4.2.0 { +global: + dm_prereq; + skip_libmp_dm_init; +} LIBMULTIPATH_4.1.0;
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v3 2/4 multipath-tools tests: and unit tests for libmpathvalid
In reply to Benjamin Marzinski--- Makefile.inc | 1 + tests/Makefile | 5 +- tests/mpathvalid.c | 467 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 tests/mpathvalid.c
Makefile.inc +1 -0
@@ -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
tests/Makefile +4 -1
@@ -13,7 +13,7 @@ CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \ LIBDEPS += -L. -L$(mpathcmddir) -lmultipath -lmpathcmd -lcmocka TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \ - alias directio valid devt + alias directio valid devt mpathvalid .SILENT: $(TESTS:%=%.o) .PRECIOUS: $(TESTS:%=%-test)
@@ -30,6 +30,7 @@ endif ifneq ($(DIO_TEST_DEV),) directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\" endif +mpathvalid-test_FLAGS := -I$(mpathvaliddir) # test-specific linker flags # XYZ-test_TESTDEPS: test libraries containing __wrap_xyz functions
@@ -55,6 +56,8 @@ alias-test_LIBDEPS := -lpthread -ldl valid-test_OBJDEPS := ../libmultipath/valid.o valid-test_LIBDEPS := -ludev -lpthread -ldl devt-test_LIBDEPS := -ludev +mpathvalid-test_LIBDEPS := -ludev -lpthread -ldl +mpathvalid-test_OBJDEPS := ../libmpathvalid/mpath_valid.o ifneq ($(DIO_TEST_DEV),) directio-test_LIBDEPS := -laio endif
tests/mpathvalid.c new file +467 -0
467 lines not on this page · raw message
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v3 3/4 libmultipath: add uid failback for dasd devices
In reply to Benjamin MarzinskiAdd failback code to get the uid for dasd devices from sysfs. Copied from dasdinfo
--- libmultipath/defaults.h | 1 + libmultipath/discovery.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-)
libmultipath/defaults.h +1 -0
@@ -8,6 +8,7 @@*/ #define DEFAULT_UID_ATTRIBUTE "ID_SERIAL"#define DEFAULT_NVME_UID_ATTRIBUTE "ID_WWN" +#define DEFAULT_DASD_UID_ATTRIBUTE "ID_UID"#define DEFAULT_UDEVDIR "/dev"#define DEFAULT_MULTIPATHDIR "/" LIB_STRING "/multipath"#define DEFAULT_SELECTOR "service-time 0"
libmultipath/discovery.c +36 -1
@@ -1957,12 +1957,44 @@ get_vpd_uid(struct path * pp)return get_vpd_sysfs (parent,0x83 , pp->wwid,WWID_SIZE ); } +/* based on code from s390-tools/dasdinfo/dasdinfo.c */ +static ssize_t dasd_get_uid (struct path *pp) +{ +struct udev_device *parent; +char value[80 ]; +char *p; +int i; + + parent =udev_device_get_parent_with_subsystem_devtype (pp->udev,"ccw" , +NULL ); +if (!parent) +return -1 ; + +if (sysfs_attr_get_value (parent,"uid" , value,80 ) <0 ) +return -1 ; + + p = value -1 ; +/* look for the 4th '.' and cut there */ +for (i =0 ; i <4 ; i++) { + p =index (p +1 ,'.' ); +if (!p) +break ; + } +if (p) + *p ='\0' ; + +return strlcpy (pp->wwid, value,WWID_SIZE ); +} +static ssize_t uid_fallback (struct path *pp,int path_state,const char **origin) {ssize_t len =-1 ; -if (pp->bus ==SYSFS_BUS_SCSI ) { +if (pp->bus ==SYSFS_BUS_CCW ) { + len =dasd_get_uid (pp); + *origin ="sysfs" ; + }else if (pp->bus ==SYSFS_BUS_SCSI ) { len =get_vpd_uid (pp); *origin ="sysfs" ;if (len <0 && path_state ==PATH_UP ) {
@@ -2010,6 +2042,9 @@ static bool has_uid_fallback(struct path *pp) !strcmp(pp->uid_attribute, ""))) || (pp->bus ==SYSFS_BUS_NVME && (!strcmp (pp->uid_attribute,DEFAULT_NVME_UID_ATTRIBUTE ) || + !strcmp (pp->uid_attribute,"" ))) || + (pp->bus ==SYSFS_BUS_CCW && + (!strcmp (pp->uid_attribute,DEFAULT_DASD_UID_ATTRIBUTE ) || !strcmp(pp->uid_attribute, "")))); }
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH v3 4/4 libmultipath: change log level for null uid_attribute
In reply to Benjamin MarzinskiIf uid_attribute is explicitly set to an empty string, multipath should log the uid at the default log level, since using the fallback code is the expected behavior.
--- libmultipath/discovery.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/discovery.c +6 -2
@@ -2084,8 +2084,11 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev, len =strlen (pp->wwid); origin ="callout" ; }else { -bool udev_available = udev && pp->uid_attribute +bool valid_uid_attr = pp->uid_attribute && *pp->uid_attribute; +bool empty_uid_attr = pp->uid_attribute + && !*pp->uid_attribute; +bool udev_available = udev && valid_uid_attr;if (udev_available) { len =get_udev_uid (pp, pp->uid_attribute, udev);
@@ -2095,7 +2098,8 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev, }if ((!udev_available || (len <=0 && allow_fallback)) &&has_uid_fallback (pp)) { - used_fallback =1 ; +if (!udev || !empty_uid_attr) + used_fallback =1 ; len =uid_fallback (pp, path_state, &origin); } }
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v3 4/4] libmultipath: change log level for null uid_attribute
Quoted 7 lines · Benjamin Marzinski
If
uid_attributeis explicitly set to an empty string, multipath should
log the uid at the default log level, since using the fallback code is
the expected behavior.Signed-off-by Benjamin Marzinski <[email protected]>
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 60 lines · Benjamin Marzinski
The main part of the this patchset is the first patch, which adds a new library interface to check whether devices are valid paths. This was designed for use in the Storage Instantiation Daemon (SID).
https://github.com/sid-project
The seconds patch adds unit tests for this library. The third patch adds
get_uidfallback code for dasd devices. The fourth patch just changes theget_uidlog level for devices configured withuid_attribute"". This
is because it is currently necessary to configure multipath withoverrides {
uid_attribute""
}to claim multipath devices with SID (instead of using multipath.rules),
since SID doesn't currently get the UID information itself, and it is called by udev before this information is added to the udev database.changes from v1 to v2
---------------------
0001: This patch is now rebased on top of, and makes use of Martin's patches that provide a default*_multipath_config, udev, and logsink. Because of this,mpathvalid_init()now has a parameter used to set logsink. There is also a new API function,mpathvalid_reload_config().0003: This is completely new, since Martin pointed out that adding a new
config option to always use the fallback getuid code was unnecessary. It
just makes auid_attributeof "" log at normal levels.changes from v2 to v3
---------------------
0001: rebased on top of Martin's latest patches, fixed some small
bugs
and added documentation tompath_valid.h
0002: New
0004: was 0003. Untangled the logic, at Martin's suggestion.Benjamin Marzinski (4):
multipath: add libmpathvalid library multipath-tools tests: and unit tests for libmpathvalid
libmultipath: add uid failback for dasd devices
libmultipath: change log level for nulluid_attributeMakefile | 3 +- Makefile.inc | 1 + libmpathvalid/Makefile | 39 +++ libmpathvalid/libmpathvalid.version | 10 + libmpathvalid/mpath_valid.c | 202 ++++++++++++ libmpathvalid/mpath_valid.h | 155 +++++++++ libmultipath/defaults.h | 1 + libmultipath/discovery.c | 45 ++- libmultipath/libmultipath.version | 6 + tests/Makefile | 5 +-
Quoted 8 lines
tests/mpathvalid.c | 467 ++++++++++++++++++++++++++++ 11 files changed, 929 insertions(+), 5 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 create mode 100644 tests/mpathvalid.c
As you probably saw, all acked. However there's a small problem with the rebase on my recent patches. They aren't all acked yet, and Xose's report about uclibc made me realize that there are more issues with uclibc in my series. I don't think this will require major changes, but e.g. on_exit() is unavailable in uclibc. I'd like to rework those.
Also, I'd wish that Christophe tags a new libmultipath version before applying the "library version" series and everything thereafter.
Martin
Signature · 11 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 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerQuoted 70 lines · Martin Wilck
Quoted 60 lines · Benjamin Marzinski
The main part of the this patchset is the first patch, which adds a new library interface to check whether devices are valid paths. This was designed for use in the Storage Instantiation Daemon (SID).
https://github.com/sid-project
The seconds patch adds unit tests for this library. The third patch adds
get_uidfallback code for dasd devices. The fourth patch just changes theget_uidlog level for devices configured withuid_attribute"". This
is because it is currently necessary to configure multipath withoverrides {
uid_attribute""
}to claim multipath devices with SID (instead of using multipath.rules),
since SID doesn't currently get the UID information itself, and it is called by udev before this information is added to the udev database.changes from v1 to v2
---------------------
0001: This patch is now rebased on top of, and makes use of Martin's patches that provide a default*_multipath_config, udev, and logsink. Because of this,mpathvalid_init()now has a parameter used to set logsink. There is also a new API function,mpathvalid_reload_config().0003: This is completely new, since Martin pointed out that adding a new
config option to always use the fallback getuid code was unnecessary. It
just makes auid_attributeof "" log at normal levels.changes from v2 to v3
---------------------
0001: rebased on top of Martin's latest patches, fixed some small
bugs
and added documentation tompath_valid.h
0002: New
0004: was 0003. Untangled the logic, at Martin's suggestion.Benjamin Marzinski (4):
multipath: add libmpathvalid library multipath-tools tests: and unit tests for libmpathvalid
libmultipath: add uid failback for dasd devices
libmultipath: change log level for nulluid_attributeMakefile | 3 +- Makefile.inc | 1 + libmpathvalid/Makefile | 39 +++ libmpathvalid/libmpathvalid.version | 10 + libmpathvalid/mpath_valid.c | 202 ++++++++++++ libmpathvalid/mpath_valid.h | 155 +++++++++ libmultipath/defaults.h | 1 + libmultipath/discovery.c | 45 ++- libmultipath/libmultipath.version | 6 + tests/Makefile | 5 +-Quoted 8 lines
tests/mpathvalid.c | 467 ++++++++++++++++++++++++++++ 11 files changed, 929 insertions(+), 5 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 create mode 100644 tests/mpathvalid.c
Quoted 8 lines
As you probably saw, all acked. However there's a small problem with the rebase on my recent patches. They aren't all acked yet, and Xose's report about uclibc made me realize that there are more issues with uclibc in my series. I don't think this will require major changes, but e.g.
on_exit()is unavailable in uclibc. I'd like to rework those.Also, I'd wish that Christophe tags a new libmultipath version before applying the "library version" series and everything thereafter.
I'll rebase it, and I'm fine with this going in after the the version bump.
-Ben
Quoted 9 lines
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
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Hi Ben:
Quoted 60 lines · Benjamin Marzinski
The main part of the this patchset is the first patch, which adds a new library interface to check whether devices are valid paths. This was designed for use in the Storage Instantiation Daemon (SID).
https://github.com/sid-project
The seconds patch adds unit tests for this library. The third patch adds
get_uidfallback code for dasd devices. The fourth patch just changes theget_uidlog level for devices configured withuid_attribute"". This
is because it is currently necessary to configure multipath withoverrides {
uid_attribute""
}to claim multipath devices with SID (instead of using multipath.rules),
since SID doesn't currently get the UID information itself, and it is called by udev before this information is added to the udev database.changes from v1 to v2
---------------------
0001: This patch is now rebased on top of, and makes use of Martin's patches that provide a default*_multipath_config, udev, and logsink. Because of this,mpathvalid_init()now has a parameter used to set logsink. There is also a new API function,mpathvalid_reload_config().0003: This is completely new, since Martin pointed out that adding a new
config option to always use the fallback getuid code was unnecessary. It
just makes auid_attributeof "" log at normal levels.changes from v2 to v3
---------------------
0001: rebased on top of Martin's latest patches, fixed some small
bugs
and added documentation tompath_valid.h
0002: New
0004: was 0003. Untangled the logic, at Martin's suggestion.Benjamin Marzinski (4):
multipath: add libmpathvalid library multipath-tools tests: and unit tests for libmpathvalid
libmultipath: add uid failback for dasd devices
libmultipath: change log level for nulluid_attributeMakefile | 3 +- Makefile.inc | 1 + libmpathvalid/Makefile | 39 +++ libmpathvalid/libmpathvalid.version | 10 + libmpathvalid/mpath_valid.c | 202 ++++++++++++ libmpathvalid/mpath_valid.h | 155 +++++++++ libmultipath/defaults.h | 1 + libmultipath/discovery.c | 45 ++- libmultipath/libmultipath.version | 6 + tests/Makefile | 5 +-
Quoted 9 lines
tests/mpathvalid.c | 467 ++++++++++++++++++++++++++++ 11 files changed, 929 insertions(+), 5 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 create mode 100644 tests/mpathvalid.c
For the set:
I have created a new branch
https://github.com/openSUSE/multipath-tools/tree/upstream-tip
where this is series applied on my recently posted series "libmultipath: improve cleanup on exit" (v3), in the hope that it will pass review, too. It has to be this way around because your set requires libmp_verbosity.
As soon as my series is finalized, this will be pushed to upstream- queue.
Regards,
Martin
Signature · 11 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 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel