From patchwork Mon Jul 15 13:00:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 2827463 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 DA6479F7D6 for ; Mon, 15 Jul 2013 13:04:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8116320155 for ; Mon, 15 Jul 2013 13:04:45 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 029B12015C for ; Mon, 15 Jul 2013 13:04:43 +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 r6FD0c7P015023; Mon, 15 Jul 2013 09:00:39 -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 r6FD0ahs028917 for ; Mon, 15 Jul 2013 09:00:36 -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 r6FD0aO1011104 for ; Mon, 15 Jul 2013 09:00:36 -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 r6FD0YOh013025 for ; Mon, 15 Jul 2013 09:00:35 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2A66BA51FE; Mon, 15 Jul 2013 15:00:34 +0200 (CEST) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 15 Jul 2013 15:00:02 +0200 Message-Id: <1373893230-26077-2-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.20 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 01/29] multipath: bind lifetime of udev context to main thread 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 We have to tie the lifetime of the udev context to the thread or program. The current approach by creating it on config_load() will invalidate the context during reconfiguration, thereby causing all still existent objects to refer to an invalid pointer. And resulting in a nice crash. Signed-off-by: Hannes Reinecke --- libmpathpersist/mpath_persist.c | 7 ++++--- libmpathpersist/mpath_persist.h | 2 +- libmpathpersist/mpath_pr_ioctl.c | 5 +++-- libmultipath/config.c | 9 +++------ libmultipath/config.h | 2 +- mpathpersist/main.c | 11 +++++++---- multipath/main.c | 12 ++++++++---- multipathd/main.c | 11 ++++++++--- 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 3041089..bd30125 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -1,4 +1,3 @@ -#include "mpath_persist.h" #include #include #include @@ -8,6 +7,7 @@ #include #include #include +#include #include #include @@ -20,6 +20,7 @@ #include #include +#include "mpath_persist.h" #include "mpathpr.h" #include "mpath_pr_ioctl.h" @@ -32,9 +33,9 @@ int -mpath_lib_init (void) +mpath_lib_init (struct udev *udev) { - if (load_config(DEFAULT_CONFIGFILE)){ + if (load_config(DEFAULT_CONFIGFILE, udev)){ condlog(0, "Failed to initialize multipath config."); return 1; } diff --git a/libmpathpersist/mpath_persist.h b/libmpathpersist/mpath_persist.h index d8ff6f2..a5e7868 100644 --- a/libmpathpersist/mpath_persist.h +++ b/libmpathpersist/mpath_persist.h @@ -174,7 +174,7 @@ struct prout_param_descriptor { /* PROUT parameter descriptor */ * * RETURNS: 0->Success, 1->Failed. */ -extern int mpath_lib_init (void ); +extern int mpath_lib_init (struct udev *udev); /* diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c index de3292e..c85fd10 100644 --- a/libmpathpersist/mpath_pr_ioctl.c +++ b/libmpathpersist/mpath_pr_ioctl.c @@ -10,8 +10,9 @@ #include #include #include -#include "mpath_pr_ioctl.h" -#include +#include +#include "mpath_pr_ioctl.h" +#include #include diff --git a/libmultipath/config.c b/libmultipath/config.c index da676df..a322dfe 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -466,9 +466,6 @@ free_config (struct config * conf) if (conf->dev) FREE(conf->dev); - if (conf->udev) - udev_unref(conf->udev); - if (conf->multipath_dir) FREE(conf->multipath_dir); @@ -518,12 +515,12 @@ free_config (struct config * conf) } int -load_config (char * file) +load_config (char * file, struct udev *udev) { if (!conf) conf = alloc_config(); - if (!conf) + if (!conf || !udev) return 1; /* @@ -532,7 +529,7 @@ load_config (char * file) if (!conf->verbosity) conf->verbosity = DEFAULT_VERBOSITY; - conf->udev = udev_new(); + conf->udev = udev; dm_drv_version(conf->version, TGT_MPATH); conf->dev_type = DEV_NONE; conf->minio = DEFAULT_MINIO; diff --git a/libmultipath/config.h b/libmultipath/config.h index 4ade355..405a8f3 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -157,7 +157,7 @@ void free_mptable (vector mptable); int store_hwe (vector hwtable, struct hwentry *); -int load_config (char * file); +int load_config (char * file, struct udev * udev); struct config * alloc_config (void); void free_config (struct config * conf); diff --git a/mpathpersist/main.c b/mpathpersist/main.c index 465fcb1..e3484b5 100644 --- a/mpathpersist/main.c +++ b/mpathpersist/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "main.h" #include @@ -68,7 +69,8 @@ int main (int argc, char * argv[]) int noisy = 0; int num_transport =0; void *resp = NULL; - struct transportid * tmp; + struct transportid * tmp; + struct udev *udev = NULL; if (optind == argc) { @@ -84,8 +86,8 @@ int main (int argc, char * argv[]) exit (1); } - - mpath_lib_init(); + udev = udev_new(); + mpath_lib_init(udev); memset(transportids,0,MPATH_MX_TIDS); while (1) @@ -461,12 +463,13 @@ int main (int argc, char * argv[]) if (res < 0) { mpath_lib_exit(); + udev_unref(udev); return MPATH_PR_FILE_ERROR; } out : mpath_lib_exit(); - + udev_unref(udev); return (ret >= 0) ? ret : MPATH_PR_OTHER; } diff --git a/multipath/main.c b/multipath/main.c index f1b3ec9..4a8b966 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -435,6 +436,7 @@ convert_dev(char *dev) int main (int argc, char *argv[]) { + struct udev *udev; int arg; extern char *optarg; extern int optind; @@ -445,10 +447,12 @@ main (int argc, char *argv[]) exit(1); } + udev = udev_new(); + if (dm_prereq()) exit(1); - if (load_config(DEFAULT_CONFIGFILE)) + if (load_config(DEFAULT_CONFIGFILE, udev)) exit(1); while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtqwW")) != EOF ) { @@ -560,11 +564,11 @@ main (int argc, char *argv[]) if (init_checkers()) { condlog(0, "failed to initialize checkers"); - exit(1); + goto out; } if (init_prio()) { condlog(0, "failed to initialize prioritizers"); - exit(1); + goto out; } dm_init(); @@ -628,7 +632,7 @@ out: */ free_config(conf); conf = NULL; - + udev_unref(udev); #ifdef _DEBUG_ dbg_free_final(NULL); #endif diff --git a/multipathd/main.c b/multipathd/main.c index 0fa1b17..aa5a298 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -93,6 +93,8 @@ static sem_t exit_sem; */ struct vectors * gvecs; +struct udev * udev; + static int need_switch_pathgroup (struct multipath * mpp, int refresh) { @@ -1403,7 +1405,7 @@ reconfigure (struct vectors * vecs) vecs->pathvec = NULL; conf = NULL; - if (!load_config(DEFAULT_CONFIGFILE)) { + if (!load_config(DEFAULT_CONFIGFILE, udev)) { conf->verbosity = old->verbosity; conf->daemon = 1; configure(vecs, 1); @@ -1588,6 +1590,8 @@ child (void * param) sem_init(&exit_sem, 0, 0); signal_init(); + udev = udev_new(); + setup_thread_attr(&misc_attr, 64 * 1024, 1); setup_thread_attr(&waiter_attr, 32 * 1024, 1); @@ -1602,7 +1606,7 @@ child (void * param) condlog(2, "--------start up--------"); condlog(2, "read " DEFAULT_CONFIGFILE); - if (load_config(DEFAULT_CONFIGFILE)) + if (load_config(DEFAULT_CONFIGFILE, udev)) exit(1); if (init_checkers()) { @@ -1752,7 +1756,8 @@ child (void * param) */ free_config(conf); conf = NULL; - + udev_unref(udev); + udev = NULL; #ifdef _DEBUG_ dbg_free_final(NULL); #endif