All of lore.kernel.org
 help / color / mirror / Atom feed
From: mwilck@suse.com
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	Guozhonghua <guozh88@chinatelecom.cn>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [dm-devel] [PATCH v2 04/11] multipathd: reset __delayed_reconfig from ev_add_map()
Date: Fri, 18 Mar 2022 23:33:32 +0100	[thread overview]
Message-ID: <20220318223339.4226-5-mwilck@suse.com> (raw)
In-Reply-To: <20220318223339.4226-1-mwilck@suse.com>

From: Martin Wilck <mwilck@suse.com>

With the previous patch, one race condition between child() and
the uevent handler (ev_add_map()) remains: 1. child() sets
__delayed_reconfig, 2. ev_add_map() calls schedule_reconfigure() and
thus DAEMON_CONFIGURE, 3. child() sets DAEMON_IDLE. This would cause
the pending reconfigure request to be missed.

To fix this, reset __delayed_reconfig immediately from ev_add_map()
(and likewise, missing_uev_wait_tick()). This way the wait loop in
child() terminates on the reconfigure_pending condition.

Also, these schedule_reconfigure() callers don't really request a
reconfigure() call; they just unblock processing previously requested
reconfigure() calls. Add a new helper, unblock_reconfigure(), that
does just that.

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

diff --git a/multipathd/main.c b/multipathd/main.c
index d033a9a..1454a18 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -155,16 +155,6 @@ int should_exit(void)
 	return get_running_state() == DAEMON_SHUTDOWN;
 }
 
-static bool get_delayed_reconfig(void)
-{
-	bool val;
-
-	pthread_mutex_lock(&config_lock);
-	val = __delayed_reconfig;
-	pthread_mutex_unlock(&config_lock);
-	return val;
-}
-
 /*
  * global copy of vecs for use in sig handlers
  */
@@ -308,6 +298,27 @@ void post_config_state(enum daemon_status state)
 	pthread_cleanup_pop(1);
 }
 
+static bool unblock_reconfigure(void)
+{
+	bool was_delayed;
+
+	pthread_mutex_lock(&config_lock);
+	was_delayed = __delayed_reconfig;
+	if (was_delayed) {
+		__delayed_reconfig = false;
+		/*
+		 * In IDLE state, make sure child() is woken up
+		 * Otherwise it will wake up when state switches to IDLE
+		 */
+		if (running_state == DAEMON_IDLE)
+			__post_config_state(DAEMON_CONFIGURE);
+	}
+	pthread_mutex_unlock(&config_lock);
+	if (was_delayed)
+		condlog(3, "unblocked delayed reconfigure");
+	return was_delayed;
+}
+
 void schedule_reconfigure(enum force_reload_types requested_type)
 {
 	pthread_mutex_lock(&config_lock);
@@ -790,12 +801,9 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs)
 		dm_get_info(mpp->alias, &mpp->dmi);
 		if (mpp->wait_for_udev) {
 			mpp->wait_for_udev = 0;
-			if (get_delayed_reconfig() &&
-			    !need_to_delay_reconfig(vecs)) {
-				condlog(2, "reconfigure (delayed)");
-				schedule_reconfigure(FORCE_RELOAD_WEAK);
+			if (!need_to_delay_reconfig(vecs) &&
+			    unblock_reconfigure())
 				return 0;
-			}
 		}
 		/*
 		 * Not really an error -- we generate our own uevent
@@ -1899,11 +1907,8 @@ missing_uev_wait_tick(struct vectors *vecs)
 		}
 	}
 
-	if (timed_out && get_delayed_reconfig() &&
-	    !need_to_delay_reconfig(vecs)) {
-		condlog(2, "reconfigure (delayed)");
-		schedule_reconfigure(FORCE_RELOAD_WEAK);
-	}
+	if (timed_out && !need_to_delay_reconfig(vecs))
+		unblock_reconfigure();
 }
 
 static void
-- 
2.35.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  parent reply	other threads:[~2022-03-18 22:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18 22:33 [dm-devel] [PATCH v2 00/11] multipathd: fix __delayed_reconfig logic mwilck
2022-03-18 22:33 ` [dm-devel] [PATCH v2 01/11] multipathd: child(): remove superfluous if condition mwilck
2022-03-22  0:18   ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 02/11] multipathd: set reload_type in when calling reconfigure() mwilck
2022-03-18 22:33 ` [dm-devel] [PATCH v2 03/11] multipathd: avoid busy loop in child() for delayed reconfigure mwilck
2022-03-22  0:19   ` Benjamin Marzinski
2022-03-18 22:33 ` mwilck [this message]
2022-03-22  0:21   ` [dm-devel] [PATCH v2 04/11] multipathd: reset __delayed_reconfig from ev_add_map() Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 05/11] multipathd: remove volatile qualifier from running_state mwilck
2022-03-22  0:23   ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 06/11] libmultipath: add callback for remove_map() mwilck
2022-03-22  0:28   ` Benjamin Marzinski
2022-03-22  8:35     ` Martin Wilck
2022-03-22 14:59       ` Benjamin Marzinski
2022-03-22 16:37         ` Martin Wilck
2022-03-18 22:33 ` [dm-devel] [PATCH v2 07/11] multipathd: use remove_map_callback for delayed reconfigure mwilck
2022-03-22  0:34   ` Benjamin Marzinski
2022-03-22  9:08     ` Martin Wilck
2022-03-22 15:36       ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 08/11] libmultipath: warn only once about deprecated options mwilck
2022-03-22  0:34   ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 09/11] multipathd: improve logging of reconfigure() mwilck
2022-03-22  0:35   ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 10/11] multipathd: log state changes mwilck
2022-03-22  0:37   ` Benjamin Marzinski
2022-03-18 22:33 ` [dm-devel] [PATCH v2 11/11] multipathd: remove unhelpful startup / shutdown messages mwilck
2022-03-22  0:43   ` Benjamin Marzinski
2022-03-22  9:30     ` Martin Wilck
2022-03-22 15:38       ` 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=20220318223339.4226-5-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    --cc=guozh88@chinatelecom.cn \
    /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.