From patchwork Thu May 2 21:46:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 2514001 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 98F653FCA5 for ; Thu, 2 May 2013 21:51:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r42LloCq024464; Thu, 2 May 2013 17:47:51 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r42Lkm6I028796 for ; Thu, 2 May 2013 17:46:48 -0400 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r42LklsB026768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 2 May 2013 17:46:47 -0400 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r42LkkxN009023; Thu, 2 May 2013 16:46:46 -0500 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r42LkjYD009022; Thu, 2 May 2013 16:46:45 -0500 From: Benjamin Marzinski To: device-mapper development Date: Thu, 2 May 2013 16:46:26 -0500 Message-Id: <1367531197-8987-6-git-send-email-bmarzins@redhat.com> In-Reply-To: <1367531197-8987-1-git-send-email-bmarzins@redhat.com> References: <1367531197-8987-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 05/16] Fix a couple of signal issues X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com The patch cleans up some signal issues. First, when the vecs locking around reconfigure got shuffled around earlier, it was removed from sighup. This patch restores that. Second, a new sigusr1 handler was created. However the existing one was never removed. Since signal handlers are per-process, and not per-thread, the original handler will get overwritten by the new one, so this patch deletes the original handler. Third, sighup locks the vecs lock and sigusr1 locks logq_lock. However, these signals weren't being blocked before threads locked those locks. This patch blocks those signals while those locks are being taken to avoid locking deadlocks. Signed-off-by: Benjamin Marzinski --- libmultipath/log_pthread.c | 3 +++ multipathd/main.c | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c index b8f9119..b3daf8f 100644 --- a/libmultipath/log_pthread.c +++ b/libmultipath/log_pthread.c @@ -55,14 +55,17 @@ void log_safe (int prio, const char * fmt, va_list ap) void log_thread_flush (void) { + sigset_t old; int empty; do { + block_signal(SIGUSR1, &old); pthread_mutex_lock(&logq_lock); empty = log_dequeue(la->buff); pthread_mutex_unlock(&logq_lock); if (!empty) log_syslog(la->buff); + pthread_sigmask(SIG_SETMASK, &old, NULL); } while (empty == 0); } diff --git a/multipathd/main.c b/multipathd/main.c index 95264fc..f6e68e8 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1467,7 +1467,9 @@ sighup (int sig) if (running_state != DAEMON_RUNNING) return; + lock(gvecs->lock); reconfigure(gvecs); + unlock(gvecs->lock); #ifdef _DEBUG_ dbg_free_final(NULL); @@ -1481,16 +1483,9 @@ sigend (int sig) } static void -sigusr1 (int sig) -{ - condlog(3, "SIGUSR1 received"); -} - -static void signal_init(void) { signal_set(SIGHUP, sighup); - signal_set(SIGUSR1, sigusr1); signal_set(SIGINT, sigend); signal_set(SIGTERM, sigend); signal(SIGPIPE, SIG_IGN); @@ -1646,6 +1641,7 @@ child (void * param) */ running_state = DAEMON_CONFIGURE; + block_signal(SIGHUP, &set); lock(vecs->lock); if (configure(vecs, 1)) { unlock(vecs->lock); @@ -1653,6 +1649,7 @@ child (void * param) exit(1); } unlock(vecs->lock); + pthread_sigmask(SIG_SETMASK, &set, NULL); /* * start threads @@ -1685,6 +1682,7 @@ child (void * param) */ running_state = DAEMON_SHUTDOWN; pthread_sigmask(SIG_UNBLOCK, &set, NULL); + block_signal(SIGUSR1, NULL); block_signal(SIGHUP, NULL); lock(vecs->lock); if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF)