From patchwork Thu May 2 21:46:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 2513951 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 0FCE83FCA5 for ; Thu, 2 May 2013 21:50:58 +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 r42Lks08024140; Thu, 2 May 2013 17:46:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r42LkrlR028854 for ; Thu, 2 May 2013 17:46:53 -0400 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r42Lkqv5019575 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 2 May 2013 17:46:52 -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 r42Lkodn009035; Thu, 2 May 2013 16:46:51 -0500 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r42Lkopd009034; Thu, 2 May 2013 16:46:50 -0500 From: Benjamin Marzinski To: device-mapper development Date: Thu, 2 May 2013 16:46:29 -0500 Message-Id: <1367531197-8987-9-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.22 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 08/16] Avoid race between ueventloop and uevqloop 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 ueventloop sets up uevq_lockp and uev_condp, which uevqloop uses. If uevqloop accesses these structures before ueventloop has initialized them, it will not wake up to process uevents. This patch statically initializes these structures so they will always be initialized. Also, since calling LIST_HEAD(uevq) initializes it, there is no reason to call INIT_LIST_HEAD on it later. Signed-off-by: Benjamin Marzinski --- libmultipath/uevent.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index bc74d38..0643e14 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -53,8 +53,10 @@ typedef int (uev_trigger)(struct uevent *, void * trigger_data); pthread_t uevq_thr; LIST_HEAD(uevq); -pthread_mutex_t uevq_lock, *uevq_lockp = &uevq_lock; -pthread_cond_t uev_cond, *uev_condp = &uev_cond; +pthread_mutex_t uevq_lock = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *uevq_lockp = &uevq_lock; +pthread_cond_t uev_cond = PTHREAD_COND_INITIALIZER; +pthread_cond_t *uev_condp = &uev_cond; uev_trigger *my_uev_trigger; void * my_trigger_data; int servicing_uev; @@ -409,10 +411,6 @@ int uevent_listen(void) * thereby not getting to empty the socket's receive buffer queue * often enough. */ - INIT_LIST_HEAD(&uevq); - - pthread_mutex_init(uevq_lockp, NULL); - pthread_cond_init(uev_condp, NULL); pthread_cleanup_push(uevq_stop, NULL); monitor = udev_monitor_new_from_netlink(conf->udev, "udev"); @@ -525,8 +523,6 @@ out: if (need_failback) err = failback_listen(); pthread_cleanup_pop(1); - pthread_mutex_destroy(uevq_lockp); - pthread_cond_destroy(uev_condp); return err; }