multipath-tools: uevent processing fixes and unit tests
Subsystems (2)
cover multipath-tools: uevent processing fixes and unit tests
Hi Christophe,
The incentive for creating this series was Ritika's patch "multipath-tools:
Skip CHANGE uevent for non-mpath devices" from October 2017, plus the observation that uevent.c contains a lot of code repetition. I've refactored and simplified the uevent_get_XXX code, and started to use "const" qualifiers in the part of the code which I touched in the process.
In order to avoid regressions in the process, I took this as a starting point for implementing a simple unit test framework. For now, it covers only the stuff that I changed in this series.
The series is based on my previous patch series ("Various multipath-tools fixes"), v2. The first patch doesn't belong in the series logically, but I thought it may help you track the ordering if I include it here rather then posting separately or spamming the list with the big series again.
Regards,
Martin
Martin Wilck (7):
assemble_map: no newline at end of params string
tests: cmocka-based unit test for uevent_get_XXX
libmultipath: refactor uevent_get_XXX
libmultipath: const qualifier for wwid and alias
libmultipath: move UUID_PREFIX to devmapper.h
libmultipath: add uevent_is_mpath
multipathd: ignore uevents for non-mpath devices
.gitignore | 3 + Makefile | 4 + libmultipath/devmapper.c | 3 - libmultipath/devmapper.h | 3 + libmultipath/discovery.c | 2 +- libmultipath/discovery.h | 2 +- libmultipath/dmparser.c | 1 - libmultipath/memory.h | 2 +- libmultipath/structs.c | 4 +- libmultipath/structs.h | 4 +- libmultipath/structs_vec.c | 2 +- libmultipath/structs_vec.h | 2 +- libmultipath/uevent.c | 183 +++++++++++++-------------- libmultipath/uevent.h | 15 +-- multipathd/main.c | 10 +- multipathd/main.h | 2 +- tests/Makefile | 23 ++++ tests/globals.c | 17 +++ tests/uevent.c | 304 +++++++++++++++++++++++++++++++++++++++++++++ 19 files changed, 462 insertions(+), 124 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/globals.c create mode 100644 tests/uevent.c
Signature · 1 line
2.15.1
PATCH 1/7 assemble_map: no newline at end of params string
This newline is superfluous for device-mapper, and causes ugly debug output.
--- libmultipath/dmparser.c | 1 - 1 file changed, 1 deletion(-)
libmultipath/dmparser.c +0 -1
@@ -114,7 +114,6 @@ assemble_map (struct multipath * mp, char * params, int len)APPEND (p, end," %s %d" , pp->dev_t, tmp_minio); } } -APPEND (p, end,"\n" );FREE (f);condlog (3 ,"%s: assembled map [%s]" , mp->alias, params);
Signature · 1 line
2.15.1
PATCH 2/7 tests: cmocka-based unit test for uevent_get_XXX
In reply to Martin WilckThis patch starts a simple unit test framework for multipath-tools based on the cmocka framework (https://cmocka.org/). As a start, it adds unit tests for the uevent_get_XXX set of functions.
Note that some tests currently fail. This will be fixed by the following patches.
--- .gitignore | 3 + Makefile | 4 + tests/Makefile | 23 ++++++ tests/globals.c | 17 ++++ tests/uevent.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 288 insertions(+) create mode 100644 tests/Makefile create mode 100644 tests/globals.c create mode 100644 tests/uevent.c
.gitignore +3 -0
@@ -18,3 +18,6 @@ libdmmp/docs/man/*.3.gz libdmmp/*.so.* libdmmp/test/libdmmp_test libdmmp/test/libdmmp_speed_test +tests/*-test +tests/*.out +
Makefile +4 -0
@@ -27,6 +27,7 @@ recurse_clean: @for dir in $(BUILDDIRS); do \ $(MAKE) -C $$dir clean || exit $?; \ done + $(MAKE) -C tests clean recurse_install: @for dir in $(BUILDDIRS); do \
@@ -44,6 +45,9 @@ install: recurse_install uninstall: recurse_uninstall +test: all + $(MAKE) -C tests + .PHONY: TAGS TAGS: etags -a libmultipath/*.c
tests/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +include ../Makefile.inc + +CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) +LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka + +TESTS := uevent + +.SILENT: $(TESTS:%=%.o) +.PRECIOUS: $(TESTS:%=%-test) + +%-test: %.o globals.c $(multipathdir)/libmultipath.so + @$(CC) -o $@ $< $(LDFLAGS) $(LIBDEPS) + +%.out: %-test + @echo == running $< == + @LD_LIBRARY_PATH=$(multipathdir):$(mpathcmddir) ./$< >$@ + +all: $(TESTS:%=%.out) + +clean: + rm -f $(TESTS:%=%-test) $(TESTS:%=%.out) $(TESTS:%=%.o) + +
tests/globals.c new file +17 -0
@@ -0,0 +1,17 @@ +#include "structs.h" +#include "config.h" + +/* Required globals */ +struct udev *udev; +int logsink =0 ; +struct config conf = { + .uid_attrs ="sd:ID_BOGUS" , +}; + +struct config *get_multipath_config (void ) +{ +return &conf; +} + +void put_multipath_config (struct config * c) +{}
tests/uevent.c new file +241 -0
241 lines not on this page · raw message
Signature · 1 line
2.15.1
PATCH 3/7 libmultipath: refactor uevent_get_XXX
In reply to Martin WilckUse common helper functions for uevent_get_XXX.
--- libmultipath/uevent.c | 159 +++++++++++++++++++++----------------------------- 1 file changed, 67 insertions(+), 92 deletions(-)
libmultipath/uevent.c +67 -92
@@ -104,28 +104,69 @@ uevq_cleanup(struct list_head *tmpq) } } +static const char *uevent_get_env_var (const struct uevent *uev, +const char *attr) +{ +int i, len; +const char *p =NULL ; + +if (attr ==NULL ) + goto invalid; + + len =strlen (attr); +if (len ==0 ) + goto invalid; + +for (i =0 ; uev->envp[i] !=NULL ; i++) { +const char *var = uev->envp[i]; + +if (strlen (var) > len && + !memcmp (var, attr, len) && var[len] =='=' ) { + p = var + len +1 ; +break ; + } + } + +condlog (4 ,"%s: %s -> '%s'" , __func__, attr, p); +return p; + +invalid: +condlog (2 ,"%s: empty variable name" , __func__); +return NULL ; +} + +static int uevent_get_env_positive_int (const struct uevent *uev, +const char *attr) +{ +const char *p =uevent_get_env_var (uev, attr); +char *q; +int ret; + +if (p ==NULL || *p =='\0' ) +return -1 ; + + ret =strtoul (p, &q,10 ); +if (*q !='\0' || ret <0 ) { +condlog (2 ,"%s: invalid %s: '%s'" , __func__, attr, p); +return -1 ; + } +return ret; +} +void uevent_get_wwid (struct uevent *uev) { -int i;char *uid_attribute; +const char *val;struct config * conf; conf =get_multipath_config (); uid_attribute =parse_uid_attribute_by_attrs (conf->uid_attrs, uev->kernel);put_multipath_config (conf); -if (!uid_attribute) -return ; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i], uid_attribute,strlen (uid_attribute)) && -strlen (uev->envp[i]) >strlen (uid_attribute) && - uev->envp[i][strlen (uid_attribute)] =='=' ) { - uev->wwid = uev->envp[i] +strlen (uid_attribute) +1 ; -break ; - } - } + val =uevent_get_env_var (uev, uid_attribute); +if (val) + uev->wwid = (char *)val;free (uid_attribute); }
@@ -852,105 +893,39 @@ out:int uevent_get_major (struct uevent *uev) { -char *p, *q; -int i, major =-1 ; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"MAJOR" ,5 ) &&strlen (uev->envp[i]) >6 ) { - p = uev->envp[i] +6 ; - major =strtoul (p, &q,10 ); -if (p == q) { -condlog (2 ,"invalid major '%s'" , p); - major =-1 ; - } -break ; - } - } -return major; +return uevent_get_env_positive_int (uev,"MAJOR" ); }int uevent_get_minor (struct uevent *uev) { -char *p, *q; -int i, minor =-1 ; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"MINOR" ,5 ) &&strlen (uev->envp[i]) >6 ) { - p = uev->envp[i] +6 ; - minor =strtoul (p, &q,10 ); -if (p == q) { -condlog (2 ,"invalid minor '%s'" , p); - minor =-1 ; - } -break ; - } - } -return minor; +return uevent_get_env_positive_int (uev,"MINOR" ); }int uevent_get_disk_ro (struct uevent *uev) { -char *p, *q; -int i, ro =-1 ; +return uevent_get_env_positive_int (uev,"DISK_RO" ); +} -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"DISK_RO" ,7 ) &&strlen (uev->envp[i]) >8 ) { - p = uev->envp[i] +8 ; - ro =strtoul (p, &q,10 ); -if (p == q) { -condlog (2 ,"invalid read_only setting '%s'" , p); - ro =-1 ; - } -break ; - } - } -return ro; +static char *uevent_get_dm_str (const struct uevent *uev,char *attr) +{ +char *tmp =uevent_get_env_var (uev, attr); + +if (tmp ==NULL ) +return NULL ; +return strdup (tmp); }char *uevent_get_dm_name (struct uevent *uev) { -char *p =NULL ; -int i; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"DM_NAME" ,7 ) && -strlen (uev->envp[i]) >8 ) { - p =MALLOC (strlen (uev->envp[i] +8 ) +1 ); -strcpy (p, uev->envp[i] +8 ); -break ; - } - } -return p; +return uevent_get_dm_str (uev,"DM_NAME" ); }char *uevent_get_dm_path (struct uevent *uev) { -char *p =NULL ; -int i; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"DM_PATH" ,7 ) && -strlen (uev->envp[i]) >8 ) { - p =MALLOC (strlen (uev->envp[i] +8 ) +1 ); -strcpy (p, uev->envp[i] +8 ); -break ; - } - } -return p; +return uevent_get_dm_str (uev,"DM_PATH" ); }char *uevent_get_dm_action (struct uevent *uev) { -char *p =NULL ; -int i; - -for (i =0 ; uev->envp[i] !=NULL ; i++) { -if (!strncmp (uev->envp[i],"DM_ACTION" ,9 ) && -strlen (uev->envp[i]) >10 ) { - p =MALLOC (strlen (uev->envp[i] +10 ) +1 ); -strcpy (p, uev->envp[i] +10 ); -break ; - } - } -return p; +return uevent_get_dm_str (uev,"DM_ACTION" ); }
Signature · 1 line
2.15.1
PATCH 4/7 libmultipath: const qualifier for wwid and alias
In reply to Martin WilckAdd "const" qualifiers to some function arguments and fields, in order to tidy up const handling of libmultipath.
--- libmultipath/discovery.c | 2 +- libmultipath/discovery.h | 2 +- libmultipath/memory.h | 2 +- libmultipath/structs.c | 4 ++-- libmultipath/structs.h | 4 ++-- libmultipath/structs_vec.c | 2 +- libmultipath/structs_vec.h | 2 +- libmultipath/uevent.c | 16 ++++++++-------- libmultipath/uevent.h | 14 +++++++------- multipathd/main.c | 8 ++++---- multipathd/main.h | 2 +- 11 files changed, 29 insertions(+), 29 deletions(-)
libmultipath/discovery.c +1 -1
@@ -34,7 +34,7 @@int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -char *wwid,int flag,struct path **pp_ptr) +const char *wwid,int flag,struct path **pp_ptr) {int err =PATHINFO_FAILED ;struct path * pp;
libmultipath/discovery.h +1 -1
@@ -38,7 +38,7 @@ int get_state (struct path * pp, struct config * conf, int daemon, int state);int get_vpd_sgio (int fd,int pg,char * str,int maxlen);int pathinfo (struct path * pp,struct config * conf,int mask);int alloc_path_with_pathinfo (struct config *conf,struct udev_device *udevice, -char *wwid,int flag,struct path **pp_ptr); +const char *wwid,int flag,struct path **pp_ptr);int store_pathinfo (vector pathvec,struct config *conf,struct udev_device *udevice,int flag,struct path **pp_ptr);
libmultipath/memory.h +1 -1
@@ -54,7 +54,7 @@ extern void dbg_free_final(char *);#else #define MALLOC (n) (calloc(1,(n))) -#define FREE (p) do { free(p); p = NULL; } while(0) +#define FREE (p) do { free((void*)p); p = NULL; } while(0)#define REALLOC (p,n) (realloc((p),(n)))#define STRDUP (n) (strdup(n))
libmultipath/structs.c +2 -2
@@ -374,7 +374,7 @@ find_mp_by_wwid (vector mpvec, char * wwid) }struct multipath * -find_mp_by_alias (vector mpvec,char * alias) +find_mp_by_alias (vector mpvec,const char * alias) {int i;int len;
@@ -425,7 +425,7 @@ find_path_by_dev (vector pathvec, char * dev) }struct path * -find_path_by_devt (vector pathvec,char * dev_t) +find_path_by_devt (vector pathvec,const char * dev_t) {int i;struct path * pp;
libmultipath/structs.h +2 -2
@@ -374,12 +374,12 @@ int store_hostgroup(vector hostgroupvec, struct host_group *hgp);int store_path (vector pathvec,struct path * pp);int store_pathgroup (vector pgvec,struct pathgroup * pgp); -struct multipath *find_mp_by_alias (vector mp,char * alias); +struct multipath *find_mp_by_alias (vector mp,const char * alias);struct multipath *find_mp_by_wwid (vector mp,char * wwid);struct multipath *find_mp_by_str (vector mp,char * wwid);struct multipath *find_mp_by_minor (vector mp,int minor); -struct path *find_path_by_devt (vector pathvec,char * devt); +struct path *find_path_by_devt (vector pathvec,const char * devt);struct path *find_path_by_dev (vector pathvec,char * dev);struct path *first_path (struct multipath * mpp);
libmultipath/structs_vec.c +1 -1
@@ -449,7 +449,7 @@ fail:return 0 ; } -struct multipath *add_map_without_path (struct vectors *vecs,char *alias) +struct multipath *add_map_without_path (struct vectors *vecs,const char *alias) {struct multipath * mpp =alloc_multipath ();struct config *conf;
libmultipath/structs_vec.h +1 -1
@@ -33,7 +33,7 @@ void remove_maps_and_stop_waiters (struct vectors * vecs);void sync_map_state (struct multipath *);int update_map (struct multipath *mpp,struct vectors *vecs); -struct multipath *add_map_without_path (struct vectors * vecs,char * alias); +struct multipath *add_map_without_path (struct vectors * vecs,const char * alias);struct multipath *add_map_with_path (struct vectors * vecs,struct path * pp,int add_vec);int update_multipath (struct vectors *vecs,char *mapname,int reset);
libmultipath/uevent.c +8 -8
@@ -891,41 +891,41 @@ out:return err; } -int uevent_get_major (struct uevent *uev) +int uevent_get_major (const struct uevent *uev) {return uevent_get_env_positive_int (uev,"MAJOR" ); } -int uevent_get_minor (struct uevent *uev) +int uevent_get_minor (const struct uevent *uev) {return uevent_get_env_positive_int (uev,"MINOR" ); } -int uevent_get_disk_ro (struct uevent *uev) +int uevent_get_disk_ro (const struct uevent *uev) {return uevent_get_env_positive_int (uev,"DISK_RO" ); } -static char *uevent_get_dm_str (const struct uevent *uev,char *attr) +static const char *uevent_get_dm_str (const struct uevent *uev,char *attr) { -char *tmp =uevent_get_env_var (uev, attr); +const char *tmp =uevent_get_env_var (uev, attr);if (tmp ==NULL )return NULL ;return strdup (tmp); } -char *uevent_get_dm_name (struct uevent *uev) +const char *uevent_get_dm_name (const struct uevent *uev) {return uevent_get_dm_str (uev,"DM_NAME" ); } -char *uevent_get_dm_path (struct uevent *uev) +const char *uevent_get_dm_path (const struct uevent *uev) {return uevent_get_dm_str (uev,"DM_PATH" ); } -char *uevent_get_dm_action (struct uevent *uev) +const char *uevent_get_dm_action (const struct uevent *uev) {return uevent_get_dm_str (uev,"DM_ACTION" ); }
libmultipath/uevent.h +7 -7
@@ -23,7 +23,7 @@ struct uevent {char *devpath;char *action;char *kernel; -char *wwid; +const char *wwid;unsigned long seqnum;char *envp[HOTPLUG_NUM_ENVP ]; };
@@ -33,11 +33,11 @@ int is_uevent_busy(void);int uevent_listen (struct udev *udev);int uevent_dispatch (int (*store_uev)(struct uevent *,void * trigger_data),void * trigger_data); -int uevent_get_major (struct uevent *uev); -int uevent_get_minor (struct uevent *uev); -int uevent_get_disk_ro (struct uevent *uev); -char *uevent_get_dm_name (struct uevent *uev); -char *uevent_get_dm_path (struct uevent *uev); -char *uevent_get_dm_action (struct uevent *uev); +int uevent_get_major (const struct uevent *uev); +int uevent_get_minor (const struct uevent *uev); +int uevent_get_disk_ro (const struct uevent *uev); +const char *uevent_get_dm_name (const struct uevent *uev); +const char *uevent_get_dm_path (const struct uevent *uev); +const char *uevent_get_dm_action (const struct uevent *uev);#endif /* _UEVENT_H */
multipathd/main.c +4 -4
@@ -387,7 +387,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)static int uev_add_map (struct uevent * uev,struct vectors * vecs) { -char *alias; +const char *alias;int major =-1 , minor =-1 , rc;condlog (3 ,"%s: add map (uevent)" , uev->kernel);
@@ -413,7 +413,7 @@ uev_add_map (struct uevent * uev, struct vectors * vecs) }int -ev_add_map (char * dev,char * alias,struct vectors * vecs) +ev_add_map (char * dev,const char * alias,struct vectors * vecs) {char * refwwid;struct multipath * mpp;
@@ -500,7 +500,7 @@ ev_add_map (char * dev, char * alias, struct vectors * vecs)static int uev_remove_map (struct uevent * uev,struct vectors * vecs) { -char *alias; +const char *alias;int minor;struct multipath *mpp;
@@ -1001,7 +1001,7 @@ out:static int uev_pathfail_check (struct uevent *uev,struct vectors *vecs) { -char *action =NULL , *devt =NULL ; +const char *action =NULL , *devt =NULL ;struct path *pp;int r =1 ;
multipathd/main.h +1 -1
@@ -24,7 +24,7 @@ int need_to_delay_reconfig (struct vectors *);int reconfigure (struct vectors *);int ev_add_path (struct path *,struct vectors *,int );int ev_remove_path (struct path *,struct vectors *,int ); -int ev_add_map (char *,char *,struct vectors *); +int ev_add_map (char *,const char *,struct vectors *);int ev_remove_map (char *,char *,int ,struct vectors *);int set_config_state (enum daemon_status );void *mpath_alloc_prin_response (int prin_sa);
Signature · 1 line
2.15.1
PATCH 5/7 libmultipath: move UUID_PREFIX to devmapper.h
In reply to Martin WilckThis constant is useful elsewhere, too.
--- libmultipath/devmapper.c | 3 --- libmultipath/devmapper.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)
libmultipath/devmapper.c +0 -3
@@ -30,9 +30,6 @@#define MAX_WAIT 5#define LOOPS_PER_SEC 5 -#define UUID_PREFIX "mpath-" -#define UUID_PREFIX_LEN 6 -static int dm_conf_verbosity;#ifdef LIBDM_API_DEFERRED
libmultipath/devmapper.h +3 -0
@@ -24,6 +24,9 @@#define MPATH_UDEV_NO_PATHS_FLAG 0#endif +#define UUID_PREFIX "mpath-" +#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1) +void dm_init (int verbosity);void libmp_dm_init (void );void libmp_udev_set_sync_support (int on);
Signature · 1 line
2.15.1
PATCH 6/7 libmultipath: add uevent_is_mpath
In reply to Martin WilckThis function can be used to test if an uevent belongs to valid multipath device. Unit tests are also added.
--- libmultipath/uevent.c | 12 ++++++++++ libmultipath/uevent.h | 1 + tests/uevent.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+)
libmultipath/uevent.c +12 -0
@@ -52,6 +52,7 @@#include "util.h" #include "config.h" #include "blacklist.h" +#include "devmapper.h" #define MAX_ACCUMULATION_COUNT 2048#define MAX_ACCUMULATION_TIME 30*1000
@@ -929,3 +930,14 @@ const char *uevent_get_dm_action(const struct uevent *uev) {return uevent_get_dm_str (uev,"DM_ACTION" ); } + +bool uevent_is_mpath (const struct uevent *uev) +{ +const char *uuid =uevent_get_env_var (uev,"DM_UUID" ); + +if (uuid ==NULL ) +return false; +if (strncmp (uuid,UUID_PREFIX ,UUID_PREFIX_LEN )) +return false; +return uuid[UUID_PREFIX_LEN ] !='\0' ; +}
libmultipath/uevent.h +1 -0
@@ -39,5 +39,6 @@ int uevent_get_disk_ro(const struct uevent *uev);const char *uevent_get_dm_name (const struct uevent *uev);const char *uevent_get_dm_path (const struct uevent *uev);const char *uevent_get_dm_action (const struct uevent *uev); +bool uevent_is_mpath (const struct uevent *uev);#endif /* _UEVENT_H */
tests/uevent.c +63 -0
81 lines not on this page · raw message
Signature · 1 line
2.15.1
PATCH 7/7 multipathd: ignore uevents for non-mpath devices
In reply to Martin Wilckmultipathd can't deal with other devices anyway. Proceeding further with events for other devices just generates log noise.
Based on an idea from Ritika Srivastava <[email protected]>. ("multipath-tools: Skip CHANGE uevent for non-mpath devices").
--- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
multipathd/main.c +1 -1
@@ -1121,7 +1121,7 @@ uev_trigger (struct uevent * uev, void * trigger_data)* Add events are ignored here as the tables * are not fully initialised then. */ -if (!strncmp (uev->kernel,"dm-" ,3 )) { +if (!strncmp (uev->kernel,"dm-" ,3 ) &&uevent_is_mpath (uev)) {if (!strncmp (uev->action,"change" ,6 )) { r =uev_add_map (uev, vecs);
Signature · 1 line
2.15.1
Re: [PATCH 7/7] multipathd: ignore uevents for non-mpath devices
Quoted 16 lines · Martin Wilck
multipathd can't deal with other devices anyway. Proceeding further with events for other devices just generates log noise.
Based on an idea from Ritika Srivastava <[email protected]>. ("multipath-tools: Skip CHANGE uevent for non-mpath devices").
Signed-off-by Martin Wilck <[email protected]>--- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)multipathd/main.c +0
-0
multipathd/main.c uev_trigger (struct uevent * uev, void * trigger_data) · line 1127
Quoted 8 lines
multipathd/main.c +1
-1@@ -1121,7 +1121,7 @@ uev_trigger (struct uevent * uev, void * trigger_data)* Add events are ignored here as the tables * are not fully initialised then. */ -if (!strncmp (uev->kernel,"dm-" ,3 )) { +if (!strncmp (uev->kernel,"dm-" ,3 ) &&uevent_is_mpath (uev)) {if (!strncmp (uev->action,"change" ,6 )) { r =uev_add_map (uev, vecs);
Hi Martin,
Thank you for the updated patch.
With this patch, the error "uevent trigger error" would not be encountered when removing lvm snapshots.
However, when the uevent is for a 'dm' device but not for a multipath device, then should we just return from this check in uev_trigger()? With this patch, uev_update_path()/uev_remove_path() would still be called which would generate further log.
Should we avoid these function calls too?
Signature · 2 lines
Thanks, Ritika
Re: [PATCH 7/7] multipathd: ignore uevents for non-mpath devices
Quoted 34 lines · Ritika Srivastava
Quoted 25 lines · Martin Wilck
multipathd can't deal with other devices anyway. Proceeding further with events for other devices just generates log noise.
Based on an idea from Ritika Srivastava <[email protected] om>.
("multipath-tools: Skip CHANGE uevent for non-mpath devices").Signed-off-by Martin Wilck <[email protected]>--- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)multipathd/main.c +1
-1@@ -1121,7 +1121,7 @@ uev_trigger (struct uevent * uev, void *trigger_data) * Add events are ignored here as the tables * are not fully initialised then. */ -if (!strncmp (uev->kernel,"dm-" ,3 )) { +if (!strncmp (uev->kernel,"dm-" ,3 ) &&uevent_is_mpath (uev)) {if (!strncmp (uev->action,"change" ,6 )) {Quoted 2 lines
r = uev_add_map(uev, vecs);Hi Martin,
Thank you for the updated patch.
With this patch, the error "uevent trigger error" would not be encountered when removing lvm snapshots.
Quoted 6 lines
However, when the uevent is for a 'dm' device but not for a multipath
device, then should we just return from this check inuev_trigger()? With this patch, uev_update_path()/uev_remove_path() would still be called which would generate further log.
Should we avoid these function calls too?
You are right, thanks for pointing that out. I'll post an update.
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH v2 1/1 multipathd: ignore uevents for non-mpath devices
In reply to Ritika Srivastavamultipathd can't deal with other devices anyway. Proceeding further with events for other devices just generates log noise.
Based on an idea from Ritika Srivastava <[email protected]>. ("multipath-tools: Skip CHANGE uevent for non-mpath devices").
Changes in v2: always return immediately for non-mpath case
(Ritika Srivastava)
--- multipathd/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
multipathd/main.c +3 -4
@@ -1122,6 +1122,8 @@ uev_trigger (struct uevent * uev, void * trigger_data)* are not fully initialised then. */ if (!strncmp (uev->kernel,"dm-" ,3 )) { +if (!uevent_is_mpath (uev)) + goto out;if (!strncmp (uev->action,"change" ,6 )) { r =uev_add_map (uev, vecs);
@@ -1132,11 +1134,8 @@ uev_trigger (struct uevent * uev, void * trigger_data)* cess. */ uev_pathfail_check (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"remove" ,6 )) { + }else if (!strncmp (uev->action,"remove" ,6 )) { r =uev_remove_map (uev, vecs); - goto out; } goto out; }
Signature · 1 line
2.16.1
Re: [PATCH v2] multipathd: ignore uevents for non-mpath devices
Quoted 30 lines · Martin Wilck
multipathd can't deal with other devices anyway. Proceeding further with events for other devices just generates log noise.
Based on an idea from Ritika Srivastava <[email protected]>. ("multipath-tools: Skip CHANGE uevent for non-mpath devices").
Changes in v2: always return immediately for non-mpath case
(Ritika Srivastava)Signed-off-by Martin Wilck <[email protected]>--- multipathd/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)multipathd/main.c +2
-0@@ -1122,6 +1122,8 @@ uev_trigger (struct uevent * uev, void * trigger_data)* are not fully initialised then. */ if (!strncmp (uev->kernel,"dm-" ,3 )) { +if (!uevent_is_mpath (uev)) + goto out;if (!strncmp (uev->action,"change" ,6 )) { r =uev_add_map (uev, vecs);@@ -1132,11 +1134,8 @@ uev_trigger (struct uevent * uev, void * trigger_data)* cess. */
multipathd/main.c uev_trigger (struct uevent * uev, void * trigger_data) · line 1141
Quoted 10 lines
multipathd/main.c +1
-4uev_pathfail_check (uev, vecs); - goto out; - } -if (!strncmp (uev->action,"remove" ,6 )) { + }else if (!strncmp (uev->action,"remove" ,6 )) { r =uev_remove_map (uev, vecs); - goto out; } goto out; }
The updated patch looks good.
Signature · 2 lines
Thanks, Ritika
Quoted 12 lines · Martin Wilck
Hi Christophe,
The incentive for creating this series was Ritika's patch "multipath-tools:
Skip CHANGE uevent for non-mpath devices" from October 2017, plus the observation thatuevent.ccontains a lot of code repetition. I've refactored and simplified theuevent_get_XXXcode, and started to use "const" qualifiers in the part of the code which I touched in the process.In order to avoid regressions in the process, I took this as a starting point for implementing a simple unit test framework. For now, it covers only the stuff that I changed in this series.
Quoted 8 lines
The series is based on my previous patch series ("Various multipath-tools fixes"), v2. The first patch doesn't belong in the series logically, but I thought it may help you track the ordering if I include it here rather then posting separately or spamming the list with the big series again.
Regards,
Martin
Looks good.
Quoted 36 lines
Martin Wilck (7):
assemble_map: no newline at end of params string
tests: cmocka-based unit test foruevent_get_XXX
libmultipath: refactoruevent_get_XXX
libmultipath: const qualifier for wwid and alias
libmultipath: moveUUID_PREFIXtodevmapper.h
libmultipath: adduevent_is_mpath
multipathd: ignore uevents for non-mpath devices.gitignore | 3 + Makefile | 4 + libmultipath/devmapper.c | 3 - libmultipath/devmapper.h | 3 + libmultipath/discovery.c | 2 +- libmultipath/discovery.h | 2 +- libmultipath/dmparser.c | 1 - libmultipath/memory.h | 2 +- libmultipath/structs.c | 4 +- libmultipath/structs.h | 4 +- libmultipath/structs_vec.c | 2 +- libmultipath/structs_vec.h | 2 +- libmultipath/uevent.c | 183 +++++++++++++-------------- libmultipath/uevent.h | 15 +-- multipathd/main.c | 10 +- multipathd/main.h | 2 +- tests/Makefile | 23 ++++ tests/globals.c | 17 +++ tests/uevent.c | 304 +++++++++++++++++++++++++++++++++++++++++++++ 19 files changed, 462 insertions(+), 124 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/globals.c create mode 100644 tests/uevent.cSignature · 1 line
2.15.1