Two multipath-tools bug fixes
cover Two multipath-tools bug fixes
Hello Christophe,
Please consider the two patches in this series for inclusion in the multipath-tools repository. The first patch fixes a recently introduced bug and the second patch fixes a longstanding bug.
Thanks,
Bart.
PATCH 1/2 multipathd: Avoid "socket operation on non-socket" errors
Changing write_all() into write() is safe for files since the POSIX standard guarantees that write() writes the entire buffer except if the disk is full, a resource limit is encountered or if interrupted by a signal. See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html.
--- libmultipath/alias.c | 2 +- libmultipath/file.c | 2 +- libmultipath/wwids.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
libmultipath/alias.c +1 -1
@@ -219,7 +219,7 @@ allocate_binding(int fd, char *wwid, int id, char *prefix) strerror(errno));return NULL ; } -if (write_all (fd, buf,strlen (buf)) !=strlen (buf)){ +if (write (fd, buf,strlen (buf)) !=strlen (buf)){condlog (0 ,"Cannot write binding to bindings file : %s" ,strerror (errno));/* clear partial write */
libmultipath/file.c +1 -1
@@ -158,7 +158,7 @@ open_file(char *file, int *can_write, char *header) goto fail;/* If file is empty, write the header */ size_t len =strlen (header); -if (write_all (fd, header, len) != len) { +if (write (fd, header, len) != len) {condlog (0 ,"Cannot write header to file %s : %s" , file,strerror (errno));
libmultipath/wwids.c +2 -2
@@ -71,7 +71,7 @@ write_out_wwid(int fd, char *wwid) { strerror(errno));return -1 ; } -if (write_all (fd, buf,strlen (buf)) !=strlen (buf)) { +if (write (fd, buf,strlen (buf)) !=strlen (buf)) {condlog (0 ,"cannot write wwid to wwids file : %s" ,strerror (errno));if (ftruncate (fd, offset))
@@ -110,7 +110,7 @@ replace_wwids(vector mp) goto out_file; } len =strlen (WWIDS_FILE_HEADER ); -if (write_all (fd,WWIDS_FILE_HEADER , len) != len) { +if (write (fd,WWIDS_FILE_HEADER , len) != len) {condlog (0 ,"Can't write wwid file header : %s" ,strerror (errno));/* cleanup partially written header */
Signature · 1 line
2.10.0
PATCH 2/2 multipathd: Avoid that a deadlock is triggered sporadically during shutdown
In reply to Bart Van Asschepthread_cond_wait() is a thread cancellation point. If a thread that is waiting in pthread_cond_wait() is canceled it is possible that the mutex is re-acquired before the first cancellation cleanup handler is called. In this case the cleanup handler is uevq_stop() and that function locks uevq_lock. Avoid that calling uevq_stop() results in a deadlock due to an attempt to lock a non-recursive mutex recursively.
--- 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_MUTEX_INITIALIZER ; +pthread_mutex_t uevq_lock =PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ;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.0
Re: [PATCH 2/2] multipathd: Avoid that a deadlock is triggered sporadically during shutdown
Quoted 18 lines · Bart Van Assche
pthread_cond_wait()is a thread cancellation point. If a thread that is waiting inpthread_cond_wait()is canceled it is possible that the mutex is re-acquired before the first cancellation cleanup handler is called. In this case the cleanup handler isuevq_stop()and that function locksuevq_lock. Avoid that callinguevq_stop()results in a deadlock due to an attempt to lock a non-recursive mutex recursively.Signed-off-by Bart Van Assche <[email protected]>--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/uevent.c +0
-0
libmultipath/uevent.c typedef int (uev_trigger)(struct uevent *, void * trigger_data); · line 58
Quoted 8 lines
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_MUTEX_INITIALIZER ; +pthread_mutex_t uevq_lock =PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ;pthread_mutex_t *uevq_lockp = &uevq_lock;pthread_cond_t uev_cond =PTHREAD_COND_INITIALIZER ;pthread_cond_t *uev_condp = &uev_cond;
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not defined in POSIX.
This is going to be problematic in musl-libc based distributions:
http://wiki.musl-libc.org/wiki/Projects_using_musl#Distributions
~/musl-gcc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmpathcmd -DUSE_SYSTEMD=229 -DLIBDM_API_FLUSH -D_GNU_SOURCE -DLIBDM_API_COOKIE -DLIBUDEV_API_RECVBUF -DLIBDM_API_DEFERRED -c -o uevent.o uevent.c uevent.c:55:29: error: ‘PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP’ undeclared here (not in a function)
pthread_mutex_t uevq_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../Makefile.inc:74: recipe for target 'uevent.o' failed make[1]: [uevent.o] Error 1 (ignored)
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Re: [PATCH 2/2] multipathd: Avoid that a deadlock is triggered sporadically during shutdown
Quoted 35 lines · Xose Vazquez Perez
Quoted 18 lines · Bart Van Assche
pthread_cond_wait()is a thread cancellation point. If a thread that is waiting inpthread_cond_wait()is canceled it is possible that the mutex is re-acquired before the first cancellation cleanup handler is called. In this case the cleanup handler isuevq_stop()and that function locksuevq_lock. Avoid that callinguevq_stop()results in a deadlock due to an attempt to lock a non-recursive mutex recursively.Signed-off-by Bart Van Assche <[email protected]>--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/uevent.c +0
-0libmultipath/uevent.c typedef int (uev_trigger)(struct uevent *, void * trigger_data); · line 58
Quoted 8 lines
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_MUTEX_INITIALIZER ; +pthread_mutex_t uevq_lock =PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ;pthread_mutex_t *uevq_lockp = &uevq_lock;pthread_cond_t uev_cond =PTHREAD_COND_INITIALIZER ;pthread_cond_t *uev_condp = &uev_cond;
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NPis not defined in POSIX.This is going to be problematic in musl-libc based distributions:
http://wiki.musl-libc.org/wiki/Projects_using_musl#Distributions
Quoted 7 lines
~/musl-gcc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmpathcmd -DUSE_SYSTEMD=229 -DLIBDM_API_FLUSH -D_GNU_SOURCE -DLIBDM_API_COOKIE -DLIBUDEV_API_RECVBUF -DLIBDM_API_DEFERRED -c -o uevent.o
uevent.cuevent.c:55:29: error: ‘PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP’ undeclared here (not in a function)pthread_mutex_t uevq_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../Makefile.inc:74: recipe for target 'uevent.o' failed make[1]: [uevent.o] Error 1 (ignored)
Hello Xose,
Thanks for reporting this. I will rework that patch.
Bart.
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Merged.
Thanks.
On Fri, Oct 14, 2016 at 5:33 PM, Bart Van Assche <[email protected]
Quoted 12 lines
wrote:
Hello Christophe,
Please consider the two patches in this series for inclusion in the multipath-tools repository. The first patch fixes a recently introduced bug and the second patch fixes a longstanding bug.
Thanks,
Bart.