* [PATCH] multipathd: fix uev_update_path dead lock
@ 2016-11-07 8:12 tang.wenjun3
2016-11-07 19:15 ` Benjamin Marzinski
0 siblings, 1 reply; 4+ messages in thread
From: tang.wenjun3 @ 2016-11-07 8:12 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: 10144149, tang.junhui, zhang.kai16, dm-devel
From: 10144149 <tang.wenjun3@zte.com.cn>
uev_update_path locked &vecs->lock, and it will get lock twice in uev_add_path;
and i think it better to retigger add path uevent directly in check_path.
---
multipathd/main.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/multipathd/main.c b/multipathd/main.c
index d6f081f..3b1bea8 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -994,9 +994,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
pp->wwid_changed = 0;
}
- if (pp->initialized == INIT_REQUESTED_UDEV)
- retval = uev_add_path(uev, vecs);
- else if (mpp && ro >= 0) {
+ if (mpp && ro >= 0) {
condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
if (mpp->wait_for_udev)
@@ -1504,12 +1502,12 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
put_multipath_config(conf);
if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV &&
pp->retriggers < retrigger_tries) {
- condlog(2, "%s: triggering change event to reinitialize",
+ condlog(2, "%s: triggering add event to reinitialize",
pp->dev);
pp->initialized = INIT_REQUESTED_UDEV;
pp->retriggers++;
- sysfs_attr_set_value(pp->udev, "uevent", "change",
- strlen("change"));
+ sysfs_attr_set_value(pp->udev, "uevent", "add",
+ strlen("add"));
return 0;
}
--
2.8.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] multipathd: fix uev_update_path dead lock
2016-11-07 8:12 [PATCH] multipathd: fix uev_update_path dead lock tang.wenjun3
@ 2016-11-07 19:15 ` Benjamin Marzinski
0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Marzinski @ 2016-11-07 19:15 UTC (permalink / raw)
To: tang.wenjun3; +Cc: dm-devel, tang.junhui, zhang.kai16
On Mon, Nov 07, 2016 at 04:12:18PM +0800, tang.wenjun3@zte.com.cn wrote:
> From: 10144149 <tang.wenjun3@zte.com.cn>
>
> uev_update_path locked &vecs->lock, and it will get lock twice in uev_add_path;
> and i think it better to retigger add path uevent directly in check_path.
Good catch on the deadlock, but I'm not sure if triggering multiple
"add" events is a good idea. Generally, there's supposed to only be one
add event, and different actions can get run on them then on the change
events. Unless someone knows that this is o.k. I'd rather just break out
the reinitialization code from uev_add_path to its own function and call
that directly both uev_add_path and uev_update_path
-Ben
> ---
> multipathd/main.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/multipathd/main.c b/multipathd/main.c
> index d6f081f..3b1bea8 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -994,9 +994,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
> pp->wwid_changed = 0;
> }
>
> - if (pp->initialized == INIT_REQUESTED_UDEV)
> - retval = uev_add_path(uev, vecs);
> - else if (mpp && ro >= 0) {
> + if (mpp && ro >= 0) {
> condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
>
> if (mpp->wait_for_udev)
> @@ -1504,12 +1502,12 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
> put_multipath_config(conf);
> if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV &&
> pp->retriggers < retrigger_tries) {
> - condlog(2, "%s: triggering change event to reinitialize",
> + condlog(2, "%s: triggering add event to reinitialize",
> pp->dev);
> pp->initialized = INIT_REQUESTED_UDEV;
> pp->retriggers++;
> - sysfs_attr_set_value(pp->udev, "uevent", "change",
> - strlen("change"));
> + sysfs_attr_set_value(pp->udev, "uevent", "add",
> + strlen("add"));
> return 0;
> }
>
> --
> 2.8.1.windows.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] multipathd: fix uev_update_path dead lock
@ 2016-11-08 3:05 tang.wenjun3
2016-11-08 17:28 ` Benjamin Marzinski
0 siblings, 1 reply; 4+ messages in thread
From: tang.wenjun3 @ 2016-11-08 3:05 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: 10144149, tang.junhui, zhang.kai16, dm-devel
From: 10144149 <tang.wenjun3@zte.com.cn>
Deadlock occurred in uev_add_path() when &vecs->lock would lock twice in uev_update_path()
---
multipathd/main.c | 54 ++++++++++++++++++++++++++++++------------------------
multipathd/main.h | 1 +
2 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/multipathd/main.c b/multipathd/main.c
index d6f081f..e74d124 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -611,7 +611,7 @@ static int
uev_add_path (struct uevent *uev, struct vectors * vecs)
{
struct path *pp;
- int ret = 0, i;
+ int ret = 0;
struct config *conf;
condlog(2, "%s: add path (uevent)", uev->kernel);
@@ -628,32 +628,11 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
pthread_testcancel();
pp = find_path_by_dev(vecs->pathvec, uev->kernel);
if (pp) {
- int r;
-
condlog(0, "%s: spurious uevent, path already in pathvec",
uev->kernel);
if (!pp->mpp && !strlen(pp->wwid)) {
condlog(3, "%s: reinitialize path", uev->kernel);
- udev_device_unref(pp->udev);
- pp->udev = udev_device_ref(uev->udev);
- conf = get_multipath_config();
- r = pathinfo(pp, conf,
- DI_ALL | DI_BLACKLIST);
- put_multipath_config(conf);
- if (r == PATHINFO_OK)
- ret = ev_add_path(pp, vecs);
- else if (r == PATHINFO_SKIPPED) {
- condlog(3, "%s: remove blacklisted path",
- uev->kernel);
- i = find_slot(vecs->pathvec, (void *)pp);
- if (i != -1)
- vector_del_slot(vecs->pathvec, i);
- free_path(pp);
- } else {
- condlog(0, "%s: failed to reinitialize path",
- uev->kernel);
- ret = 1;
- }
+ ret = ev_add_path_with_pathinfo(uev->udev, pp, vecs);
}
}
lock_cleanup_pop(vecs->lock);
@@ -693,6 +672,33 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
return ret;
}
+int
+ev_add_path_with_pathinfo (struct udev_device *udevice, struct path * pp, struct vectors * vecs)
+{
+ int r;
+ int ret = 0, i;
+ struct config *conf;
+
+ udev_device_unref(pp->udev);
+ pp->udev = udev_device_ref(udevice);
+ conf = get_multipath_config();
+ r = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST);
+ put_multipath_config(conf);
+ if (r == PATHINFO_OK)
+ ret = ev_add_path(pp, vecs);
+ else if (r == PATHINFO_SKIPPED) {
+ condlog(3, "%s: remove blacklisted path", pp->dev);
+ i = find_slot(vecs->pathvec, (void *)pp);
+ if (i != -1)
+ vector_del_slot(vecs->pathvec, i);
+ free_path(pp);
+ } else {
+ condlog(0, "%s: failed to reinitialize path", pp->dev);
+ ret = 1;
+ }
+ return ret;
+}
+
/*
* returns:
* 0: added
@@ -995,7 +1001,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
}
if (pp->initialized == INIT_REQUESTED_UDEV)
- retval = uev_add_path(uev, vecs);
+ retval = ev_add_path_with_pathinfo(uev->udev, pp, vecs);
else if (mpp && ro >= 0) {
condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
diff --git a/multipathd/main.h b/multipathd/main.h
index f72580d..d3cd145 100644
--- a/multipathd/main.h
+++ b/multipathd/main.h
@@ -23,6 +23,7 @@ const char * daemon_status(void);
int need_to_delay_reconfig (struct vectors *);
int reconfigure (struct vectors *);
int ev_add_path (struct path *, struct vectors *);
+int ev_add_path_with_pathinfo (struct udev_device *, struct path *, struct vectors *);
int ev_remove_path (struct path *, struct vectors *);
int ev_add_map (char *, char *, struct vectors *);
int ev_remove_map (char *, char *, int, struct vectors *);
--
2.8.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] multipathd: fix uev_update_path dead lock
2016-11-08 3:05 tang.wenjun3
@ 2016-11-08 17:28 ` Benjamin Marzinski
0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Marzinski @ 2016-11-08 17:28 UTC (permalink / raw)
To: tang.wenjun3; +Cc: dm-devel, tang.junhui, zhang.kai16
On Tue, Nov 08, 2016 at 11:05:01AM +0800, tang.wenjun3@zte.com.cn wrote:
Thanks.
ACK
-Ben
> From: 10144149 <tang.wenjun3@zte.com.cn>
>
> Deadlock occurred in uev_add_path() when &vecs->lock would lock twice in uev_update_path()
> ---
> multipathd/main.c | 54 ++++++++++++++++++++++++++++++------------------------
> multipathd/main.h | 1 +
> 2 files changed, 31 insertions(+), 24 deletions(-)
>
> diff --git a/multipathd/main.c b/multipathd/main.c
> index d6f081f..e74d124 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -611,7 +611,7 @@ static int
> uev_add_path (struct uevent *uev, struct vectors * vecs)
> {
> struct path *pp;
> - int ret = 0, i;
> + int ret = 0;
> struct config *conf;
>
> condlog(2, "%s: add path (uevent)", uev->kernel);
> @@ -628,32 +628,11 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> pthread_testcancel();
> pp = find_path_by_dev(vecs->pathvec, uev->kernel);
> if (pp) {
> - int r;
> -
> condlog(0, "%s: spurious uevent, path already in pathvec",
> uev->kernel);
> if (!pp->mpp && !strlen(pp->wwid)) {
> condlog(3, "%s: reinitialize path", uev->kernel);
> - udev_device_unref(pp->udev);
> - pp->udev = udev_device_ref(uev->udev);
> - conf = get_multipath_config();
> - r = pathinfo(pp, conf,
> - DI_ALL | DI_BLACKLIST);
> - put_multipath_config(conf);
> - if (r == PATHINFO_OK)
> - ret = ev_add_path(pp, vecs);
> - else if (r == PATHINFO_SKIPPED) {
> - condlog(3, "%s: remove blacklisted path",
> - uev->kernel);
> - i = find_slot(vecs->pathvec, (void *)pp);
> - if (i != -1)
> - vector_del_slot(vecs->pathvec, i);
> - free_path(pp);
> - } else {
> - condlog(0, "%s: failed to reinitialize path",
> - uev->kernel);
> - ret = 1;
> - }
> + ret = ev_add_path_with_pathinfo(uev->udev, pp, vecs);
> }
> }
> lock_cleanup_pop(vecs->lock);
> @@ -693,6 +672,33 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
> return ret;
> }
>
> +int
> +ev_add_path_with_pathinfo (struct udev_device *udevice, struct path * pp, struct vectors * vecs)
> +{
> + int r;
> + int ret = 0, i;
> + struct config *conf;
> +
> + udev_device_unref(pp->udev);
> + pp->udev = udev_device_ref(udevice);
> + conf = get_multipath_config();
> + r = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST);
> + put_multipath_config(conf);
> + if (r == PATHINFO_OK)
> + ret = ev_add_path(pp, vecs);
> + else if (r == PATHINFO_SKIPPED) {
> + condlog(3, "%s: remove blacklisted path", pp->dev);
> + i = find_slot(vecs->pathvec, (void *)pp);
> + if (i != -1)
> + vector_del_slot(vecs->pathvec, i);
> + free_path(pp);
> + } else {
> + condlog(0, "%s: failed to reinitialize path", pp->dev);
> + ret = 1;
> + }
> + return ret;
> +}
> +
> /*
> * returns:
> * 0: added
> @@ -995,7 +1001,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
> }
>
> if (pp->initialized == INIT_REQUESTED_UDEV)
> - retval = uev_add_path(uev, vecs);
> + retval = ev_add_path_with_pathinfo(uev->udev, pp, vecs);
> else if (mpp && ro >= 0) {
> condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
>
> diff --git a/multipathd/main.h b/multipathd/main.h
> index f72580d..d3cd145 100644
> --- a/multipathd/main.h
> +++ b/multipathd/main.h
> @@ -23,6 +23,7 @@ const char * daemon_status(void);
> int need_to_delay_reconfig (struct vectors *);
> int reconfigure (struct vectors *);
> int ev_add_path (struct path *, struct vectors *);
> +int ev_add_path_with_pathinfo (struct udev_device *, struct path *, struct vectors *);
> int ev_remove_path (struct path *, struct vectors *);
> int ev_add_map (char *, char *, struct vectors *);
> int ev_remove_map (char *, char *, int, struct vectors *);
> --
> 2.8.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-08 17:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-07 8:12 [PATCH] multipathd: fix uev_update_path dead lock tang.wenjun3
2016-11-07 19:15 ` Benjamin Marzinski
-- strict thread matches above, loose matches on Subject: below --
2016-11-08 3:05 tang.wenjun3
2016-11-08 17:28 ` Benjamin Marzinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).