All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benjamin Marzinski" <bmarzins@redhat.com>
To: dm-devel@redhat.com
Cc: Martin Wilck <mwilck@suse.com>, christophe.varoqui@free.fr
Subject: [PATCH 09/12] call start_waiter_thread() before setup_multipath()
Date: Wed, 14 Mar 2018 12:46:42 -0500	[thread overview]
Message-ID: <1521049605-22050-10-git-send-email-bmarzins@redhat.com> (raw)
In-Reply-To: <1521049605-22050-1-git-send-email-bmarzins@redhat.com>

If setup_multipath() is called before the waiter thread has started,
there is a window where a dm event can occur between when
setup_multipath() updates the device state and when the waiter thread
starts waiting for new events, causing the new event to be missed and
the multipath device to not get updated.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 multipathd/main.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index 2924d53..f116c74 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -326,7 +326,7 @@ set_multipath_wwid (struct multipath * mpp)
 }
 
 static int
-update_map (struct multipath *mpp, struct vectors *vecs)
+update_map (struct multipath *mpp, struct vectors *vecs, int new_map)
 {
 	int retries = 3;
 	char params[PARAMS_SIZE] = {0};
@@ -356,6 +356,12 @@ retry:
 	dm_lib_release();
 
 fail:
+	if (new_map && (retries < 0 || start_waiter_thread(mpp, vecs))) {
+		condlog(0, "%s: failed to create new map", mpp->alias);
+		remove_map(mpp, vecs, 1);
+		return 1;
+	}
+
 	if (setup_multipath(vecs, mpp))
 		return 1;
 
@@ -400,12 +406,9 @@ add_map_without_path (struct vectors *vecs, const char *alias)
 
 	vector_set_slot(vecs->mpvec, mpp);
 
-	if (update_map(mpp, vecs) != 0) /* map removed */
+	if (update_map(mpp, vecs, 1) != 0) /* map removed */
 		return NULL;
 
-	if (start_waiter_thread(mpp, vecs))
-		goto out;
-
 	return mpp;
 out:
 	remove_map(mpp, vecs, PURGE_VEC);
@@ -559,7 +562,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs)
 		if (mpp->wait_for_udev > 1) {
 			condlog(2, "%s: performing delayed actions",
 				mpp->alias);
-			if (update_map(mpp, vecs))
+			if (update_map(mpp, vecs, 0))
 				/* setup multipathd removed the map */
 				return 1;
 		}
@@ -870,6 +873,11 @@ retry:
 	}
 	dm_lib_release();
 
+	if ((mpp->action == ACT_CREATE ||
+	     (mpp->action == ACT_NOTHING && start_waiter && !mpp->waiter)) &&
+	    start_waiter_thread(mpp, vecs))
+			goto fail_map;
+
 	/*
 	 * update our state from kernel regardless of create or reload
 	 */
@@ -878,11 +886,6 @@ retry:
 
 	sync_map_state(mpp);
 
-	if ((mpp->action == ACT_CREATE ||
-	     (mpp->action == ACT_NOTHING && start_waiter && !mpp->waiter)) &&
-	    start_waiter_thread(mpp, vecs))
-			goto fail_map;
-
 	if (retries >= 0) {
 		condlog(2, "%s [%s]: path added to devmap %s",
 			pp->dev, pp->dev_t, mpp->alias);
@@ -1518,7 +1521,8 @@ missing_uev_wait_tick(struct vectors *vecs)
 		if (mpp->wait_for_udev && --mpp->uev_wait_tick <= 0) {
 			timed_out = 1;
 			condlog(0, "%s: timeout waiting on creation uevent. enabling reloads", mpp->alias);
-			if (mpp->wait_for_udev > 1 && update_map(mpp, vecs)) {
+			if (mpp->wait_for_udev > 1 &&
+			    update_map(mpp, vecs, 0)) {
 				/* update_map removed map */
 				i--;
 				continue;
@@ -1550,7 +1554,7 @@ ghost_delay_tick(struct vectors *vecs)
 			condlog(0, "%s: timed out waiting for active path",
 				mpp->alias);
 			mpp->force_udev_reload = 1;
-			if (update_map(mpp, vecs) != 0) {
+			if (update_map(mpp, vecs, 0) != 0) {
 				/* update_map removed map */
 				i--;
 				continue;
@@ -2199,14 +2203,13 @@ configure (struct vectors * vecs)
 	 * start dm event waiter threads for these new maps
 	 */
 	vector_foreach_slot(vecs->mpvec, mpp, i) {
-		if (setup_multipath(vecs, mpp)) {
-			i--;
-			continue;
-		}
 		if (start_waiter_thread(mpp, vecs)) {
 			remove_map(mpp, vecs, 1);
 			i--;
+			continue;
 		}
+		if (setup_multipath(vecs, mpp))
+			i--;
 	}
 	return 0;
 }
-- 
2.7.4

  parent reply	other threads:[~2018-03-14 17:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-14 17:46 [PATCH 00/12] multipath: new and rebased patches Benjamin Marzinski
2018-03-14 17:46 ` [PATCH 01/12] Unit tests for basenamecpy Benjamin Marzinski
2018-03-19  9:49   ` Martin Wilck
2018-03-19 10:05     ` Martin Wilck
2018-03-14 17:46 ` [PATCH 02/12] libmultipath: fix basenamecpy Benjamin Marzinski
2018-03-14 17:46 ` [PATCH 03/12] libmultipath: set dm_conf_verbosity Benjamin Marzinski
2018-03-19 10:18   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 04/12] multipathd: log thread cleanup Benjamin Marzinski
2018-03-19 10:20   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 05/12] libmultipath: fix log_pthread processing Benjamin Marzinski
2018-03-19 10:22   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 06/12] multipathd: use nanosleep for strict timing Benjamin Marzinski
2018-03-19 10:50   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 07/12] libmultipath: move remove_map waiter code to multipathd Benjamin Marzinski
2018-03-19 10:57   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 08/12] move waiter code from libmultipath " Benjamin Marzinski
2018-03-14 17:46 ` Benjamin Marzinski [this message]
2018-03-14 17:46 ` [PATCH 10/12] libmultipath: add helper functions Benjamin Marzinski
2018-03-14 17:46 ` [PATCH 11/12] multipathd: add new polling dmevents waiter thread Benjamin Marzinski
2018-03-19 12:48   ` Martin Wilck
2018-03-14 17:46 ` [PATCH 12/12] multipath: add unit tests for dmevents code Benjamin Marzinski
2018-03-19 12:01   ` Martin Wilck
2018-03-15 14:30 ` [PATCH 00/12] multipath: new and rebased patches Benjamin Marzinski

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=1521049605-22050-10-git-send-email-bmarzins@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@free.fr \
    --cc=dm-devel@redhat.com \
    --cc=mwilck@suse.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.