From patchwork Tue Jul 16 07:13:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 2827924 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 E3AAE9F9CA for ; Tue, 16 Jul 2013 07:16:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAC9D2018C for ; Tue, 16 Jul 2013 07:16:44 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id 231D520186 for ; Tue, 16 Jul 2013 07:16:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7Dx4E021525; Tue, 16 Jul 2013 03:13:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7DTMG027834 for ; Tue, 16 Jul 2013 03:13:29 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7DTRb013189 for ; Tue, 16 Jul 2013 03:13:29 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6G7DSgi011774 for ; Tue, 16 Jul 2013 03:13:28 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C7C82A5591; Tue, 16 Jul 2013 09:13:24 +0200 (CEST) From: Hannes Reinecke To: Christophe Varoqui Date: Tue, 16 Jul 2013 09:13:15 +0200 Message-Id: <1373958801-103613-25-git-send-email-hare@suse.de> In-Reply-To: <1373958801-103613-1-git-send-email-hare@suse.de> References: <1373958801-103613-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.69 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, URIBL_BLOCKED) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 24/30] multipath: reference the udev context when starting event queue 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.3 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 uevent listener is running asynchronously, so it might still be active and receiving events when the main thread is already shut down. So it need to take a separate reference to the udev context to avoid the context becoming invalid while the listener is running. Signed-off-by: Hannes Reinecke --- libmultipath/uevent.c | 16 ++++++++++++---- libmultipath/uevent.h | 4 +++- multipathd/main.c | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index 0643e14..9ee3ade 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -47,7 +47,6 @@ #include "list.h" #include "uevent.h" #include "vector.h" -#include "config.h" typedef int (uev_trigger)(struct uevent *, void * trigger_data); @@ -127,11 +126,14 @@ service_uevq(struct list_head *tmpq) static void uevq_stop(void *arg) { + struct udev *udev = arg; + condlog(3, "Stopping uev queue"); pthread_mutex_lock(uevq_lockp); my_uev_trigger = NULL; pthread_cond_signal(uev_condp); pthread_mutex_unlock(uevq_lockp); + udev_unref(udev); } void @@ -399,7 +401,7 @@ exit: return 1; } -int uevent_listen(void) +int uevent_listen(struct udev *udev) { int err; struct udev_monitor *monitor = NULL; @@ -411,11 +413,17 @@ int uevent_listen(void) * thereby not getting to empty the socket's receive buffer queue * often enough. */ - pthread_cleanup_push(uevq_stop, NULL); + if (!udev) { + condlog(1, "no udev context"); + return 1; + } + udev_ref(udev); + pthread_cleanup_push(uevq_stop, udev); - monitor = udev_monitor_new_from_netlink(conf->udev, "udev"); + monitor = udev_monitor_new_from_netlink(udev, "udev"); if (!monitor) { condlog(2, "failed to create udev monitor"); + err = 2; goto out; } #ifdef LIBUDEV_API_RECVBUF diff --git a/libmultipath/uevent.h b/libmultipath/uevent.h index 762595a..e5fdfcc 100644 --- a/libmultipath/uevent.h +++ b/libmultipath/uevent.h @@ -13,6 +13,8 @@ #define NETLINK_KOBJECT_UEVENT 15 #endif +struct udev; + struct uevent { struct list_head node; struct udev_device *udev; @@ -27,7 +29,7 @@ struct uevent { int is_uevent_busy(void); void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached); -int uevent_listen(void); +int uevent_listen(struct udev *udev); int uevent_dispatch(int (*store_uev)(struct uevent *, void * trigger_data), void * trigger_data); int uevent_get_major(struct uevent *uev); diff --git a/multipathd/main.c b/multipathd/main.c index aa5a298..b41fc64 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -835,7 +835,7 @@ out: static void * ueventloop (void * ap) { - if (uevent_listen()) + if (uevent_listen(udev)) condlog(0, "error starting uevent listener"); return NULL; @@ -1658,7 +1658,7 @@ child (void * param) /* * Start uevent listener early to catch events */ - if ((rc = pthread_create(&uevent_thr, &misc_attr, ueventloop, vecs))) { + if ((rc = pthread_create(&uevent_thr, &misc_attr, ueventloop, udev))) { condlog(0, "failed to create uevent thread: %d", rc); exit(1); }