Fifteen multipath-tools patches
cover Fifteen multipath-tools patches
Hello Christophe,
It would be appreciated if you would consider this patch series for inclusion in the multipath-tools repository. The changes in this patch series are:
- A build fix for musl-libc.
- A fix for a deadlock during shutdown.
- A bunch of patches that address warnings reported by the sparse
static analyzer.
Thanks,
Bart.
PATCH 1/15 libmultipath: Make building against musl-libc again possible
musl-libc does not support PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP.
This patch reverts commit 7884bde302ad ("multipathd: Avoid that a deadlock is triggered sporadically during shutdown").
--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/uevent.c +1 -1
@@ -52,7 +52,7 @@ typedef int (uev_trigger)(struct uevent *, void * trigger_data);pthread_t uevq_thr;LIST_HEAD (uevq); -pthread_mutex_t uevq_lock =PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ; +pthread_mutex_t uevq_lock =PTHREAD_MUTEX_INITIALIZER ;pthread_mutex_t *uevq_lockp = &uevq_lock;pthread_cond_t uev_cond =PTHREAD_COND_INITIALIZER ;pthread_cond_t *uev_condp = &uev_cond;
Signature · 1 line
2.10.1
PATCH 2/15 libmultipath: Avoid that thread cancellation causes a hang
In reply to Bart Van AsscheApparently uevq_stop() hangs every now and then in pthread_mutex_lock() if the udev listener thread is canceled. Avoid this hang by removing code from uevq_stop(). This is safe because uevq_stop() is only called just before uevent_listen() returns and in that case neither clearing my_uev_trigger nor signaling uev_condp is needed. Additionally, rename uevq_stop() into uevent_cleanup() to make clear that its purpose is to clean up resources and not to stop the uevent listener.
--- libmultipath/uevent.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
libmultipath/uevent.c +3 -7
@@ -124,15 +124,11 @@ service_uevq(struct list_head *tmpq) } } -static void uevq_stop (void *arg) +static void uevent_cleanup (void *arg) {struct udev *udev = arg; -condlog (3 ,"Stopping uev queue" ); -pthread_mutex_lock (uevq_lockp); - my_uev_trigger =NULL ; -pthread_cond_signal (uev_condp); -pthread_mutex_unlock (uevq_lockp); +condlog (3 ,"Releasing uevent_listen() resources" );udev_unref (udev); }
@@ -495,7 +491,7 @@ int uevent_listen(struct udev *udev)return 1 ; }udev_ref (udev); -pthread_cleanup_push (uevq_stop, udev); +pthread_cleanup_push (uevent_cleanup, udev); monitor =udev_monitor_new_from_netlink (udev,"udev" );if (!monitor) {
Signature · 1 line
2.10.1
PATCH 3/15 libmultipath: Remove an incorrect comment
In reply to Bart Van AsscheIt is easy to see that uevq_lockp is not held while service_uevq() is called. Since no other code accesses the list that is processed by this function calling service_uevq() without holding uevq_lockp is safe. Hence remove the comment about locking above service_uevq().
--- libmultipath/uevent.c | 3 --- 1 file changed, 3 deletions(-)
libmultipath/uevent.c +0 -3
@@ -104,9 +104,6 @@ setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached) } } -/* -* Called with uevq_lockp held -*/ void service_uevq (struct list_head *tmpq) {
Signature · 1 line
2.10.1
PATCH 4/15 libmultipath: Move setup_thread_attr() from uevent.c into util.c
In reply to Bart Van AsscheThe setup_thread_attr() is not called by any code in source file uevent.c. Hence move that function to source file util.c.
--- libmultipath/checkers/rbd.c | 2 +- libmultipath/checkers/tur.c | 2 +- libmultipath/uevent.c | 25 ------------------------- libmultipath/uevent.h | 1 - libmultipath/util.c | 25 +++++++++++++++++++++++-- libmultipath/util.h | 1 + 6 files changed, 26 insertions(+), 30 deletions(-)
libmultipath/checkers/rbd.c +1 -1
@@ -26,7 +26,7 @@#include "checkers.h" #include "../libmultipath/debug.h" -#include "../libmultipath/uevent.h" +#include "../libmultipath/util.h" #include "../libmultipath/time-util.h" struct rbd_checker_context ;
libmultipath/checkers/tur.c +1 -1
@@ -19,7 +19,7 @@#include "../libmultipath/debug.h" #include "../libmultipath/sg_include.h" -#include "../libmultipath/uevent.h" +#include "../libmultipath/util.h" #include "../libmultipath/time-util.h" #include "../libmultipath/util.h"
libmultipath/uevent.c +0 -25
@@ -37,7 +37,6 @@#include <linux/types.h> #include <linux/netlink.h> #include <pthread.h> -#include <limits.h> #include <sys/mman.h> #include <libudev.h> #include <errno.h>
@@ -81,30 +80,6 @@ struct uevent * alloc_uevent (void) }void -setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached) -{ -if (pthread_attr_init (attr)) { -fprintf (stderr,"can't initialize thread attr: %s\n" , -strerror (errno)); -exit (1 ); - } -if (stacksize <PTHREAD_STACK_MIN ) - stacksize =PTHREAD_STACK_MIN ; - -if (pthread_attr_setstacksize (attr, stacksize)) { -fprintf (stderr,"can't set thread stack size to %lu: %s\n" , - (unsigned long )stacksize,strerror (errno)); -exit (1 ); - } -if (detached &&pthread_attr_setdetachstate (attr, -PTHREAD_CREATE_DETACHED )) { -fprintf (stderr,"can't set thread to detached: %s\n" , -strerror (errno)); -exit (1 ); - } -} - -void service_uevq (struct list_head *tmpq) {struct uevent *uev, *tmp;
libmultipath/uevent.h +0 -1
@@ -27,7 +27,6 @@ struct uevent { };int is_uevent_busy (void ); -void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached);int uevent_listen (struct udev *udev); int uevent_dispatch(int (*store_uev)(struct uevent *, void * trigger_data),
libmultipath/util.c +23 -2
@@ -1,7 +1,10 @@ -#include <string.h> +#include <assert.h> #include <ctype.h> -#include <sys/types.h> +#include <limits.h> +#include <pthread.h> +#include <string.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> #include "debug.h"
@@ -258,3 +261,21 @@ dev_t parse_devt(const char *dev_t)return makedev (maj, min); } + +void +setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached) +{ +int ret; + + ret =pthread_attr_init (attr); +assert (ret ==0 ); +if (stacksize <PTHREAD_STACK_MIN ) + stacksize =PTHREAD_STACK_MIN ; + ret =pthread_attr_setstacksize (attr, stacksize); +assert (ret ==0 ); +if (detached) { + ret =pthread_attr_setdetachstate (attr, +PTHREAD_CREATE_DETACHED ); +assert (ret ==0 ); + } +}
libmultipath/util.h +1 -0
@@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_t size);int devt2devname (char *,int ,char *);dev_t parse_devt (const char *dev_t);char *convert_dev (char *dev,int is_path_device); +void setup_thread_attr (pthread_attr_t *attr,size_t stacksize,int detached); #define safe_sprintf(var, format, args...) \ snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
Signature · 1 line
2.10.1
PATCH 5/15 libmultipath: Fix POLLIN checks
In reply to Bart Van AsscheInstead of testing (pfd.revents == 0) & 1, test whether (pfd.revents & 1) == 0.
This has been detected by the sparse static analyzer.
--- libmpathcmd/mpath_cmd.c | 2 +- libmultipath/uxsock.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
libmpathcmd/mpath_cmd.c +1 -1
@@ -31,7 +31,7 @@ static ssize_t read_all(int fd, void *buf, size_t len, unsigned int timeout)if (errno ==EINTR )continue ;return -1 ; - }else if (!pfd.revents &POLLIN ) + }else if (!(pfd.revents &POLLIN ))continue ; n =recv (fd, buf, len,0 );if (n <0 ) {
libmultipath/uxsock.c +1 -1
@@ -116,7 +116,7 @@ ssize_t read_all(int fd, void *buf, size_t len, unsigned int timeout)if (errno ==EINTR )continue ;return -errno; - }else if (!pfd.revents &POLLIN ) + }else if (!(pfd.revents &POLLIN ))continue ; n =read (fd, buf, len);if (n <0 ) {
Signature · 1 line
2.10.1
PATCH 6/15 libmultipath: Remove an unused function
In reply to Bart Van AsscheThe function snprint_config() is not used. Hence remove it.
--- libmultipath/print.c | 6 ------ 1 file changed, 6 deletions(-)
libmultipath/print.c +0 -6
@@ -1745,12 +1745,6 @@ snprint_devices (struct config *conf, char * buff, int len, struct vectors *vecsreturn fwd; } -extern int -snprint_config (char * buff,int len) -{ -return 0 ; -} -/* * stdout printing helpers */
Signature · 1 line
2.10.1
Re: [PATCH 06/15] libmultipath: Remove an unused function
Removing functions packaged in a library just because they are not used in multipath does not seem fine, in general. They could still be used by third party.
Germano
Quoted 25 lines · Bart Van Assche
The function
snprint_config()is not used. Hence remove it.Signed-off-by Bart Van Assche <[email protected]>--- libmultipath/print.c | 6 ------ 1 file changed, 6 deletions(-)libmultipath/print.c +0
-6@@ -1745,12 +1745,6 @@ snprint_devices (struct config *conf, char * buff, int len, struct vectors *vecsreturn fwd; } -extern int -snprint_config (char * buff,int len) -{ -return 0 ; -} -/* * stdout printing helpers */
Re: [PATCH 06/15] libmultipath: Remove an unused function
Quoted 16 lines · Germano Percossi
Quoted 15 lines · Bart Van Assche
The function
snprint_config()is not used. Hence remove it.Signed-off-by Bart Van Assche <[email protected]>--- libmultipath/print.c | 6 ------ 1 file changed, 6 deletions(-)libmultipath/print.c +0
-0@@ -1745,12 +1745,6 @@ snprint_devices (struct config *conf, char * buff, int len, struct vectors *vecsreturn fwd; }
Quoted 13 lines
libmultipath/print.c snprint_devices (struct config *conf, char * buff, int len, struct vectors *vecs · line 1750
Quoted 9 lines
libmultipath/print.c +0
-6-extern int -snprint_config (char * buff,int len) -{ -return 0 ; -} -/* * stdout printing helpers */ Removing functions packaged in a library just because they are not used in multipath does not seem fine, in general. They could still be used by third party.
Hello Germano,
The snprint_config() function has never been declared in any multipath-tools header file so if someone would want to use this function without triggering a compiler warning they would have to add something like "extern int snprint_config (char * buff, int len)" to their source code. Because of this reason and also because of the empty implementation I think that is unlikely that any project is using this function.
Bart.
Re: [PATCH 06/15] libmultipath: Remove an unused function
Sorry, my reply was meant for mpath_prin_pthread_fn patch but, I guess, given the lack of a declaration in a header file, your answer will be the same.
Germano
Quoted 44 lines · Bart Van Assche
Quoted 17 lines · Germano Percossi
Quoted 16 lines · Bart Van Assche
The function
snprint_config()is not used. Hence remove it.Signed-off-by Bart Van Assche <[email protected]>--- libmultipath/print.c | 6 ------ 1 file changed, 6 deletions(-)libmultipath/print.c +0
-0@@ -1745,12 +1745,6 @@ snprint_devices (struct config *conf, char *buff, int len, struct vectors *vecs
return fwd;}
Quoted 13 lines
libmultipath/print.c snprint_devices (struct config *conf, char * buff, int len, struct vectors *vecs · line 1750
Quoted 9 lines
libmultipath/print.c +0
-6-extern int -snprint_config (char * buff,int len) -{ -return 0 ; -} -/* * stdout printing helpers */ Removing functions packaged in a library just because they are not used in multipath does not seem fine, in general. They could still be used by third party.
Hello Germano,
The
snprint_config()function has never been declared in any multipath-tools header file so if someone would want to use this function without triggering a compiler warning they would have to add something like "extern intsnprint_config(char * buff, int len)" to their source code. Because of this reason and also because of the empty implementation I think that is unlikely that any project is using this function.Bart.
Re: [PATCH 06/15] libmultipath: Remove an unused function
Quoted 3 lines · Germano Percossi
Sorry, my reply was meant for
mpath_prin_pthread_fnpatch but, I guess, given the lack of a declaration in a header file, your answer will be the same.
Hello Germano,
Inspection of the git log -p output learned me that also mpath_prin_pthread_fn() was never declared in any multipath-tools header file.
Bart.
PATCH 7/15 libmpathpersist: Remove an unused function
In reply to Bart Van Assche--- libmpathpersist/mpath_persist.c | 11 ----------- 1 file changed, 11 deletions(-)
libmpathpersist/mpath_persist.c +0 -11
@@ -414,17 +414,6 @@ get_mpvec (vector curmp, vector pathvec, char * refwwid)return MPATH_PR_SUCCESS ; } -void *mpath_prin_pthread_fn (void *p) -{ -int ret; -struct prin_param * pparam = (struct prin_param *)p; - - ret =prin_do_scsi_ioctl (pparam->dev, pparam->rq_servact, - pparam->resp, pparam->noisy); - pparam->status = ret; -pthread_exit (NULL ); -} -int mpath_send_prin_activepath (char * dev,int rq_servact,struct prin_resp * resp,int noisy) {
Signature · 1 line
2.10.1
PATCH 8/15 libmultipath: Remove an unused variable
In reply to Bart Van Assche--- libmultipath/uevent.c | 1 - 1 file changed, 1 deletion(-)
libmultipath/uevent.c +0 -1
@@ -49,7 +49,6 @@typedef int (uev_trigger )(struct uevent *,void * trigger_data); -pthread_t uevq_thr;LIST_HEAD (uevq);pthread_mutex_t uevq_lock =PTHREAD_MUTEX_INITIALIZER ;pthread_mutex_t *uevq_lockp = &uevq_lock;
Signature · 1 line
2.10.1
PATCH 9/15 libmultipath/checkers/rbd: Use unsigned int for one-bit bitfields
In reply to Bart Van AsscheAvoid that this bitfield is sign-extended. Detected by sparse.
--- libmultipath/checkers/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/checkers/rbd.c +1 -1
@@ -46,7 +46,7 @@ struct rbd_checker_context {char *username;int remapped;int blacklisted; - int lock_on_read:1; + unsigned lock_on_read:1;rados_t cluster;
Signature · 1 line
2.10.1
PATCH 10/15 libmultipath: Move the definition of a global variable from .h to .c
In reply to Bart Van AsscheThis change does not change the semantics of the code but makes it easier for sparse to analyze the source code.
--- libmultipath/log.c | 2 ++ libmultipath/log.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
libmultipath/log.c +2 -0
@@ -15,6 +15,8 @@#define ALIGN (len, s) (((len)+(s)-1)/(s)*(s)) +struct logarea * la; +#if LOGDBG static void dump_logarea (void ) {
libmultipath/log.h +1 -1
@@ -29,7 +29,7 @@ struct logarea {char * buff; }; -struct logarea * la; +extern struct logarea * la;int log_init (char * progname,int size);void log_close (void );
Signature · 1 line
2.10.1
PATCH 11/15 libmpathpersist: Move the definition of a global variable from .h to .c
In reply to Bart Van Assche--- libmpathpersist/mpath_persist.c | 1 + libmpathpersist/mpathpr.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
libmpathpersist/mpath_persist.c +1 -0
@@ -35,6 +35,7 @@#define __STDC_FORMAT_MACROS 1struct udev *udev; +struct config *conf;struct config *mpath_lib_init (struct udev *udev)
libmpathpersist/mpathpr.h +1 -1
@@ -26,7 +26,7 @@ struct threadinfo { }; -struct config * conf; +extern struct config *conf;int prin_do_scsi_ioctl (char * dev,int rq_servact,struct prin_resp * resp,int noisy);
Signature · 1 line
2.10.1
PATCH 12/15 Use NULL instead of 0 where a pointer is expected
In reply to Bart Van AsscheThis was detected by sparse.
--- kpartx/lopart.c | 2 +- libmultipath/checkers/rbd.c | 2 +- mpathpersist/main.h | 48 ++++++++++++++++++++++----------------------- 3 files changed, 26 insertions(+), 26 deletions(-)
kpartx/lopart.c +1 -1
@@ -228,7 +228,7 @@ find_unused_loop_device (void) " maybe /dev/loop# has the wrong major number?"); }else fprintf (stderr,"mount: could not find any free loop device" ); -return 0 ; +return NULL ; } extern int
libmultipath/checkers/rbd.c +1 -1
@@ -464,7 +464,7 @@ static int rbd_rm_blacklist(struct rbd_checker_context *ct) cmd[1 ] =NULL ; ret =rados_mon_command (ct->cluster, (const char **)cmd,1 ,"" ,0 , -NULL ,0 , &stat, &stat_len); +NULL ,NULL , &stat, &stat_len);if (ret <0 ) {condlog (1 ,"rbd%d: repair failed to remove blacklist for %s %d" , ct->rbd_bus_id, ct->client_addr, ret);
mpathpersist/main.h +24 -24
52 lines not on this page · raw message
Signature · 1 line
2.10.1
PATCH 13/15 libmultipath/prioritizers: Make getprio() prototypes consistent
In reply to Bart Van AsscheAdditionally, ensure that the compiler checks the getprio() prototype.
--- libmultipath/prio.h | 3 +++ libmultipath/prioritizers/const.c | 2 +- libmultipath/prioritizers/datacore.c | 2 +- libmultipath/prioritizers/iet.c | 2 +- libmultipath/prioritizers/random.c | 2 +- libmultipath/prioritizers/weightedpath.c | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-)
libmultipath/prio.h +3 -0
@@ -64,4 +64,7 @@ char * prio_name (struct prio *);char *prio_args (struct prio *);int prio_set_args (struct prio *,char *); +/* The only function exported by prioritizer dynamic libraries (.so) */ +int getprio (struct path *,char *,unsigned int ); +#endif /* _PRIO_H */
libmultipath/prioritizers/const.c +1 -1
@@ -2,7 +2,7 @@#include "prio.h" -int getprio (struct path * pp,char * args) +int getprio (struct path * pp,char * args,unsigned int timeout) {return 1 ; }
libmultipath/prioritizers/datacore.c +1 -1
@@ -106,7 +106,7 @@ int datacore_prio (const char *dev, int sg_fd, char * args)return 0 ; } -int getprio (struct path * pp,char * args) +int getprio (struct path * pp,char * args,unsigned int timeout) {return datacore_prio (pp->dev, pp->fd, args); }
libmultipath/prioritizers/iet.c +1 -1
@@ -138,7 +138,7 @@ int iet_prio(const char *dev, char * args)return 10 ; } -int getprio (struct path * pp,char * args) +int getprio (struct path * pp,char * args,unsigned int timeout) {return iet_prio (pp->dev, args); }
libmultipath/prioritizers/random.c +1 -1
@@ -5,7 +5,7 @@#include "prio.h" -int getprio (struct path * pp,char * args) +int getprio (struct path * pp,char * args,unsigned int timeout) {struct timeval tv;
libmultipath/prioritizers/weightedpath.c +1 -1
@@ -151,7 +151,7 @@ int prio_path_weight(struct path *pp, char *prio_args)return priority; } -int getprio (struct path *pp,char *args) +int getprio (struct path *pp,char *args,unsigned int timeout) {return prio_path_weight (pp, args); }
Signature · 1 line
2.10.1
PATCH 14/15 libmultipath/checkers: Make the compiler check the checker function prototypes
In reply to Bart Van Assche--- libmultipath/checkers.h | 6 ++++++ 1 file changed, 6 insertions(+)
libmultipath/checkers.h +6 -0
@@ -142,4 +142,10 @@ char * checker_message (struct checker *);void checker_clear_message (struct checker *c);void checker_get (char *,struct checker *,char *); +/* Functions exported by path checker dynamic libraries (.so) */ +int libcheck_check (struct checker *); +int libcheck_init (struct checker *); +void libcheck_free (struct checker *); +void libcheck_repair (struct checker *); +#endif /* _CHECKERS_H */
Signature · 1 line
2.10.1
PATCH 15/15 kpartx: Move the declaration of a global variable from .c to .h
In reply to Bart Van Assche--- kpartx/gpt.c | 1 - kpartx/kpartx.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-)
kpartx/gpt.c +0 -1
@@ -504,7 +504,6 @@ compare_gpts(gpt_header *pgpt, gpt_header *agpt, uint64_t lastlba)static int find_valid_gpt (int fd,gpt_header ** gpt,gpt_entry ** ptes) { -extern int force_gpt;int good_pgpt =0 , good_agpt =0 , good_pmbr =0 ;gpt_header *pgpt =NULL , *agpt =NULL ;gpt_entry *pptes =NULL , *aptes =NULL ;
kpartx/kpartx.h +2 -0
@@ -39,6 +39,8 @@ struct slice {typedef int (ptreader )(int fd,struct slice all,struct slice *sp,int ns); +extern int force_gpt; +extern ptreader read_dos_pt;extern ptreader read_bsd_pt;extern ptreader read_solaris_pt;
Signature · 1 line
2.10.1