From: Hannes Reinecke <hare@suse.de>
To: Christophe Varoqui <christophe.varoqui@gmail.com>
Cc: dm-devel@redhat.com
Subject: [PATCH 01/29] multipath: bind lifetime of udev context to main thread
Date: Mon, 15 Jul 2013 15:00:02 +0200 [thread overview]
Message-ID: <1373893230-26077-2-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1373893230-26077-1-git-send-email-hare@suse.de>
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 <hare@suse.de>
---
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 <libdevmapper.h>
#include <defaults.h>
#include <sys/stat.h>
@@ -8,6 +7,7 @@
#include <checkers.h>
#include <structs.h>
#include <structs_vec.h>
+#include <libudev.h>
#include <prio.h>
#include <unistd.h>
@@ -20,6 +20,7 @@
#include <ctype.h>
#include <propsel.h>
+#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 <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
-#include "mpath_pr_ioctl.h"
-#include <mpath_persist.h>
+#include <libudev.h>
+#include "mpath_pr_ioctl.h"
+#include <mpath_persist.h>
#include <debug.h>
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 <vector.h>
#include <structs.h>
#include <getopt.h>
+#include <libudev.h>
#include <mpath_persist.h>
#include "main.h"
#include <pthread.h>
@@ -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 <stdio.h>
#include <unistd.h>
#include <ctype.h>
+#include <libudev.h>
#include <checkers.h>
#include <prio.h>
@@ -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
--
1.7.10.4
next prev parent reply other threads:[~2013-07-15 13:00 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-15 13:00 [PATCH 00/29] SLES resync Hannes Reinecke
2013-07-15 13:00 ` Hannes Reinecke [this message]
2013-07-15 13:00 ` [PATCH 02/29] Document 'infinity' as possible value for dev_loss_tmo Hannes Reinecke
2013-07-15 13:00 ` [PATCH 03/29] alua: Do not add preferred path priority for active/optimized Hannes Reinecke
2013-07-15 13:00 ` [PATCH 04/29] multipath: Increase dev_loss_tmo prior to fast_io_fail Hannes Reinecke
2013-07-15 13:00 ` [PATCH 05/29] libmultipath: return PATH_DOWN for quiesced paths Hannes Reinecke
2013-07-15 13:00 ` [PATCH 06/29] libmultipath: Implement PATH_TIMEOUT Hannes Reinecke
2013-07-15 13:00 ` [PATCH 07/29] Deprecate pg_timeout Hannes Reinecke
2013-07-15 13:00 ` [PATCH 08/29] kpartx: create correct symlinks for PATH_FAILED events Hannes Reinecke
2013-07-15 13:00 ` [PATCH 09/29] multipath: Deprecate 'getuid' configuration variable Hannes Reinecke
2013-07-15 13:00 ` [PATCH 10/29] kpartx: support disk with non-512B sectors Hannes Reinecke
2013-07-15 13:00 ` [PATCH 11/29] multipath: Add 'Datacore Virtual Disk' to internal hardware table Hannes Reinecke
2013-07-15 13:00 ` [PATCH 12/29] Minor fixes for priority handling Hannes Reinecke
2013-07-15 13:00 ` [PATCH 13/29] Check return value from pathinfo() Hannes Reinecke
2013-07-15 13:00 ` [PATCH 14/29] Read directly from sysfs when checking the device size Hannes Reinecke
2013-07-15 13:00 ` [PATCH 15/29] multipath.conf.annotated: Document rr_min_io_rq Hannes Reinecke
2013-07-15 13:00 ` [PATCH 16/29] Correctly print out 'max' for max_fds Hannes Reinecke
2013-07-15 13:00 ` [PATCH 17/29] Correctly set max_fds in case of failure Hannes Reinecke
2013-07-15 13:00 ` [PATCH 18/29] Update multipath.conf.defaults Hannes Reinecke
2013-07-15 13:00 ` [PATCH 19/29] Correctly set pgfailback Hannes Reinecke
2013-07-15 13:00 ` [PATCH 20/29] multipath.conf.5: clarify 'no_path_retry' default setting Hannes Reinecke
2013-07-15 13:00 ` [PATCH 21/29] multipath.conf.annotated: remove 'udev_dir' Hannes Reinecke
2013-07-15 13:00 ` [PATCH 22/29] multipath: Implement 'property' blacklist Hannes Reinecke
2013-07-15 13:00 ` [PATCH 23/29] Do not print error when rport is blocked Hannes Reinecke
2013-07-15 13:00 ` [PATCH 24/29] multipath: reference the udev context when starting event queue Hannes Reinecke
2013-07-15 13:00 ` [PATCH 25/29] multipathd: valgrind fixes Hannes Reinecke
2013-07-15 13:00 ` [PATCH 26/29] multipathd: increase stacksize for uevent listener Hannes Reinecke
2013-07-15 13:00 ` [PATCH 27/29] Specify checker_timeout in seconds Hannes Reinecke
2013-07-15 13:00 ` [PATCH 28/29] multipath: fix setting of fast_io_fail_tmo Hannes Reinecke
2013-07-15 13:00 ` [PATCH 29/29] multipath: reset queue_if_no_path if flush failed Hannes Reinecke
2013-07-15 13:53 ` [PATCH 00/29] SLES resync Sebastian Riemer
2013-07-15 14:12 ` Hannes Reinecke
2013-07-16 7:10 ` Hannes Reinecke
2013-07-16 9:20 ` Sebastian Riemer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1373893230-26077-2-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=christophe.varoqui@gmail.com \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.