From patchwork Wed Dec 11 06:43:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 3322621 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B42C9F37C for ; Wed, 11 Dec 2013 06:47:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5EAB20749 for ; Wed, 11 Dec 2013 06:47:20 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id EE92520396 for ; Wed, 11 Dec 2013 06:47:19 +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 rBB6hndb018566; Wed, 11 Dec 2013 01:43:49 -0500 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 rBB6hQTP016454 for ; Wed, 11 Dec 2013 01:43:26 -0500 Received: from dhcp80-209.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBB6hPQO030592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2013 01:43:26 -0500 Received: from dhcp80-209.msp.redhat.com (localhost [127.0.0.1]) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7) with ESMTP id rBB6hOVV001357; Wed, 11 Dec 2013 00:43:24 -0600 Received: (from bmarzins@localhost) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7/Submit) id rBB6hOM5001356; Wed, 11 Dec 2013 00:43:24 -0600 From: Benjamin Marzinski To: device-mapper development Date: Wed, 11 Dec 2013 00:43:00 -0600 Message-Id: <1386744190-1295-7-git-send-email-bmarzins@redhat.com> In-Reply-To: <1386744190-1295-1-git-send-email-bmarzins@redhat.com> References: <1386744190-1295-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 06/16] signal waiter thread to stop waiting on dm events 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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ioctl syscall is not a pthread cancellation point. So, when device-mapper is waiting on events, pthread_cancel won't cancel the waiter thread. This patch makes the waiter threads handle SIGUSR2, and has stop_waiter_thread() signal it to break out of waiting on dm events. Unfortunately, there is still a possibility of the signal arriving before the ioctl, and the waiter thread still hanging until the devices are reloaded. Signed-off-by: Benjamin Marzinski --- libmultipath/waiter.c | 9 +++++++++ multipathd/main.c | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/libmultipath/waiter.c b/libmultipath/waiter.c index 5094290..7cedd4b 100644 --- a/libmultipath/waiter.c +++ b/libmultipath/waiter.c @@ -57,6 +57,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs) thread = mpp->waiter; mpp->waiter = (pthread_t)0; pthread_cancel(thread); + pthread_kill(thread, SIGUSR2); } /* @@ -65,6 +66,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs) */ int waiteventloop (struct event_thread *waiter) { + sigset_t set, oldset; int event_nr; int r; @@ -97,8 +99,15 @@ int waiteventloop (struct event_thread *waiter) dm_task_no_open_count(waiter->dmt); /* wait */ + sigemptyset(&set); + sigaddset(&set, SIGUSR2); + pthread_sigmask(SIG_UNBLOCK, &set, &oldset); + + pthread_testcancel(); r = dm_task_run(waiter->dmt); + pthread_testcancel(); + pthread_sigmask(SIG_SETMASK, &oldset, NULL); dm_task_destroy(waiter->dmt); waiter->dmt = NULL; diff --git a/multipathd/main.c b/multipathd/main.c index 7c0e313..c388e42 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1521,6 +1521,12 @@ sigusr1 (int sig) } static void +sigusr2 (int sig) +{ + condlog(3, "SIGUSR2 received"); +} + +static void signal_init(void) { sigset_t set; @@ -1528,10 +1534,12 @@ signal_init(void) sigemptyset(&set); sigaddset(&set, SIGHUP); sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGUSR2); pthread_sigmask(SIG_BLOCK, &set, NULL); signal_set(SIGHUP, sighup); signal_set(SIGUSR1, sigusr1); + signal_set(SIGUSR2, sigusr2); signal_set(SIGINT, sigend); signal_set(SIGTERM, sigend); signal(SIGPIPE, SIG_IGN);