From patchwork Mon Jul 15 13:00:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 2827479 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 2C7859F9F9 for ; Mon, 15 Jul 2013 13:05:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8480720163 for ; Mon, 15 Jul 2013 13:05:42 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id B96B72015F for ; Mon, 15 Jul 2013 13:05:37 +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 r6FD27pB006504; Mon, 15 Jul 2013 09:02:08 -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 r6FD0eoM029035 for ; Mon, 15 Jul 2013 09:00:41 -0400 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FD0ebV011134 for ; Mon, 15 Jul 2013 09:00:40 -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 r6FD0dii018056 for ; Mon, 15 Jul 2013 09:00:39 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6B310A52D7; Mon, 15 Jul 2013 15:00:36 +0200 (CEST) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 15 Jul 2013 15:00:25 +0200 Message-Id: <1373893230-26077-25-git-send-email-hare@suse.de> In-Reply-To: <1373893230-26077-1-git-send-email-hare@suse.de> References: <1373893230-26077-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.17 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 24/29] 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); }