Skip to contentSkip to conversation

multipath-tools: release lock on handler failure

PATCH In review Michael Wang 2 participants 3 messages Oct 12, 2016 – Oct 17, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multipath-tools: release lock on handler failure

Inside parse_cmd() the pthread_cleanup_pop() rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.

This will lead into the situation that all the following operation will trying to hold a lock which will never be released.

This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.

---
 multipathd/cli.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
multipathd/cli.c +3 -1
index e8a9384..50161be 100644
@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
                tmo.tv_sec = 0;
        }
        if (h->locked) {
+               int locked = 0;
                struct vectors * vecs = (struct vectors *)data;
 
                pthread_cleanup_push(cleanup_lock, &vecs->lock);
@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
                        r = 0;
                }
                if (r == 0) {
+                       locked = 1;
                        pthread_testcancel();
                        r = h->fn(cmdvec, reply, len, data);
                }
-               pthread_cleanup_pop(!r);
+               pthread_cleanup_pop(locked);
        } else
                r = h->fn(cmdvec, reply, len, data);
        free_keys(cmdvec);
Signature · 1 line
2.5.0
#1 lore raw

Dear maintainer, is this patch looks fine to you?

Regards,
Michael Wang

Quoted 42 lines · Michael Wang

Inside parse_cmd() the pthread_cleanup_pop() rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.

This will lead into the situation that all the following operation will trying to hold a lock which will never be released.

This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.

---
 multipathd/cli.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
multipathd/cli.c +3 -1
index e8a9384..50161be 100644
@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
                tmo.tv_sec = 0;
        }
        if (h->locked) {
+               int locked = 0;
                struct vectors * vecs = (struct vectors *)data;
 
                pthread_cleanup_push(cleanup_lock, &vecs->lock);
@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
                        r = 0;
                }
                if (r == 0) {
+                       locked = 1;
                        pthread_testcancel();
                        r = h->fn(cmdvec, reply, len, data);
                }
-               pthread_cleanup_pop(!r);
+               pthread_cleanup_pop(locked);
        } else
                r = h->fn(cmdvec, reply, len, data);
        free_keys(cmdvec);
#2 lore raw

Merged.
Thanks.

Quoted 51 lines · Michael Wang

Dear maintainer, is this patch looks fine to you?

Regards,
Michael Wang

multipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len,

Quoted 21 lines · Michael Wang

Inside parse_cmd() the pthread_cleanup_pop() rely on '!r' as the indicator of locked or not, while this will be overwritten if the handler return failed, and the unlock will be missing.

This will lead into the situation that all the following operation will trying to hold a lock which will never be released.

This patch using a separate flag to record the status of locking to make sure the unlock and lock are in pairs.

---
 multipathd/cli.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
multipathd/cli.c +0 -0
index e8a9384..50161be 100644
@@ -481,6 +481,7 @@ parse_cmd (char * cmd, char ** reply, int * len,

void * data, int timeout )

multipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len,

Quoted 8 lines
multipathd/cli.c +1 -0
                tmo.tv_sec = 0;
        }
        if (h->locked) {
+               int locked = 0;
                struct vectors * vecs = (struct vectors *)data;
 
                pthread_cleanup_push(cleanup_lock, &vecs->lock);
@@ -491,10 +492,11 @@ parse_cmd (char * cmd, char ** reply, int * len,

void * data, int timeout )

Quoted 13 lines
multipathd/cli.c +2 -1
                        r = 0;
                }
                if (r == 0) {
+                       locked = 1;
                        pthread_testcancel();
                        r = h->fn(cmdvec, reply, len, data);
                }
-               pthread_cleanup_pop(!r);
+               pthread_cleanup_pop(locked);
        } else
                r = h->fn(cmdvec, reply, len, data);
        free_keys(cmdvec);