Skip to contentSkip to conversation

Two multipath-tools bug fixes

PATCH In review Bart Van Assche 3 participants 6 messages Oct 14, 2016 – Oct 20, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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.

Fixes commit 810082e7a8cf ("libmultipath, multipathd: Rework SIGPIPE handling")
---
 libmultipath/alias.c | 2 +-
 libmultipath/file.c  | 2 +-
 libmultipath/wwids.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
libmultipath/alias.c +1 -1
index b86843a..12afef8 100644
@@ -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
index 74cde64..e4951c9 100644
@@ -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
index babf149..bc70a27 100644
@@ -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
#2 lore raw

PATCH 2/2 multipathd: Avoid that a deadlock is triggered sporadically during shutdown

In reply to Bart Van Assche

pthread_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
index 6247898..85fd2fb 100644
@@ -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
#3 lore raw

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 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 +0 -0
index 6247898..85fd2fb 100644

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

#4 lore raw

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 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 +0 -0
index 6247898..85fd2fb 100644

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

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.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)

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

#5 lore raw
In reply to Bart Van Assche

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.