More Misc Multipath patches
Benjamin Marzinski
maintainercover More Misc Multipath patches
Here are the patches that I've built up while getting my last batch accepted, as well as a change for the tur checker to hopefully address Martin's short term objections to commit 455242d (libmultipath: fix tur checker timeout).
Benjamin Marzinski (6):
multipath: tweak logging style
multipathd: check for NULL udevice in cli_add_path
libmultipath: remove max_fds code duplication
multipathd: set return code for multipathd commands
mpathpersist: fix registration rollback issue
libmultipath: timeout on unresponsive tur thread
libmpathpersist/mpath_persist.c | 16 +++------------- libmultipath/checkers/tur.c | 6 +++--- libmultipath/devmapper.c | 8 ++++---- libmultipath/util.c | 31 +++++++++++++++++++++++++++++++ libmultipath/util.h | 1 + multipath/main.c | 12 +----------- multipathd/cli_handlers.c | 4 ++++ multipathd/main.c | 41 +++++++++-------------------------------- multipathd/uxclnt.c | 13 ++++++++----- 9 files changed, 64 insertions(+), 68 deletions(-)
Signature · 1 line
2.7.4
Benjamin Marzinski
maintainerPATCH 1/6 multipath: tweak logging style
When multipathd commands are run, errors should be printed to stderr, instead of syslog. Also, when the multipath is run and calls device-mapper, device-mapper should log to stderr instead of stdout, just like multipath does now.
--- libmultipath/devmapper.c | 8 ++++---- multipathd/main.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)
libmultipath/devmapper.c +4 -4
@@ -80,11 +80,11 @@ dm_write_log (int level, const char *file, int line, const char *f, ...)strftime (buff,sizeof (buff),"%b %d %H:%M:%S" , tb); buff[sizeof (buff)-1 ] ='\0' ; -fprintf (stdout,"%s | " , buff); +fprintf (stderr,"%s | " , buff); } -fprintf (stdout,"libdevmapper: %s(%i): " , file, line); -vfprintf (stdout, f, ap); -fprintf (stdout,"\n" ); +fprintf (stderr,"libdevmapper: %s(%i): " , file, line); +vfprintf (stderr, f, ap); +fprintf (stderr,"\n" ); }else {condlog (level,"libdevmapper: %s(%i): " , file, line);log_safe (level +3 , f, ap);
multipathd/main.c +2 -0
@@ -2984,6 +2984,7 @@ main (int argc, char *argv[]) logsink =-1 ;break ;case 'k' : + logsink =0 ; conf =load_config (DEFAULT_CONFIGFILE );if (!conf)exit (1 );
@@ -3013,6 +3014,7 @@ main (int argc, char *argv[])char * s = cmd;char * c = s; + logsink =0 ; conf =load_config (DEFAULT_CONFIGFILE );if (!conf)exit (1 );
Signature · 1 line
2.7.4
Re: [PATCH 1/6] multipath: tweak logging style
Quoted 6 lines · Benjamin Marzinski
When multipathd commands are run, errors should be printed to stderr, instead of syslog. Also, when the multipath is run and calls device-mapper, device-mapper should log to stderr instead of stdout, just like multipath does now.
Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 9 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/6 multipathd: check for NULL udevice in cli_add_path
In reply to Benjamin MarzinskiIf cli_add_path can't get a udevice for the path, it should fail immediately, instead of continuing with a NULL udevice, since it will fail in store_pathinfo() anyway.
--- multipathd/cli_handlers.c | 4 ++++ 1 file changed, 4 insertions(+)
multipathd/cli_handlers.c +4 -0
@@ -720,6 +720,10 @@ cli_add_path (void * v, char ** reply, int * len, void * data) udevice =udev_device_new_from_subsystem_sysname (udev,"block" , param); +if (!udevice) { +condlog (0 ,"%s: can't find path" , param); +return 1 ; + } conf =get_multipath_config ();pthread_cleanup_push (put_multipath_config, conf); r = store_pathinfo(vecs->pathvec, conf,
Signature · 1 line
2.7.4
Re: [PATCH 2/6] multipathd: check for NULL udevice in cli_add_path
Quoted 5 lines · Benjamin Marzinski
If
cli_add_pathcan't get a udevice for the path, it should fail immediately, instead of continuing with a NULL udevice, since it will fail instore_pathinfo()anyway.Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 9 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 3/6 libmultipath: remove max_fds code duplication
In reply to Benjamin MarzinskiInstead of multipath, multipathd, and mpathpersist all having code to set the max number of open file descriptors, just use a util function to do it.
--- libmpathpersist/mpath_persist.c | 11 +---------- libmultipath/util.c | 31 +++++++++++++++++++++++++++++++ libmultipath/util.h | 1 + multipath/main.c | 12 +----------- multipathd/main.c | 31 +++---------------------------- 5 files changed, 37 insertions(+), 49 deletions(-)
libmpathpersist/mpath_persist.c +1 -10
@@ -31,7 +31,6 @@#include <stdlib.h> #include <string.h> #include <errno.h> -#include <sys/resource.h> #define __STDC_FORMAT_MACROS 1
@@ -48,15 +47,7 @@ mpath_lib_init (void)return NULL ; } -if (conf->max_fds) { -struct rlimit fd_limit; - - fd_limit.rlim_cur = conf->max_fds; - fd_limit.rlim_max = conf->max_fds; -if (setrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) -condlog (0 ,"can't set open fds limit to %d : %s" , - conf->max_fds,strerror (errno)); - } +set_max_fds (conf->max_fds);return conf; }
libmultipath/util.c +31 -0
@@ -7,6 +7,8 @@#include <sys/sysmacros.h> #include <sys/types.h> #include <sys/utsname.h> +#include <sys/time.h> +#include <sys/resource.h> #include <dirent.h> #include <unistd.h> #include <errno.h>
@@ -465,3 +467,32 @@ int safe_write(int fd, const void *buf, size_t count) }return 0 ; } + +void set_max_fds (int max_fds) +{ +struct rlimit fd_limit; + +if (!max_fds) +return ; + +if (getrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) { +condlog (0 ,"can't get open fds limit: %s" , +strerror (errno)); + fd_limit.rlim_cur =0 ; + fd_limit.rlim_max =0 ; + } +if (fd_limit.rlim_cur < max_fds) { + fd_limit.rlim_cur = max_fds; +if (fd_limit.rlim_max < max_fds) + fd_limit.rlim_max = max_fds; +if (setrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) { +condlog (0 ,"can't set open fds limit to " +"%lu/%lu : %s" , + fd_limit.rlim_cur, fd_limit.rlim_max, +strerror (errno)); + }else { +condlog (3 ,"set open fds limit to %lu/%lu" , + fd_limit.rlim_cur, fd_limit.rlim_max); + } + } +}
libmultipath/util.h +1 -0
@@ -21,6 +21,7 @@ int get_linux_version_code(void);int parse_prkey (char *ptr,uint64_t *prkey);int parse_prkey_flags (char *ptr,uint64_t *prkey,uint8_t *flags);int safe_write (int fd,const void *buf,size_t count); +void set_max_fds (int max_fds);#define KERNEL_VERSION (maj, min, ptc) ((((maj) * 256) + (min)) * 256 + (ptc))
multipath/main.c +1 -11
@@ -56,8 +56,6 @@#include "pgpolicies.h" #include "version.h" #include <errno.h> -#include <sys/time.h> -#include <sys/resource.h> #include "wwids.h" #include "uxsock.h" #include "mpath_cmd.h"
@@ -1002,15 +1000,7 @@ main (int argc, char *argv[]) logsink =1 ; } -if (conf->max_fds) { -struct rlimit fd_limit; - - fd_limit.rlim_cur = conf->max_fds; - fd_limit.rlim_max = conf->max_fds; -if (setrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) -condlog (0 ,"can't set open fds limit to %d : %s" , - conf->max_fds,strerror (errno)); - } +set_max_fds (conf->max_fds);libmp_udev_set_sync_support (1 );
multipathd/main.c +3 -28
@@ -12,8 +12,6 @@#include <sys/types.h> #include <fcntl.h> #include <errno.h> -#include <sys/time.h> -#include <sys/resource.h> #include <limits.h> #include <linux/oom.h> #include <libudev.h>
@@ -2663,33 +2661,10 @@ child (void * param) envp =getenv ("LimitNOFILE" ); -if (envp) { +if (envp)condlog (2 ,"Using systemd provided open fds limit of %s" , envp); - }else if (conf->max_fds) { -struct rlimit fd_limit; - -if (getrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) { -condlog (0 ,"can't get open fds limit: %s" , -strerror (errno)); - fd_limit.rlim_cur =0 ; - fd_limit.rlim_max =0 ; - } -if (fd_limit.rlim_cur < conf->max_fds) { - fd_limit.rlim_cur = conf->max_fds; -if (fd_limit.rlim_max < conf->max_fds) - fd_limit.rlim_max = conf->max_fds; -if (setrlimit (RLIMIT_NOFILE , &fd_limit) <0 ) { -condlog (0 ,"can't set open fds limit to " -"%lu/%lu : %s" , - fd_limit.rlim_cur, fd_limit.rlim_max, -strerror (errno)); - }else { -condlog (3 ,"set open fds limit to %lu/%lu" , - fd_limit.rlim_cur, fd_limit.rlim_max); - } - } - - } +else +set_max_fds (conf->max_fds); vecs = gvecs =init_vecs ();if (!vecs)
Signature · 1 line
2.7.4
Re: [PATCH 3/6] libmultipath: remove max_fds code duplication
Quoted 6 lines · Benjamin Marzinski
Instead of multipath, multipathd, and mpathpersist all having code to set the max number of open file descriptors, just use a util function to
do it.Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 9 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/6 multipathd: set return code for multipathd commands
In reply to Benjamin MarzinskiFailed multipathd commands should set the return code to 1.
--- multipathd/main.c | 8 ++++---- multipathd/uxclnt.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-)
multipathd/main.c +4 -4
@@ -2966,9 +2966,9 @@ main (int argc, char *argv[])if (verbosity) conf->verbosity = verbosity; uxsock_timeout = conf->uxsock_timeout; -uxclnt (optarg, uxsock_timeout +100 ); + err =uxclnt (optarg, uxsock_timeout +100 );free_config (conf); -exit (0 ); +return err;case 'B' : bindings_read_only =1 ;break ;
@@ -3005,9 +3005,9 @@ main (int argc, char *argv[]) optind++; } c +=snprintf (c, s +CMDSIZE - c,"\n" ); -uxclnt (s, uxsock_timeout +100 ); + err =uxclnt (s, uxsock_timeout +100 );free_config (conf); -exit (0 ); +return err; }if (foreground) {
multipathd/uxclnt.c +8 -5
@@ -103,14 +103,14 @@ static void process(int fd, unsigned int timeout) } } -static void process_req (int fd,char * inbuf,unsigned int timeout) +static int process_req (int fd,char * inbuf,unsigned int timeout) {char *reply;int ret;if (send_packet (fd, inbuf) !=0 ) {printf ("cannot send packet\n" ); -return ; +return 1 ; } ret =recv_packet (fd, &reply, timeout);if (ret <0 ) {
@@ -118,9 +118,12 @@ static void process_req(int fd, char * inbuf, unsigned int timeout)printf ("timeout receiving packet\n" ); else printf("error %d receiving packet\n", ret); +return 1 ; }else {printf ("%s" , reply); + ret = (strcmp (reply,"fail\n" ) ==0 );FREE (reply); +return ret; } }
@@ -129,16 +132,16 @@ static void process_req(int fd, char * inbuf, unsigned int timeout)*/ int uxclnt (char * inbuf,unsigned int timeout) { -int fd; +int fd, ret =0 ; fd =mpath_connect ();if (fd ==-1 )exit (1 );if (inbuf) -process_req (fd, inbuf, timeout); + ret =process_req (fd, inbuf, timeout);else process (fd, timeout);mpath_disconnect (fd); -return 0 ; +return ret; }
Signature · 1 line
2.7.4
Re: [PATCH 4/6] multipathd: set return code for multipathd commands
Quoted 4 lines · Benjamin Marzinski
Failed multipathd commands should set the return code to 1.
Signed-off-by Benjamin Marzinski <[email protected]>---
Signature · 9 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/6 mpathpersist: fix registration rollback issue
In reply to Benjamin MarzinskiWhen mpathpersist tries to rollback the registration, it copies the SARK to the RK, and clears the SARK. However, it repeated this step for each thread. This means that the first rollback thread correctly had the RK set to the SARK used during registration. However, if more than one registration needed to be rolled back, later threads would have both the RK and SARK cleared. This commit fixes that by only copying and clearing the SARK once.
--- libmpathpersist/mpath_persist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
libmpathpersist/mpath_persist.c +2 -3
@@ -559,11 +559,10 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, }if (rollback && ((rq_servact ==MPATH_PROUT_REG_SA ) && sa_key !=0 )){condlog (3 ,"%s: ERROR: initiating pr out rollback" , mpp->wwid); +memcpy (¶mp->key, ¶mp->sa_key,8 ); +memset (¶mp->sa_key,0 ,8 );for ( i=0 ; i < count ; i++){if (thread[i].param.status ==MPATH_PR_SUCCESS ) { -memcpy (&thread[i].param.paramp->key, &thread[i].param.paramp->sa_key,8 ); -memset (&thread[i].param.paramp->sa_key,0 ,8 ); - thread[i].param.status =MPATH_PR_SUCCESS ; rc =pthread_create (&thread[i].id, &attr, mpath_prout_pthread_fn, (void *)(&thread[i].param));if (rc){
Signature · 1 line
2.7.4
Re: [PATCH 5/6] mpathpersist: fix registration rollback issue
Quoted 38 lines · Benjamin Marzinski
When mpathpersist tries to rollback the registration, it copies the SARK to the RK, and clears the SARK. However, it repeated this step
for each thread. This means that the first rollback thread correctly had the RK set to the SARK used during registration. However, if more than one registration needed to be rolled back, later threads would have
both the RK and SARK cleared. This commit fixes that by only copying and
clearing the SARK once.Signed-off-by Benjamin Marzinski <[email protected]>--- libmpathpersist/mpath_persist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)libmpathpersist/mpath_persist.c +2
-0@@ -559,11 +559,10 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, }if (rollback && ((rq_servact ==MPATH_PROUT_REG_SA ) && sa_key !=0 )){condlog (3 ,"%s: ERROR: initiating pr out rollback" , mpp->wwid); +memcpy (¶mp->key, ¶mp->sa_key,8 ); +memset (¶mp->sa_key,0 ,8 );for ( i=0 ; i < count ; i++){if (thread[i].param.status ==MPATH_PR_SUCCESS ){
libmpathpersist/mpath_persist.c +0
-1- memcpy(&thread[i].param.paramp->key,&thread[i].param.paramp->sa_key, 8);
libmpathpersist/mpath_persist.c +0
-1- memset(&thread[i].param.paramp->sa_key,0, 8);
libmpathpersist/mpath_persist.c +0
-1- thread[i].param.status =
Quoted 1 line
MPATH_PR_SUCCESS;
Why did you delete this last statement, too?
Martin
Quoted 5 lines
rc = pthread_create(&thread[i].id,
&attr,mpath_prout_pthread_fn,
(void
*)(&thread[i].param));
if (rc){
Signature · 9 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 5/6] mpathpersist: fix registration rollback issue
Quoted 20 lines · Martin Wilck
Quoted 20 lines
libmpathpersist/mpath_persist.c +2
-0@@ -559,11 +559,10 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, }if (rollback && ((rq_servact ==MPATH_PROUT_REG_SA ) && sa_key !=0 )){condlog (3 ,"%s: ERROR: initiating pr out rollback" , mpp->wwid); +memcpy (¶mp->key, ¶mp->sa_key,8 ); +memset (¶mp->sa_key,0 ,8 );for ( i=0 ; i < count ; i++){if (thread[i].param.status ==MPATH_PR_SUCCESS ){
libmpathpersist/mpath_persist.c +0
-1- memcpy(&thread[i].param.paramp->key,&thread[i].param.paramp->sa_key, 8);
libmpathpersist/mpath_persist.c +0
-1- memset(&thread[i].param.paramp-
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
sa_key,0, 8);
libmpathpersist/mpath_persist.c +0
-1- thread[i].param.status =
MPATH_PR_SUCCESS;Why did you delete this last statement, too?
For obvious reasons ... Sorry for the noise.
I added a Reviewed-by: tag.
Best,
Martin
Signature · 9 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 5/6] mpathpersist: fix registration rollback issue
In reply to Benjamin MarzinskiQuoted 11 lines · Benjamin Marzinski
When mpathpersist tries to rollback the registration, it copies the SARK to the RK, and clears the SARK. However, it repeated this step
for each thread. This means that the first rollback thread correctly had the RK set to the SARK used during registration. However, if more than one registration needed to be rolled back, later threads would have
both the RK and SARK cleared. This commit fixes that by only copying and
clearing the SARK once.
Quoted 1 line
Signed-off-by Benjamin Marzinski <[email protected]>
Signature · 9 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/6 libmultipath: timeout on unresponsive tur thread
In reply to Benjamin MarzinskiIf the tur checker thread has been cancelled but isn't responding, timeout instead of doing a sync check. This will keep one bad device from impacting all of multipathd.
--- libmultipath/checkers/tur.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libmultipath/checkers/tur.c +3 -3
@@ -305,10 +305,10 @@ int libcheck_check(struct checker * c) }else {if (uatomic_read (&ct->holders) >1 ) {/* The thread has been cancelled but hasn't -* quilt. Fail back to synchronous mode */ -condlog (3 ,"%d:%d : tur checker failing back to sync" , +* quit. exit with timeout. */ +condlog (3 ,"%d:%d : tur thread not responding" ,major (ct->devt),minor (ct->devt)); -return tur_check (c->fd, c->timeout, c->message); +return PATH_TIMEOUT ; }/* Start new TUR checker */ pthread_mutex_lock (&ct->lock);
Signature · 1 line
2.7.4
Re: [PATCH 6/6] libmultipath: timeout on unresponsive tur thread
Quoted 8 lines · Benjamin Marzinski
If the tur checker thread has been cancelled but isn't responding, timeout instead of doing a sync check. This will keep one bad device from impacting all of multipathd.
Fixes 455242d ("libmultipath: fix tur checker timeout")Cc Martin Wilck <[email protected]>Signed-off-by Benjamin Marzinski <[email protected]>---
Signature · 9 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