multipath: new and rebased patches
Subsystems (2)
Benjamin Marzinski
maintainercover multipath: new and rebased patches
Patches 1-5 are minor bug fixes and a unit test for basenamecpy.
Patch 6 is revised version of my nanosleep patch, that only changes the checkerloop code, since that is the only time when multipathd actually sets an alarm without locking.
Patches 7-11 are a rebase of my "alternate dmevents waiter method" patchset. The only code that has changed outside of rebasing them is in patch 11. It adds a function, remove_map_by_alias(), and uses it in dmevent_loop(). This simply moves the code the gets the multipath device out of dmevents.c, so it can work exclusively in device names. It also changes the names of the functions the initialize and cleanup the dmevents polling code to match similar multipathd functions and adds a Makefile define to disable using the polling code, both suggested by Martin Wilck.
Patch 12 is unit testing code for the new code in dmevents.c
Here is the description from my initial posting of the alternate dmevents waiter method" patchset:
This patchset implements a new method of getting dmevents for multipathd.
With the existing wait code, multipathd needs to create a waiter thread for every multipath device. This can become very wasteful in setups with large numbers of multipath devices. These duplicate threads all are serialized to update the multipath devices, so they don't actually speed up dmevent handling.
The new method uses the new dmevent polling ability introduced in the 4.37.0 device-mapper kernel module. The original method has been retained for backwards compatablility, and it is possible to force multipathd to use the orignal method on newer kernels. The benefit of this new method is that there is only one thread necessary to wait on dmevents, which can be started when device-mapper starts, and stopped during shutdown, just like the other main threads.
These patches use device-mapper features that don't have a libdevmapper API. They will switch over as soon as support is available in libdevmapper.
Benjamin Marzinski (12):
Unit tests for basenamecpy
libmultipath: fix basenamecpy
libmultipath: set dm_conf_verbosity
multipathd: log thread cleanup
libmultipath: fix log_pthread processing
multipathd: use nanosleep for strict timing
libmultipath: move remove_map waiter code to multipathd move waiter code from libmultipath to multipathd call start_waiter_thread() before setup_multipath()
libmultipath: add helper functions
multipathd: add new polling dmevents waiter thread
multipath: add unit tests for dmevents code
Makefile.inc | 3 + libmultipath/Makefile | 2 +- libmultipath/devmapper.c | 29 +- libmultipath/devmapper.h | 3 +- libmultipath/log_pthread.c | 40 +-- libmultipath/log_pthread.h | 10 +- libmultipath/structs_vec.c | 140 +------- libmultipath/structs_vec.h | 8 +- libmultipath/util.c | 25 +- libmultipath/util.h | 2 +- libmultipath/vector.c | 16 +- libmultipath/vector.h | 1 + libmultipath/waiter.c | 215 ------------ libmultipath/waiter.h | 17 - multipathd/Makefile | 6 +- multipathd/dmevents.c | 392 +++++++++++++++++++++ multipathd/dmevents.h | 13 + multipathd/main.c | 230 ++++++++++-- multipathd/waiter.c | 215 ++++++++++++ multipathd/waiter.h | 17 + tests/Makefile | 9 +- tests/dmevents.c | 847 +++++++++++++++++++++++++++++++++++++++++++++ tests/util.c | 167 +++++++++ 23 files changed, 1944 insertions(+), 463 deletions(-) delete mode 100644 libmultipath/waiter.c delete mode 100644 libmultipath/waiter.h create mode 100644 multipathd/dmevents.c create mode 100644 multipathd/dmevents.h create mode 100644 multipathd/waiter.c create mode 100644 multipathd/waiter.h create mode 100644 tests/dmevents.c create mode 100644 tests/util.c
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 1/12 Unit tests for basenamecpy
The current implementation of basenamecpy is broken, so some of these tests currently fail. Fixes to follow.
--- tests/Makefile | 2 +- tests/util.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 tests/util.c
tests/Makefile +1 -1
@@ -3,7 +3,7 @@ include ../Makefile.inc CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka -TESTS := uevent parser +TESTS := uevent parser util .SILENT: $(TESTS:%=%.o) .PRECIOUS: $(TESTS:%=%-test)
tests/util.c new file +167 -0
167 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 01/12] Unit tests for basenamecpy
Quoted 18 lines · Benjamin Marzinski
The current implementation of basenamecpy is broken, so some of these tests currently fail. Fixes to follow.
Signed-off-by Benjamin Marzinski <[email protected]>--- tests/Makefile | 2 +- tests/util.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 tests/util.ctests/util.c new file +5
-0+static void test_basenamecpy_good6 (void **state) +{ +char dst[6 ]; + + assert_int_equal(basenamecpy("/xyzzy/plugh ", dst,sizeof(dst)), 5);
Review
Quoted 2 lines
(quoted diff) +2
-0+ assert_string_equal(dst, "plugh"); +}
This deserves explanation. "basename" wouldn't normally strip trailing whitespace.
Quoted 7 lines
tests/util.c new file +6
-0+/* ends in slash */ +static void test_basenamecpy_bad1 (void **state) +{ +char dst[10 ]; + + assert_int_equal(basenamecpy("foo/bar/", dst, sizeof(dst)),0);
This, too, deviates from standard "basename" behavior and should be explained ("basename /usr/" yields "usr", so does "basename /usr///").
Quoted 12 lines
tests/util.c new file +12
-0+} + +static void test_basenamecpy_bad2 (void **state) +{ +char dst[10 ]; + +assert_int_equal (basenamecpy (NULL , dst,sizeof (dst)),0 ); +} + +static void test_basenamecpy_bad3 (void **state) +{ +char dst[10 ];
tests/util.c line 131
Quoted 10 lines
tests/util.c new file +10
-0+ +assert_int_equal (basenamecpy ("" , dst,sizeof (dst)),0 ); +} + +static void test_basenamecpy_bad4 (void **state) +{ +char dst[10 ]; + +assert_int_equal (basenamecpy ("/" , dst,sizeof (dst)),0 ); +}
Another one: "basename /" yields "/" in the shell, so does "basename ///").
I don't insist that basenamecpy behaves 100% identical as "basename", but I reckon if expectations are different, we should explain why.
Regards,
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
Re: [PATCH 01/12] Unit tests for basenamecpy
Quoted 26 lines · Martin Wilck
Quoted 18 lines · Benjamin Marzinski
The current implementation of basenamecpy is broken, so some of these
tests currently fail. Fixes to follow.Signed-off-by Benjamin Marzinski <[email protected]>--- tests/Makefile | 2 +- tests/util.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 tests/util.ctests/util.c new file +5
-0+static void test_basenamecpy_good6 (void **state) +{ +char dst[6 ]; + + assert_int_equal(basenamecpy("/xyzzy/plugh ", dst,sizeof(dst)), 5);
Review
Quoted 2 lines
(quoted diff) +2
-0+ assert_string_equal(dst, "plugh"); +}This deserves explanation. "basename" wouldn't normally strip trailing
whitespace.
Quoted 12 lines
Quoted 8 lines
tests/util.c new file +6
-0+/* ends in slash */ +static void test_basenamecpy_bad1 (void **state) +{ +char dst[10 ]; + + assert_int_equal(basenamecpy("foo/bar/", dst,sizeof(dst)),
0);This, too, deviates from standard "basename" behavior and should be explained ("basename
/usr/" yields "usr", so does "basename/usr///").
I didn't realize the difference between POSIX "basename" and GNU "basename", and was mislead by the shell behavior. So this and the following nitpick about "/" can be disregarded. But please add a comment for the whitespace stripping.
Apart from that, ACK.
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
Benjamin Marzinski
maintainerPATCH 2/12 libmultipath: fix basenamecpy
In reply to Benjamin Marzinskibasenamecpy was returning the wrong answer in multiple cases, as shown by the unit tests for it. Now it will properly find the basename (as defined by GNU basename, which works well for all of multipath's uses) and return a copy, if the basename can fit in provided buffer.
--- libmultipath/util.c | 25 ++++++++----------------- libmultipath/util.h | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-)
libmultipath/util.c +8 -17
@@ -30,30 +30,21 @@ strchop(char *str) }int -basenamecpy (const char * str1,char * str2,int str2len) +basenamecpy (const char *src,char *dst,size_t size) { -const char *p; +const char *p, *e; -if (!str1 || !strlen (str1)) +if (!src || !dst || !strlen (src))return 0 ; -if (strlen (str1) >= str2len) -return 0 ; + p =basename (src); -if (!str2) +for (e = p +strlen (p) -1 ; e >= p &&isspace (*e); --e) ; +if (e < p || e - p > size -2 )return 0 ; - p = str1 + (strlen (str1) -1 ); - -while (*--p !='/' && p != str1) -continue ; - -if (p != str1) - p++; - -strncpy (str2, p, str2len); - str2[str2len -1 ] ='\0' ; -return strchop (str2); +strlcpy (dst, p, e - p +2 ); +return strlen (dst); }int
libmultipath/util.h +1 -1
@@ -5,7 +5,7 @@#include <inttypes.h> size_t strchop (char *); -int basenamecpy (const char * src,char * dst,int ); +int basenamecpy (const char *src,char *dst,size_t size);int filepresent (char * run);char *get_next_string (char **temp,char *split_char);int get_word (char * sentence,char ** word);
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 3/12 libmultipath: set dm_conf_verbosity
In reply to Benjamin Marzinskidm_conf_verbosity was created to keep dm_write_log from needing access to the multipath config. However it never was set.
--- libmultipath/devmapper.c | 1 + 1 file changed, 1 insertion(+)
libmultipath/devmapper.c +1 -0
@@ -95,6 +95,7 @@ dm_write_log (int level, const char *file, int line, const char *f, ...)void dm_init (int v) { + dm_conf_verbosity = v;dm_log_init (&dm_write_log);dm_log_init_verbose (v +3 ); }
Signature · 1 line
2.7.4
Re: [PATCH 03/12] libmultipath: set dm_conf_verbosity
Quoted 4 lines · Benjamin Marzinski
dm_conf_verbositywas created to keepdm_write_logfrom needing access to the multipath config. However it never was set.Signed-off-by Benjamin Marzinski <[email protected]>
I'm curious how much verbosity this will add to multipathd output. But ut's activated at v >= 4 only, so it should be fine.
Back in my head, I've been thinking about more fine-grained logging control with log layer + log level for a while...
Quoted 17 lines
--- libmultipath/devmapper.c | 1 + 1 file changed, 1 insertion(+)libmultipath/devmapper.c +1
-0@@ -95,6 +95,7 @@ dm_write_log (int level, const char *file, int line, const char *f, ...) void dm_init(int v) { + dm_conf_verbosity = v;dm_log_init (&dm_write_log);dm_log_init_verbose (v +3 );}
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
Benjamin Marzinski
maintainerPATCH 4/12 multipathd: log thread cleanup
In reply to Benjamin MarzinskiThe function log_thread_flush() is an exact copy of flush_lgoqueue(), so both clearly don't need to exist. Also, There is no reason to make all of the log thread variables global. The only time any of them were being used outside of log_thread.c, was to reset the log. This code should never be run if the log_thread isn't running, so it makes more sense to live inside of log_thread.c
--- libmultipath/log_pthread.c | 34 +++++++++++++++------------------- libmultipath/log_pthread.h | 10 +--------- multipathd/main.c | 5 ++--- 3 files changed, 18 insertions(+), 31 deletions(-)
libmultipath/log_pthread.c +15 -19
@@ -14,13 +14,13 @@#include "log.h" #include "lock.h" -pthread_t log_thr; +static pthread_t log_thr; -pthread_mutex_t logq_lock; -pthread_mutex_t logev_lock; -pthread_cond_t logev_cond; +static pthread_mutex_t logq_lock; +static pthread_mutex_t logev_lock; +static pthread_cond_t logev_cond; -int logq_running; +static int logq_running;void log_safe (int prio,const char * fmt,va_list ap) {
@@ -38,19 +38,6 @@ void log_safe (int prio, const char * fmt, va_list ap)pthread_mutex_unlock (&logev_lock); } -void log_thread_flush (void ) -{ -int empty; - -do { -pthread_mutex_lock (&logq_lock); - empty =log_dequeue (la->buff); -pthread_mutex_unlock (&logq_lock); -if (!empty) -log_syslog (la->buff); - }while (empty ==0 ); -} -static void flush_logqueue (void ) {int empty;
@@ -82,7 +69,7 @@ static void * log_thread (void * et)pthread_mutex_unlock (&logev_lock);if (!running)break ; -log_thread_flush (); +flush_logqueue (); }return NULL ; }
@@ -107,6 +94,15 @@ void log_thread_start (pthread_attr_t *attr)return ; } +void log_thread_reset (void ) +{ +logdbg (stderr,"resetting log\n" ); + +pthread_mutex_lock (&logq_lock); +log_reset ("multipathd" ); +pthread_mutex_unlock (&logq_lock); +} +void log_thread_stop (void ) {logdbg (stderr,"enter log_thread_stop\n" );
libmultipath/log_pthread.h +1 -9
@@ -3,17 +3,9 @@#include <pthread.h> -extern pthread_t log_thr; - -extern pthread_mutex_t logq_lock; -extern pthread_mutex_t logev_lock; -extern pthread_cond_t logev_cond; - -extern int logq_running; -void log_safe (int prio,const char * fmt,va_list ap);void log_thread_start (pthread_attr_t *attr); +void log_thread_reset (void );void log_thread_stop (void ); -void log_thread_flush (void );#endif /* _LOG_PTHREAD_H */
multipathd/main.c +2 -3
@@ -2219,9 +2219,8 @@ handle_signals(bool nonfatal) }if (log_reset_sig) {condlog (2 ,"reset log (signal)" ); -pthread_mutex_lock (&logq_lock); -log_reset ("multipathd" ); -pthread_mutex_unlock (&logq_lock); +if (logsink ==1 ) +log_thread_reset (); } reconfig_sig =0 ; log_reset_sig =0 ;
Signature · 1 line
2.7.4
Re: [PATCH 04/12] multipathd: log thread cleanup
Quoted 11 lines · Benjamin Marzinski
The function
log_thread_flush()is an exact copy offlush_lgoqueue(), so
both clearly don't need to exist. Also, There is no reason to make all
of the log thread variables global. The only time any of them were being used outside oflog_thread.c, was to reset the log. This code should never be run if thelog_threadisn't running, so it makes more sense to live inside oflog_thread.cSigned-off-by Benjamin Marzinski <[email protected]>---
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH 5/12 libmultipath: fix log_pthread processing
In reply to Benjamin Marzinskilog_pthread() was waiting for notification on logev_cond, without checking if it had already happened. This means it could end up waiting, while there is work that it should be doing.
--- libmultipath/log_pthread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libmultipath/log_pthread.c +5 -1
@@ -21,6 +21,7 @@ static pthread_mutex_t logev_lock;static pthread_cond_t logev_cond;static int logq_running; +static int log_messages_pending;void log_safe (int prio,const char * fmt,va_list ap) {
@@ -34,6 +35,7 @@ void log_safe (int prio, const char * fmt, va_list ap)pthread_mutex_unlock (&logq_lock);pthread_mutex_lock (&logev_lock); + log_messages_pending =1 ;pthread_cond_signal (&logev_cond);pthread_mutex_unlock (&logev_lock); }
@@ -64,7 +66,9 @@ static void * log_thread (void * et)while (1 ) {pthread_mutex_lock (&logev_lock); -pthread_cond_wait (&logev_cond, &logev_lock); +if (logq_running && !log_messages_pending) +pthread_cond_wait (&logev_cond, &logev_lock); + log_messages_pending =0 ; running = logq_running;pthread_mutex_unlock (&logev_lock);if (!running)
Signature · 1 line
2.7.4
Re: [PATCH 05/12] libmultipath: fix log_pthread processing
Quoted 5 lines · Benjamin Marzinski
log_pthread()was waiting for notification onlogev_cond, without checking if it had already happened. This means it could end up waiting, while there is work that it should be doing.Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Benjamin Marzinski
maintainerPATCH 6/12 multipathd: use nanosleep for strict timing
In reply to Benjamin MarzinskiIn order to safely use SIGALRM in a multi-threaded program, only one thread can schedule and wait on SIGALRM at a time. All other threads must have SIGALRM blocked, and be unable to schedule an alarm. The strict_timing code in checkerloop was unblocking SIGALRM, and calling setitimer(), without any locking. Instead, it should use nanosleep() to sleep for the correct length of time, since that doesn't depend or interfere with signals.
--- multipathd/main.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)
multipathd/main.c +9 -18
@@ -1855,7 +1855,6 @@ checkerloop (void *ap)struct path *pp;int count =0 ;unsigned int i; -struct itimerval timer_tick_it;struct timespec last_time;struct config *conf;
@@ -1873,8 +1872,7 @@ checkerloop (void *ap)while (1 ) {struct timespec diff_time, start_time, end_time; -int num_paths =0 , ticks =0 , signo, strict_timing, rc =0 ; -sigset_t mask; +int num_paths =0 , ticks =0 , strict_timing, rc =0 ;if (clock_gettime (CLOCK_MONOTONIC , &start_time) !=0 ) start_time.tv_sec =0 ;
@@ -1962,25 +1960,18 @@ checkerloop (void *ap)if (!strict_timing)sleep (1 );else { - timer_tick_it.it_interval.tv_sec =0 ; - timer_tick_it.it_interval.tv_usec =0 ;if (diff_time.tv_nsec) { - timer_tick_it.it_value.tv_sec =0 ; - timer_tick_it.it_value.tv_usec = + diff_time.tv_sec =0 ; + diff_time.tv_nsec =1000UL *1000 *1000 - diff_time.tv_nsec; - }else { - timer_tick_it.it_value.tv_sec =1 ; - timer_tick_it.it_value.tv_usec =0 ; - } -setitimer (ITIMER_REAL , &timer_tick_it,NULL ); + }else + diff_time.tv_sec =1 ; -sigemptyset (&mask); -sigaddset (&mask,SIGALRM );condlog (3 ,"waiting for %lu.%06lu secs" , - timer_tick_it.it_value.tv_sec, - timer_tick_it.it_value.tv_usec); -if (sigwait (&mask, &signo) !=0 ) { -condlog (3 ,"sigwait failed with error %d" , + diff_time.tv_sec, + diff_time.tv_nsec /1000 ); +if (nanosleep (&diff_time,NULL ) !=0 ) { +condlog (3 ,"nanosleep failed with error %d" , errno); conf =get_multipath_config (); conf->strict_timing =0 ;
Signature · 1 line
2.7.4
Re: [PATCH 06/12] multipathd: use nanosleep for strict timing
Quoted 30 lines · Benjamin Marzinski
In order to safely use SIGALRM in a multi-threaded program, only one thread can schedule and wait on SIGALRM at a time. All other threads must have SIGALRM blocked, and be unable to schedule an alarm. The
strict_timingcode in checkerloop was unblocking SIGALRM, and callingsetitimer(), without any locking. Instead, it should usenanosleep()to sleep for the correct length of time, since that doesn't depend or interfere with signals.Signed-off-by Benjamin Marzinski <[email protected]>--- multipathd/main.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)multipathd/main.c +0
-4condlog(3, "waiting for %lu.%06lu secs", - timer_tick_it.it_value.tv_sec, - timer_tick_it.it_value.tv_usec); -if (sigwait (&mask, &signo) !=0 ) { - condlog(3, "sigwait failed witherror %d",
multipathd/main.c +4
-0+ diff_time.tv_sec, + diff_time.tv_nsec / 1000); +if (nanosleep (&diff_time,NULL ) !=0 ) { + condlog(3, "nanosleep failed witherror %d",
multipathd/main.c checkerloop (void *ap) · line 1977
Quoted 3 lines
multipathd/main.c +0
-0errno); conf =get_multipath_config (); conf->strict_timing =0 ;
Nitpick: the only realistic error code for nanosleep is EINTR, in which case we IMO don't need the log message, because just means one of the expected signals arrived.
As stated earlier, I'd prefer a kernel interval timer for strict_timing. I'm unsure why it hasn't been done that way in the first place. Anyway, that can be discussed later, therefore:
... with the nit above.
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
Benjamin Marzinski
maintainerPATCH 7/12 libmultipath: move remove_map waiter code to multipathd
In reply to Benjamin MarzinskiOnly multipathd needs to worry about the multipath waiter code. There is no point in having remove_map_and_stop_waiter() or remove_maps_and_stop_waiters() in libmultipath, since they should never be use outside of multipathd.
--- libmultipath/structs_vec.c | 40 +++++----------------------------------- libmultipath/structs_vec.h | 2 -- multipathd/main.c | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 37 deletions(-)
libmultipath/structs_vec.c +5 -35
@@ -117,25 +117,16 @@ set_multipath_wwid (struct multipath * mpp)dm_get_uuid (mpp->alias, mpp->wwid); } -#define KEEP_WAITER 0 -#define STOP_WAITER 1#define PURGE_VEC 1 -static void -_remove_map (struct multipath * mpp,struct vectors * vecs, -int stop_waiter,int purge_vec) +void +remove_map (struct multipath * mpp,struct vectors * vecs,int purge_vec) {int i;condlog (4 ,"%s: remove multipath map" , mpp->alias);/* -* stop the DM event waiter thread -*/ -if (stop_waiter) -stop_waiter_thread (mpp, vecs); - -/* * clear references to this map */ orphan_paths (vecs->pathvec, mpp);
@@ -150,19 +141,8 @@ _remove_map (struct multipath * mpp, struct vectors * vecs,free_multipath (mpp,KEEP_PATHS ); } -void remove_map (struct multipath *mpp,struct vectors *vecs,int purge_vec) -{ -_remove_map (mpp, vecs,KEEP_WAITER , purge_vec); -} - -void remove_map_and_stop_waiter (struct multipath *mpp,struct vectors *vecs, -int purge_vec) -{ -_remove_map (mpp, vecs,STOP_WAITER , purge_vec); -} - -static void -_remove_maps (struct vectors * vecs,int stop_waiter) +void +remove_maps (struct vectors * vecs) {int i;struct multipath * mpp;
@@ -171,7 +151,7 @@ _remove_maps (struct vectors * vecs, int stop_waiter)return ; vector_foreach_slot (vecs->mpvec, mpp, i) { -_remove_map (mpp, vecs, stop_waiter,1 ); +remove_map (mpp, vecs,1 ); i--; }
@@ -179,16 +159,6 @@ _remove_maps (struct vectors * vecs, int stop_waiter) vecs->mpvec =NULL ; } -void remove_maps (struct vectors *vecs) -{ -_remove_maps (vecs,KEEP_WAITER ); -} - -void remove_maps_and_stop_waiters (struct vectors *vecs) -{ -_remove_maps (vecs,STOP_WAITER ); -} -void extract_hwe_from_path (struct multipath * mpp) {
libmultipath/structs_vec.h +0 -2
@@ -27,9 +27,7 @@ int update_multipath_strings (struct multipath *mpp, vector pathvec,void extract_hwe_from_path (struct multipath * mpp);void remove_map (struct multipath * mpp,struct vectors * vecs,int purge_vec); -void remove_map_and_stop_waiter (struct multipath * mpp,struct vectors * vecs,int purge_vec);void remove_maps (struct vectors * vecs); -void remove_maps_and_stop_waiters (struct vectors * vecs);void sync_map_state (struct multipath *);int update_map (struct multipath *mpp,struct vectors *vecs);
multipathd/main.c +23 -0
@@ -293,6 +293,29 @@ switch_pathgroup (struct multipath * mpp) mpp->alias, mpp->bestpg); } +static void +remove_map_and_stop_waiter (struct multipath *mpp,struct vectors *vecs, +int purge_vec) +{ +stop_waiter_thread (mpp, vecs); +remove_map (mpp, vecs, purge_vec); +} + +static void +remove_maps_and_stop_waiters (struct vectors *vecs) +{ +int i; +struct multipath * mpp; + +if (!vecs) +return ; + + vector_foreach_slot(vecs->mpvec, mpp, i) +stop_waiter_thread (mpp, vecs); + +remove_maps (vecs); +} +static int coalesce_maps (struct vectors *vecs,vector nmpv) {
Signature · 1 line
2.7.4
Re: [PATCH 07/12] libmultipath: move remove_map waiter code to multipathd
Quoted 15 lines · Benjamin Marzinski
Only multipathd needs to worry about the multipath waiter code. There is
no point in havingremove_map_and_stop_waiter()orremove_maps_and_stop_waiters()in libmultipath, since they should never
be use outside of multipathd.Reviewed-by Martin Wilck <[email protected]>Signed-off-by Benjamin Marzinski <[email protected]>(quoted diff) +2
-0+static void +remove_map_and_stop_waiter(struct multipath *mpp, struct vectors*vecs,
multipathd/main.c switch_pathgroup (struct multipath * mpp) · line 302
Quoted 5 lines
multipathd/main.c +5
-0+ int purge_vec) +{ +stop_waiter_thread (mpp, vecs); +remove_map (mpp, vecs, purge_vec); +}
AFAICS remove_map_and_stop_waiter is always called with purge_vec == 1, so this could be further simplified. Could be a separate patch though.
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
Benjamin Marzinski
maintainerPATCH 8/12 move waiter code from libmultipath to multipathd
In reply to Benjamin MarzinskiOnly multipathd uses the code in waiter.[ch] and the functions that call it directly, so they should all live in the multipathd directory. This patch is simply moving the waiter.[ch] files and the functions in structs_vec that use them. None of the moved code has been changed.
--- libmultipath/Makefile | 2 +- libmultipath/structs_vec.c | 98 --------------------- libmultipath/structs_vec.h | 4 +- libmultipath/waiter.c | 215 --------------------------------------------- libmultipath/waiter.h | 17 ---- multipathd/Makefile | 2 +- multipathd/main.c | 96 ++++++++++++++++++++ multipathd/waiter.c | 215 +++++++++++++++++++++++++++++++++++++++++++++ multipathd/waiter.h | 17 ++++ 9 files changed, 332 insertions(+), 334 deletions(-) delete mode 100644 libmultipath/waiter.c delete mode 100644 libmultipath/waiter.h create mode 100644 multipathd/waiter.c create mode 100644 multipathd/waiter.h
libmultipath/Makefile +1 -1
@@ -42,7 +42,7 @@ OBJS = memory.o parser.o vector.o devmapper.o callout.o \ pgpolicies.o debug.o defaults.o uevent.o time-util.o \ switchgroup.o uxsock.o print.o alias.o log_pthread.o \ log.o configure.o structs_vec.o sysfs.o prio.o checkers.o \ - lock.o waiter.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \ + lock.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \ io_err_stat.o dm-generic.o generic.o foreign.o all: $(LIBS)
libmultipath/structs_vec.c +0 -98
116 lines not on this page · raw message
libmultipath/structs_vec.h +2 -2
@@ -26,12 +26,12 @@ int update_multipath_strings (struct multipath *mpp, vector pathvec, int is_daemon);void extract_hwe_from_path (struct multipath * mpp); +#define PURGE_VEC 1 +void remove_map (struct multipath * mpp,struct vectors * vecs,int purge_vec);void remove_maps (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,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/waiter.c deleted +0 -215
215 lines not on this page · raw message
libmultipath/waiter.h deleted +0 -17
@@ -1,17 +0,0 @@ -#ifndef _WAITER_H -#define _WAITER_H - -extern pthread_attr_t waiter_attr; - -struct event_thread { -struct dm_task *dmt; -pthread_t thread; -int event_nr; -char mapname[WWID_SIZE ]; -struct vectors *vecs; -}; - -void stop_waiter_thread (struct multipath *mpp,struct vectors *vecs); -int start_waiter_thread (struct multipath *mpp,struct vectors *vecs); - -#endif /* _WAITER_H */
multipathd/Makefile +1 -1
@@ -22,7 +22,7 @@ ifdef SYSTEMD endif endif -OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o +OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o EXEC = multipathd
multipathd/main.c +96 -0
102 lines not on this page · raw message
multipathd/waiter.c new file +215 -0
215 lines not on this page · raw message
multipathd/waiter.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _WAITER_H +#define _WAITER_H + +extern pthread_attr_t waiter_attr; + +struct event_thread { +struct dm_task *dmt; +pthread_t thread; +int event_nr; +char mapname[WWID_SIZE ]; +struct vectors *vecs; +}; + +void stop_waiter_thread (struct multipath *mpp,struct vectors *vecs); +int start_waiter_thread (struct multipath *mpp,struct vectors *vecs); + +#endif /* _WAITER_H */
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 9/12 call start_waiter_thread() before setup_multipath()
In reply to Benjamin MarzinskiIf setup_multipath() is called before the waiter thread has started, there is a window where a dm event can occur between when setup_multipath() updates the device state and when the waiter thread starts waiting for new events, causing the new event to be missed and the multipath device to not get updated.
--- multipathd/main.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
multipathd/main.c +20 -17
@@ -326,7 +326,7 @@ set_multipath_wwid (struct multipath * mpp) }static int -update_map (struct multipath *mpp,struct vectors *vecs) +update_map (struct multipath *mpp,struct vectors *vecs,int new_map) {int retries =3 ;char params[PARAMS_SIZE ] = {0 };
@@ -356,6 +356,12 @@ retry:dm_lib_release (); fail: +if (new_map && (retries <0 ||start_waiter_thread (mpp, vecs))) { +condlog (0 ,"%s: failed to create new map" , mpp->alias); +remove_map (mpp, vecs,1 ); +return 1 ; + } +if (setup_multipath (vecs, mpp))return 1 ;
@@ -400,12 +406,9 @@ add_map_without_path (struct vectors *vecs, const char *alias)vector_set_slot (vecs->mpvec, mpp); -if (update_map (mpp, vecs) !=0 )/* map removed */ +if (update_map (mpp, vecs,1 ) !=0 )/* map removed */ return NULL ; -if (start_waiter_thread (mpp, vecs)) - goto out; -return mpp; out:remove_map (mpp, vecs,PURGE_VEC );
@@ -559,7 +562,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs)if (mpp->wait_for_udev >1 ) {condlog (2 ,"%s: performing delayed actions" , mpp->alias); -if (update_map (mpp, vecs)) +if (update_map (mpp, vecs,0 ))/* setup multipathd removed the map */ return 1 ; }
@@ -870,6 +873,11 @@ retry: }dm_lib_release (); +if ((mpp->action ==ACT_CREATE || + (mpp->action ==ACT_NOTHING && start_waiter && !mpp->waiter)) && +start_waiter_thread (mpp, vecs)) + goto fail_map; +/* * update our state from kernel regardless of create or reload */
@@ -878,11 +886,6 @@ retry:sync_map_state (mpp); -if ((mpp->action ==ACT_CREATE || - (mpp->action ==ACT_NOTHING && start_waiter && !mpp->waiter)) && -start_waiter_thread (mpp, vecs)) - goto fail_map; -if (retries >=0 ) {condlog (2 ,"%s [%s]: path added to devmap %s" , pp->dev, pp->dev_t, mpp->alias);
@@ -1518,7 +1521,8 @@ missing_uev_wait_tick(struct vectors *vecs)if (mpp->wait_for_udev && --mpp->uev_wait_tick <=0 ) { timed_out =1 ;condlog (0 ,"%s: timeout waiting on creation uevent. enabling reloads" , mpp->alias); -if (mpp->wait_for_udev >1 &&update_map (mpp, vecs)) { +if (mpp->wait_for_udev >1 && +update_map (mpp, vecs,0 )) {/* update_map removed map */ i--;continue ;
@@ -1550,7 +1554,7 @@ ghost_delay_tick(struct vectors *vecs)condlog (0 ,"%s: timed out waiting for active path" , mpp->alias); mpp->force_udev_reload =1 ; -if (update_map (mpp, vecs) !=0 ) { +if (update_map (mpp, vecs,0 ) !=0 ) {/* update_map removed map */ i--;continue ;
@@ -2199,14 +2203,13 @@ configure (struct vectors * vecs)* start dm event waiter threads for these new maps */ vector_foreach_slot(vecs->mpvec, mpp, i) { -if (setup_multipath (vecs, mpp)) { - i--; -continue ; - }if (start_waiter_thread (mpp, vecs)) {remove_map (mpp, vecs,1 ); i--; +continue ; } +if (setup_multipath (vecs, mpp)) + i--; }return 0 ; }
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 10/12 libmultipath: add helper functions
In reply to Benjamin MarzinskiAdd the ability to reset a vector without completely freeing it, and to check the version of the device-mapper module. The existing version checking code checks the version of a specific device mapper target, and has been renamed for clarity's sake. These functions will be used in a later patch.
--- libmultipath/devmapper.c | 28 ++++++++++++++++++++++++---- libmultipath/devmapper.h | 3 ++- libmultipath/vector.c | 16 ++++++++++++---- libmultipath/vector.h | 1 + multipathd/main.c | 2 +- 5 files changed, 40 insertions(+), 10 deletions(-)
libmultipath/devmapper.c +24 -4
@@ -130,7 +130,27 @@ dm_lib_prereq (void) }int -dm_drv_version (unsigned int * version,char * str) +dm_drv_version (unsigned int *v) +{ +char buff[64 ]; + + v[0 ] =0 ; + v[1 ] =0 ; + v[2 ] =0 ; + +if (!dm_driver_version (buff,sizeof (buff))) { +condlog (0 ,"cannot get kernel dm version" ); +return 1 ; + } +if (sscanf (buff,"%u.%u.%u " , &v[0 ], &v[1 ], &v[2 ]) !=3 ) { +condlog (0 ,"invalid kernel dm version '%s'" , buff); +return 1 ; + } +return 0 ; +} + +int +dm_tgt_version (unsigned int * version,char * str) {int r =2 ;struct dm_task *dmt;
@@ -177,13 +197,13 @@ out: }static int -dm_drv_prereq (unsigned int *ver) +dm_tgt_prereq (unsigned int *ver) {unsigned int minv[3 ] = {1 ,0 ,3 };unsigned int version[3 ] = {0 ,0 ,0 };unsigned int * v = version; -if (dm_drv_version (v,TGT_MPATH )) { +if (dm_tgt_version (v,TGT_MPATH )) {/* in doubt return not capable */ return 1 ; }
@@ -208,7 +228,7 @@ static int dm_prereq(unsigned int *v) {if (dm_lib_prereq ())return 1 ; -return dm_drv_prereq (v); +return dm_tgt_prereq (v); }static int libmp_dm_udev_sync =0 ;
libmultipath/devmapper.h +2 -1
@@ -31,7 +31,8 @@ void dm_init(int verbosity);void 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,char * str); +int dm_drv_version (unsigned int * version); +int dm_tgt_version (unsigned int * version,char * str);int dm_simplecmd_flush (int ,const char *,uint16_t );int dm_simplecmd_noflush (int ,const char *,uint16_t );int dm_addmap_create (struct multipath *mpp,char *params);
libmultipath/vector.c +12 -4
@@ -145,18 +145,26 @@ vector_repack(vector v)vector_del_slot (v, i--); } -/* Free memory vector allocation */ -void -vector_free (vector v) +vector +vector_reset (vector v) {if (!v) -return ; +return NULL ;if (v->slot)FREE (v->slot); v->allocated =0 ; v->slot =NULL ; +return v; +} + +/* Free memory vector allocation */ +void +vector_free (vector v) +{ +if (!vector_reset (v)) +return ;FREE (v); }
libmultipath/vector.h +1 -0
@@ -74,6 +74,7 @@ typedef struct _vector *vector;/* Prototypes */ extern vector vector_alloc (void );extern void *vector_alloc_slot (vector v); +vector vector_reset (vector v);extern void vector_free (vector v);#define vector_free_const (x) vector_free((vector)(long)(x))extern void free_strvec (vector strvec);
multipathd/main.c +1 -1
@@ -2259,7 +2259,7 @@ reconfigure (struct vectors * vecs)/* Re-read any timezone changes */ tzset (); -dm_drv_version (conf->version,TGT_MPATH ); +dm_tgt_version (conf->version,TGT_MPATH );if (verbosity) conf->verbosity = verbosity;if (bindings_read_only)
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 11/12 multipathd: add new polling dmevents waiter thread
In reply to Benjamin MarzinskiThe current method of waiting for dmevents on multipath devices involves creating a seperate thread for each device. This can become very wasteful when there are large numbers of multipath devices. Also, since multipathd needs to grab the vecs lock to update the devices, the additional threads don't actually provide much parallelism.
The patch adds a new method of updating multipath devices on dmevents, which uses the new device-mapper event polling interface. This means that there is only one dmevent waiting thread which will wait for events on all of the multipath devices. Currently the code to get the event number from the list of device names and to re-arm the polling interface is not in libdevmapper, so the patch does that work. Obviously, these bits need to go into libdevmapper, so that multipathd can use a standard interface.
I haven't touched any of the existing event waiting code, since event polling was only added to device-mapper in version 4.37.0. multipathd checks this version, and defaults to using the polling code if device-mapper supports it. This can be overridden by running multipathd with "-w", to force it to use the old event waiting code.
--- Makefile.inc | 3 + libmultipath/structs_vec.c | 8 + libmultipath/structs_vec.h | 2 + multipathd/Makefile | 6 +- multipathd/dmevents.c | 392 +++++++++++++++++++++++++++++++++++++++++++++ multipathd/dmevents.h | 13 ++ multipathd/main.c | 62 ++++++- 7 files changed, 477 insertions(+), 9 deletions(-) create mode 100644 multipathd/dmevents.c create mode 100644 multipathd/dmevents.h
Makefile.inc +3 -0
@@ -14,6 +14,9 @@ # # Uncomment to disable libdmmp support # ENABLE_LIBDMMP = 0 +# +# Uncomment to disable dmevents polling support +# ENABLE_DMEVENTS_POLL = 0 ifeq ($(TOPDIR),) TOPDIR = ..
libmultipath/structs_vec.c +8 -0
@@ -130,6 +130,14 @@ remove_map(struct multipath * mpp, struct vectors * vecs, int purge_vec) }void +remove_map_by_alias (const char *alias,struct vectors * vecs,int purge_vec) +{ +struct multipath * mpp =find_mp_by_alias (vecs->mpvec, alias); +if (mpp) +remove_map (mpp, vecs, purge_vec); +} + +void remove_maps (struct vectors * vecs) {int i;
libmultipath/structs_vec.h +2 -0
@@ -29,6 +29,8 @@ void extract_hwe_from_path(struct multipath * mpp);#define PURGE_VEC 1void remove_map (struct multipath * mpp,struct vectors * vecs,int purge_vec); +void remove_map_by_alias (const char *alias,struct vectors * vecs, +int purge_vec);void remove_maps (struct vectors * vecs);void sync_map_state (struct multipath *);
multipathd/Makefile +5 -1
@@ -21,8 +21,12 @@ ifdef SYSTEMD LIBDEPS += -lsystemd-daemon endif endif +ifeq ($(ENABLE_DMEVENTS_POLL),0) + CFLAGS += -DNO_DMEVENTS_POLL +endif -OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o +OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o \ + dmevents.o EXEC = multipathd
multipathd/dmevents.c new file +392 -0
392 lines not on this page · raw message
multipathd/dmevents.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _DMEVENTS_H +#define _DMEVENTS_H + +#include "structs_vec.h" + +int dmevent_poll_supported (void ); +int init_dmevent_waiter (struct vectors *vecs); +void cleanup_dmevent_waiter (void ); +int watch_dmevents (char *name); +void unwatch_all_dmevents (void ); +void *wait_dmevents (void *unused); + +#endif /* _DMEVENTS_H */
multipathd/main.c +54 -8
155 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 11/12] multipathd: add new polling dmevents waiter thread
Quoted 29 lines · Benjamin Marzinski
The current method of waiting for dmevents on multipath devices involves
creating a seperate thread for each device. This can become very wasteful when there are large numbers of multipath devices. Also, since
multipathd needs to grab the vecs lock to update the devices, the additional threads don't actually provide much parallelism.The patch adds a new method of updating multipath devices on dmevents,
which uses the new device-mapper event polling interface. This means that there is only one dmevent waiting thread which will wait for events
on all of the multipath devices. Currently the code to get the event number from the list of device names and to re-arm the polling interface
is not in libdevmapper, so the patch does that work. Obviously, these bits need to go into libdevmapper, so that multipathd can use a standard
interface.I haven't touched any of the existing event waiting code, since event polling was only added to device-mapper in version
4.37.0. multipathd
checks this version, and defaults to using the polling code if device-mapper supports it. This can be overridden by running multipathd
with "-w", to force it to use the old event waiting code.
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>
... with some minor nitpicks, see below.
Quoted 15 lines
--- Makefile.inc | 3 + libmultipath/structs_vec.c | 8 + libmultipath/structs_vec.h | 2 + multipathd/Makefile | 6 +- multipathd/dmevents.c | 392 +++++++++++++++++++++++++++++++++++++++++++++ multipathd/dmevents.h | 13 ++ multipathd/main.c | 62 ++++++- 7 files changed, 477 insertions(+), 9 deletions(-) create mode 100644 multipathd/dmevents.c create mode 100644 multipathd/dmevents.h
multipathd/dmevents.c line 124
Quoted 8 lines
multipathd/dmevents.c new file +8
-0+static int arm_dm_event_poll (int fd) +{ +struct dm_ioctl dmi; +memset (&dmi,0 ,sizeof (dmi)); + dmi.version[0 ] =DM_VERSION_MAJOR ; + dmi.version[1 ] =DM_VERSION_MINOR ; + dmi.version[2 ] =DM_VERSION_PATCHLEVEL ; + dmi.flags =0x4 ;
We've had this before, I'd appreciate a short comment explaining this flag as Alasdair did in his post from Feb 13th.
multipathd/dmevents.c line 192
Quoted 3 lines
multipathd/dmevents.c new file +3
-0+ +/* You must call update_multipath() after calling this function, to +* deal with any events that came in before the device was added */
This comment is slightly irritating, because you don't call update_multipath() anywhere where you call watch_dmevents (rather, you call __setup_multipath). I understand the comment is about the order of calls, not about having to call update_multipath(), but that's not immediately obvious.
Quoted 21 lines
multipathd/dmevents.c new file +8
-0+int watch_dmevents (char *name) +{ +int event_nr; +struct dev_event *dev_evt, *old_dev_evt; +int i; + +if (!dm_is_mpath (name)) { + condlog(0, "%s: not a multipath device. can't watchevents",
multipathd/dmevents.c new file +8
-0+ name); +return -1 ; + } + +if ((event_nr =dm_geteventnr (name)) <0 ) +return -1 ; + + dev_evt = (struct dev_event *)malloc(sizeof(struct
dev_event));(quoted diff) +2
-0+ if (!dev_evt) { + condlog(0, "%s: can't allocate event waiterstructure", name);
multipathd/dmevents.c line 215
Quoted 5 lines
multipathd/dmevents.c new file +5
-0+return -1 ; + } + +strncpy (dev_evt->name, name,WWID_SIZE ); + dev_evt->name[WWID_SIZE -1 ] =0 ;
Nitpick: using strlcpy() in new code would simplify code and review.
Review
Quoted 13 lines
multipathd/dmevents.c new file +11
-0+ dev_evt->evt_nr = event_nr; + dev_evt->action =EVENT_NOTHING ; + +pthread_mutex_lock (&waiter->events_lock); + vector_foreach_slot(waiter->events, old_dev_evt, i){ +if (!strcmp (dev_evt->name, old_dev_evt->name)) { +/* caller will be updating this device */ + old_dev_evt->evt_nr = event_nr; + old_dev_evt->action =EVENT_NOTHING ; +pthread_mutex_unlock (&waiter->events_lock); + condlog(2, "%s: already waiting for eventson device",
(quoted diff) +1
-0+ name);
What about using condlog(3) here? Is it something admins need to care about in regular operation?
Quoted 105 lines
multipathd/dmevents.c new file +30
-0+free (dev_evt); +return 0 ; + } + } +if (!vector_alloc_slot (waiter->events)) { +pthread_mutex_unlock (&waiter->events_lock); +free (dev_evt); +return -1 ; + } +vector_set_slot (waiter->events, dev_evt); +pthread_mutex_unlock (&waiter->events_lock); +return 0 ; +} +/* +* returns the reschedule delay +* negative means *stop* +*/ + +/* poll, arm, update, return */ +static int dmevent_loop (void ) +{ +int r, i =0 ; +struct pollfd pfd; +struct dev_event *dev_evt; + + pfd.fd = waiter->fd; + pfd.events =POLLIN ; + r =poll (&pfd,1 ,-1 ); +if (r <=0 ) { + condlog(0, "failed polling for dm events: %s",strerror(errno));
multipathd/dmevents.c new file +6
-0+/* sleep 1s and hope things get better */ +return 1 ; + } + +if (arm_dm_event_poll (waiter->fd) !=0 ) { + condlog(0, "Cannot re-arm event polling: %s",strerror(errno));
multipathd/dmevents.c new file +6
-0+/* sleep 1s and hope things get better */ +return 1 ; + } + +if (dm_get_events () !=0 ) { + condlog(0, "failed getting dm events: %s",strerror(errno));
multipathd/dmevents.c new file +17
-0+/* sleep 1s and hope things get better */ +return 1 ; + } + +/* +* upon event ... +*/ + +while (1 ) { +int done =1 ; +struct dev_event curr_dev; + +pthread_mutex_lock (&waiter->events_lock); + vector_foreach_slot(waiter->events, dev_evt, i) { +if (dev_evt->action !=EVENT_NOTHING ) { + curr_dev = *dev_evt; +if (dev_evt->action ==EVENT_REMOVE ){
(quoted diff) +1
-0+ vector_del_slot(waiter-Quoted 1 line
events, i);
multipathd/dmevents.c new file +3
-0+free (dev_evt); + }else + dev_evt->action =
EVENT_NOTHING;multipathd/dmevents.c new file +15
-0+ done =0 ; +break ; + } + } +pthread_mutex_unlock (&waiter->events_lock); +if (done) +return 1 ; + +condlog (3 ,"%s: devmap event #%i" , curr_dev.name, + curr_dev.evt_nr); + +/* +* event might be : +* +* 1) a table reload, which means our mpp structure is
(quoted diff) +1
-0+ * obsolete : refresh it through
update_multipath()multipathd/dmevents.c new file +7
-0+* 2) a path failed by DM : mark as such through +* update_multipath() +* 3) map has gone away : stop the thread. +* 4) a path reinstate : nothing to do +* 5) a switch group : nothing to do +*/ + pthread_cleanup_push(cleanup_lock, &waiter->vecs-Quoted 1 line
lock);
multipathd/dmevents.c new file +5
-0+lock (&waiter->vecs->lock); +pthread_testcancel (); + r =0 ; +if (curr_dev.action ==EVENT_REMOVE ) + remove_map_by_alias(curr_dev.name, waiter-Quoted 1 line
vecs, 1);
(quoted diff) +2
-0+ else + r = update_multipath(waiter->vecs,curr_dev.name, 1);
multipathd/dmevents.c line 350
Quoted 1 line
multipathd/dmevents.c new file +1
-0+lock_cleanup_pop (&waiter->vecs->lock);
I dislike lock_cleanup_pop(). pthread_cleanup_pop(1) would be so much more obvious.
Regards,
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
Benjamin Marzinski
maintainerPATCH 12/12 multipath: add unit tests for dmevents code
In reply to Benjamin MarzinskiThese unit tests do not get complete code coverage. Also, they don't check for memory errors. To do this through unit tests, instead of using valgrid, would require adding unit test specific compilation defines to the code, and compiling a seperate unit-test version.
--- tests/Makefile | 9 +- tests/dmevents.c | 847 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 853 insertions(+), 3 deletions(-) create mode 100644 tests/dmevents.c
tests/Makefile +6 -3
@@ -3,11 +3,16 @@ include ../Makefile.inc CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka -TESTS := uevent parser util +TESTS := uevent parser util dmevents .SILENT: $(TESTS:%=%.o) .PRECIOUS: $(TESTS:%=%-test) +all: $(TESTS:%=%.out) + +dmevents-test: dmevents.o ../multipathd/dmevents.c globals.c $(multipathdir)/libmultipath.so + @$(CC) -o $@ $< $(LDFLAGS) $(LIBDEPS) -lpthread -ldevmapper -lurcu -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=dm_is_mpath -Wl,--wrap=dm_geteventnr -Wl,--wrap=ioctl -Wl,--wrap=libmp_dm_task_create -Wl,--wrap=dm_task_no_open_count -Wl,--wrap=dm_task_run -Wl,--wrap=dm_task_get_names -Wl,--wrap=dm_task_destroy -Wl,--wrap=poll -Wl,--wrap=remove_map_by_alias -Wl,--wrap=update_multipath + %-test: %.o globals.c $(multipathdir)/libmultipath.so @$(CC) -o $@ $< $(LDFLAGS) $(LIBDEPS)
@@ -15,8 +20,6 @@ TESTS := uevent parser util @echo == running $< == @LD_LIBRARY_PATH=$(multipathdir):$(mpathcmddir) ./$< >$@ -all: $(TESTS:%=%.out) - clean: dep_clean rm -f $(TESTS:%=%-test) $(TESTS:%=%.out) $(TESTS:%=%.o)
tests/dmevents.c new file +847 -0
847 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 12/12] multipath: add unit tests for dmevents code
Quoted 6 lines · Benjamin Marzinski
These unit tests do not get complete code coverage. Also, they don't check for memory errors. To do this through unit tests, instead of using valgrid, would require adding unit test specific compilation defines to the code, and compiling a seperate unit-test version.
Signed-off-by Benjamin Marzinski <[email protected]>
I'm impressed, you went much further with cmocka than I did so far. Nice work.
... but this is pretty dense material. I'd appreciate a follow-up patch adding some comments about the more complex test cases to make them easier to understand.
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
Benjamin Marzinski
maintainerOoops. I accidentally used your old email for this patchset, Christophe.
-Ben
Quoted 96 lines · Benjamin Marzinski
Patches 1-5 are minor bug fixes and a unit test for basenamecpy.
Patch 6 is revised version of my nanosleep patch, that only changes the checkerloop code, since that is the only time when multipathd actually sets an alarm without locking.
Patches 7-11 are a rebase of my "alternate dmevents waiter method" patchset. The only code that has changed outside of rebasing them is in patch 11. It adds a function,
remove_map_by_alias(), and uses it indmevent_loop(). This simply moves the code the gets the multipath device out ofdmevents.c, so it can work exclusively in device names. It also changes the names of the functions the initialize and cleanup the dmevents polling code to match similar multipathd functions and adds aMakefiledefine to disable using the polling code, both suggested by Martin Wilck.Patch 12 is unit testing code for the new code in
dmevents.cHere is the description from my initial posting of the alternate dmevents waiter method" patchset:
This patchset implements a new method of getting dmevents for multipathd.
With the existing wait code, multipathd needs to create a waiter thread for every multipath device. This can become very wasteful in setups with large numbers of multipath devices. These duplicate threads all are serialized to update the multipath devices, so they don't actually speed up dmevent handling.
The new method uses the new dmevent polling ability introduced in the 4.37.0 device-mapper kernel module. The original method has been retained for backwards compatablility, and it is possible to force multipathd to use the orignal method on newer kernels. The benefit of this new method is that there is only one thread necessary to wait on dmevents, which can be started when device-mapper starts, and stopped during shutdown, just like the other main threads.
These patches use device-mapper features that don't have a libdevmapper API. They will switch over as soon as support is available in libdevmapper.
Benjamin Marzinski (12):
Unit tests for basenamecpy
libmultipath: fix basenamecpy
libmultipath: setdm_conf_verbosity
multipathd: log thread cleanup
libmultipath: fixlog_pthreadprocessing
multipathd: use nanosleep for strict timing
libmultipath: moveremove_mapwaiter code to multipathd move waiter code from libmultipath to multipathd callstart_waiter_thread()beforesetup_multipath()
libmultipath: add helper functions
multipathd: add new polling dmevents waiter thread
multipath: add unit tests for dmevents codeMakefile.inc | 3 + libmultipath/Makefile | 2 +- libmultipath/devmapper.c | 29 +- libmultipath/devmapper.h | 3 +- libmultipath/log_pthread.c | 40 +-- libmultipath/log_pthread.h | 10 +- libmultipath/structs_vec.c | 140 +------- libmultipath/structs_vec.h | 8 +- libmultipath/util.c | 25 +- libmultipath/util.h | 2 +- libmultipath/vector.c | 16 +- libmultipath/vector.h | 1 + libmultipath/waiter.c | 215 ------------ libmultipath/waiter.h | 17 - multipathd/Makefile | 6 +- multipathd/dmevents.c | 392 +++++++++++++++++++++ multipathd/dmevents.h | 13 + multipathd/main.c | 230 ++++++++++-- multipathd/waiter.c | 215 ++++++++++++ multipathd/waiter.h | 17 + tests/Makefile | 9 +- tests/dmevents.c | 847 +++++++++++++++++++++++++++++++++++++++++++++ tests/util.c | 167 +++++++++ 23 files changed, 1944 insertions(+), 463 deletions(-) delete mode 100644 libmultipath/waiter.c delete mode 100644 libmultipath/waiter.h create mode 100644 multipathd/dmevents.c create mode 100644 multipathd/dmevents.h create mode 100644 multipathd/waiter.c create mode 100644 multipathd/waiter.h create mode 100644 tests/dmevents.c create mode 100644 tests/util.cSignature · 6 lines
2.7.4 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel