From 4d0c245641d80a5fd10833333dc288a5a9293ee9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Aug 2016 09:57:39 -0700 Subject: [PATCH 2/3] libmultipath/checkers/tur: Introduce checker_thread_running() Additionally, protect tur_checker_context.thread reads via hldr_lock. This avoids that data race detection tools complain about reads of the member variable 'thread'. Signed-off-by: Bart Van Assche --- libmultipath/checkers/tur.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index ad66918..c014b65 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -68,6 +68,17 @@ int libcheck_init (struct checker * c) return 0; } +static int checker_thread_running(struct tur_checker_context *ct) +{ + pthread_t thread; + + pthread_spin_lock(&ct->hldr_lock); + thread = ct->thread; + pthread_spin_unlock(&ct->hldr_lock); + + return thread != 0; +} + void cleanup_context(struct tur_checker_context *ct) { pthread_mutex_destroy(&ct->lock); @@ -295,7 +306,7 @@ libcheck_check (struct checker * c) if (ct->running) { /* Check if TUR checker is still running */ - if (ct->thread) { + if (checker_thread_running(ct)) { if (tur_check_async_timeout(c)) { condlog(3, "%d:%d: tur checker timeout", TUR_DEVT(ct)); @@ -318,7 +329,7 @@ libcheck_check (struct checker * c) } pthread_mutex_unlock(&ct->lock); } else { - if (ct->thread) { + if (checker_thread_running(ct)) { /* pthread cancel failed. continue in sync mode */ pthread_mutex_unlock(&ct->lock); condlog(3, "%d:%d: tur thread not responding", @@ -352,7 +363,7 @@ libcheck_check (struct checker * c) strncpy(c->message, ct->message,CHECKER_MSG_LEN); c->message[CHECKER_MSG_LEN - 1] = '\0'; pthread_mutex_unlock(&ct->lock); - if (ct->thread && + if (checker_thread_running(ct) && (tur_status == PATH_PENDING || tur_status == PATH_UNCHECKED)) { condlog(3, "%d:%d: tur checker still running", TUR_DEVT(ct)); -- 2.9.2