From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796065509; b=1tyN8pEBBYFHeiIV8prfDQHtr/4UijyEi0KNalpGWjBW8wOiaQQUeDbZszgedaYXTbs6 FPsj8VRDeTydeuPET1SMJUN9pP6TZjmlvsa+GAUPS50c35c5SxJRuJb3XUAqOe3sT6ArI xhc9t6+fOp0qGbRWrDpX4AtYM8Pb+VoT+9Buo9TtJXZxAelQEn77dYV1OKCjqcwOvL6Vy obuHwpmfmaO9j1FVfl/ke7PRoivHey4/E7RsQPpK4fjJGFdKAYMMrNBMZu0XY7bp/Dc3q lAKR6xKDto7yOr7yTqxzLPs+kTBYff28QuIkZWSGpAnA3ObRYPmYzUVRiHG8Ec3pIJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796065509; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Received:Received:Date:From: To:Cc:Subject:Message-ID:References:MIME-Version:In-Reply-To: X-Scanned-By:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition; bh=293gb562aoBQsIxbM8Y5D5UC56CWQvkk55O5iYWvfdM=; b=bV1iLRYus2+IM+jJd+GVGDTMucUHkBS0dFT4Rkif8UaGWLj8j6eO+ygypaNpDu5n2a+r YgHPa4hK7A6mVq6/26ysHemjbUd15ysobIcVIYTJ3xX/iQfYk40wHQatUXQio0A6y49/b 4Mky2vMJV/qtGurZGHsKf26YI+7Z64YlIlOEYQjnJNs7ehk2QNptXSdxizocGID1ZjsIH Eo+h3UMh2KTOxQCcRB6l2a3JF8dKdLPTgdqBhC69P2s0/cB7Exixkc7MzTMR8jzPX5wAF MfoSfjmpXMW/ryFZG6hiRdQgtMtfCT0Psp5lOf3BuDe8lW89ypqw+959zl+h4874CeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=igdJ7RK1; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CFDB606A320 for ; Mon, 30 Nov 2026 19:05:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4CFDB606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=igdJ7RK1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796065507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=293gb562aoBQsIxbM8Y5D5UC56CWQvkk55O5iYWvfdM=; b=igdJ7RK180zf2Tg0wjOR2+JePf9WrEBylPEInEPRdgd/Zo3SkJkHFNeyRq2rINr5Am8mEX 2PIxxmvUUNM/9zgUqY7FS7wet6sZZ6fsF3JBrIP8Pvh74hRLqrJFcstTuXC48wUE1iU1kw ZHSAx0aTpEI+6R+K5JPaP2QSwf5tN1E= X-MC-Rep: binary re single Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-kuUQazPWOt2SXao4Fces1A-1; Mon, 30 Nov 2026 19:05:04 +0000 X-MC-Unique: kuUQazPWOt2SXao4Fces1A-1 X-Mimecast-MFC-AGG-ID: kuUQazPWOt2SXao4Fces1A_1796065503 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 56D6D195F14D; Mon, 30 Nov 2026 19:05:03 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E3A7C30002D9; Mon, 30 Nov 2026 19:05:02 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.18.1/8.17.1) with ESMTPS id 6AUJ51gV3536137 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 30 Nov 2026 14:05:01 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.18.1/8.18.1/Submit) id 6AUJ50jx3536127; Mon, 30 Nov 2026 14:05:00 -0500 Date: Mon, 30 Nov 2026 14:05:00 -0500 From: Benjamin Marzinski To: Martin Wilck Cc: Christophe Varoqui , device-mapper development Subject: Re: [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete Message-ID: References: <20261126052434.725762-1-bmarzins@redhat.com> <20261126052434.725762-5-bmarzins@redhat.com> <179569332053.310906.14178249137263551915.b4-review@b4> X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <179569332053.310906.14178249137263551915.b4-review@b4> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9pfKHIbsmWdxtG-2dCt_3sMoT_eJx1BYp7jP8XFK9F4_1796065503 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Nov 26, 2026 at 12:42:00PM +0100, Martin Wilck wrote: > > Add the "reconfigure wait" and "reconfigure all wait" multipathd > > commands. These work just like the non-wait options, but they do not > > return until there are no more scheduled reconfigures. > > > > Signed-off-by: Benjamin Marzinski > > > > diff --git a/multipathd/callbacks.c b/multipathd/callbacks.c > > index 2027c3a..6064751 100644 > > --- a/multipathd/callbacks.c > > +++ b/multipathd/callbacks.c > > @@ -44,6 +44,9 @@ void init_handler_callbacks(void) > > set_unlocked_handler_callback(VRB_RECONFIGURE, HANDLER(cli_reconfigure)); > > set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_ALL, > > HANDLER(cli_reconfigure_all)); > > + set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_WAIT, HANDLER(cli_reconfigure_wait)); > > + set_unlocked_handler_callback(VRB_RECONFIGURE | Q1_ALL | Q2_WAIT, > > + HANDLER(cli_reconfigure_all_wait)); > > set_handler_callback(VRB_SUSPEND | Q1_MAP, HANDLER(cli_suspend)); > > set_handler_callback(VRB_RESUME | Q1_MAP, HANDLER(cli_resume)); > > set_handler_callback(VRB_RESIZE | Q1_MAP, HANDLER(cli_resize)); > > diff --git a/multipathd/cli.c b/multipathd/cli.c > > index 0d679c8..25dce4e 100644 > > --- a/multipathd/cli.c > > +++ b/multipathd/cli.c > > @@ -228,6 +228,7 @@ load_keys (void) > > r += add_key(keys, "setprhold", VRB_SETPRHOLD, 0); > > r += add_key(keys, "unsetprhold", VRB_UNSETPRHOLD, 0); > > r += add_key(keys, "pathlist", KEY_PATHLIST, 1); > > + r += add_key(keys, "wait", KEY_WAIT, 0); > > > > if (r) { > > free_keys(keys); > > diff --git a/multipathd/cli.h b/multipathd/cli.h > > index 6d599ca..1c6c42e 100644 > > --- a/multipathd/cli.h > > +++ b/multipathd/cli.h > > @@ -64,6 +64,7 @@ enum { > > KEY_GROUP = 82, > > KEY_KEY = 83, > > KEY_PATHLIST = 84, > > + KEY_WAIT = 85, > > }; > > > > /* > > @@ -85,6 +86,7 @@ enum { > > Q1_ALL = KEY_ALL << 8, > > Q1_DAEMON = KEY_DAEMON << 8, > > Q1_STATUS = KEY_STATUS << 8, > > + Q1_WAIT = KEY_WAIT << 8, > > > > /* byte 2: qualifier 2 */ > > Q2_FMT = KEY_FMT << 16, > > @@ -97,6 +99,7 @@ enum { > > Q2_GROUP = KEY_GROUP << 16, > > Q2_KEY = KEY_KEY << 16, > > Q2_PATHLIST = KEY_PATHLIST << 16, > > + Q2_WAIT = KEY_WAIT << 16, > > > > /* byte 3: qualifier 3 */ > > Q3_FMT = KEY_FMT << 24, > > diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c > > index e5c43bd..86f050a 100644 > > --- a/multipathd/cli_handlers.c > > +++ b/multipathd/cli_handlers.c > > @@ -1021,7 +1021,7 @@ static int cli_reconfigure(void *v, struct strbuf *reply, > > { > > condlog(2, "reconfigure (operator)"); > > > > - schedule_reconfigure(FORCE_RELOAD_WEAK); > > + schedule_reconfigure(FORCE_RELOAD_WEAK, NULL); > > return 0; > > } > > > > @@ -1030,7 +1030,25 @@ int cli_reconfigure_all(void *v, struct strbuf *reply, > > { > > condlog(2, "reconfigure all (operator)"); > > > > - schedule_reconfigure(FORCE_RELOAD_YES); > > + schedule_reconfigure(FORCE_RELOAD_YES, NULL); > > + return 0; > > +} > > + > > +static int cli_reconfigure_wait(void *v, struct strbuf *reply, > > + struct list_head *wait_node, void *data) > > +{ > > + condlog(2, "reconfigure wait (operator)"); > > + > > + schedule_reconfigure(FORCE_RELOAD_WEAK, wait_node); > > + return 0; > > +} > > + > > +static int cli_reconfigure_all_wait(void *v, struct strbuf *reply, > > + struct list_head *wait_node, void *data) > > +{ > > + condlog(2, "reconfigure all wait (operator)"); > > + > > + schedule_reconfigure(FORCE_RELOAD_YES, wait_node); > > return 0; > > } > > > > diff --git a/multipathd/main.c b/multipathd/main.c > > index 1bb8eac..83773d9 100644 > > --- a/multipathd/main.c > > +++ b/multipathd/main.c > > @@ -135,6 +135,8 @@ static enum daemon_status running_state = DAEMON_INIT; > > static bool delayed_reconfig; > > /* Don't access this variable without holding config_lock */ > > static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE; > > +/* Don't access this variable without holding config_lock */ > > +LIST_HEAD(config_wait_list); > > I am unsure about the purpose of using config_lock for this list. > The uxlsnr side uses client_wait_lock, and knows nothing about config_lock, > so it may manipulate elements of this list without taking config_lock. > The list should be protected by client_wait_lock. The client_wait_lock is a fast lock for clients to grab to check if they have been woken up or to remove themselves from the list. The config_lock is to make sure that scheduling the reconfigure and adding the wait_node to the config_wait_list are atomic, so there isn't a race between adding a waiter for a reconfigure and completing the reconfigure. Otherwise, you could have the following race: 1. The uxlsnr thread calls schedule_reconfigure() and schedules a reconfigure 2. The main thread child() does the reconfigure 3. The main thread child() removes all waiters from its list. 4. The uxlsnr thread schedule_reconfigure() adds the waiter to the list. 5. The client's wait_node remains on the config_wait_list, even though there is no pending reconfigure. You need to make sure that scheduling the reconfigure and adding the wait_node to the list happen under the same lock, otherwise the reconfigure and wakeup could happen in between them and the client could never get woken up. In theory, you could skip the client_wait_lock completely, and (in this case) use the config_lock for all the synchronization. But it won't always be the config_lock that you need to synchronize things. For wating on per-device events, you might have to hold the vecs lock to make sure that device isn't removed while you are adding the wait_node to the per-path wait list. We don't want to have to grab the vecs lock just to check if client has been woken up. So, there is a client_wait_lock that should almost never be under contention, to grab for simple list checking and manipulation. There is also another potential race if you don't check reconfigure_pending and wake up the waiters atomically. A schedule_reconfigure could come in after child() checks reconfigure_pending post reconfigure(), but before it calls wakeup_event_waiter(). Then a waiter would get woken up, without having waited for the reconfigure it scheduled. However, this issue can get cleaned up if we don't do my too-fancy lockless check. If we always check c->wait_node under a lock, then it's safe to modify it in the child() thread. In that case, while we're holding the config lock before the reconfigure call, where we set reconfigure_pending to FORCE_RELOAD_NONE, we can also use list_splice_tail_init() to move config_wait_list to a temporary list. Then we just wake up that temporary list after calling reconfigure. This means that waiters just wait for the first reconfigure that happens after they call a waiting reconfigure function, instead of waiting till there are no outstanding reconfigures. Calling list_splice_tail_init() on a config_wait_list will change the value of the tail wait_node's next pointer. It's possible that my too-fancy lockless read could see a torn write that just happened to make it look like wait_node->next it was pointing to wait_node, causing list_empty() to return true. > > pid_t daemon_pid; > > static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; > > static pthread_cond_t config_cond; > > @@ -336,7 +338,8 @@ void remove_map_callback(struct multipath *mpp) > > unblock_reconfigure(); > > } > > > > -void schedule_reconfigure(enum force_reload_types requested_type) > > +void schedule_reconfigure(enum force_reload_types requested_type, > > + struct list_head *wait_node) > > { > > pthread_mutex_lock(&config_lock); > > pthread_cleanup_push(config_cleanup, NULL); > > @@ -360,6 +363,8 @@ void schedule_reconfigure(enum force_reload_types requested_type) > > default: > > break; > > } > > + if (wait_node) > > + wait_for_event(wait_node, &config_wait_list); > > We should only wait for this event if reconfigure_pending ws actually set. > Waiting in DAEMON_SHUTDOWN state seems definitely wrong. Yep. Good catch. > > pthread_cleanup_pop(1); > > } > > > > @@ -3657,7 +3662,7 @@ handle_signals(bool nonfatal) > > return; > > if (reconfig_sig) { > > condlog(3, "reconfigure (signal)"); > > - schedule_reconfigure(FORCE_RELOAD_WEAK); > > + schedule_reconfigure(FORCE_RELOAD_WEAK, NULL); > > } > > if (log_reset_sig) { > > condlog(3, "reset log (signal)"); > > @@ -4169,6 +4174,12 @@ child (__attribute__((unused)) void *param) > > pthread_mutex_unlock(&config_lock); > > > > rc = reconfigure(vecs, reload_type); > > + > > + /* wake up waiters if there are no pending reconfigs */ > > + pthread_mutex_lock(&config_lock); > > + if (reconfigure_pending == FORCE_RELOAD_NONE) > > + wakeup_event_waiter(&config_wait_list); > > + pthread_mutex_unlock(&config_lock); > > } else { > > pthread_mutex_lock(&config_lock); > > delayed_reconfig = true; > > diff --git a/multipathd/main.h b/multipathd/main.h > > index b66208e..76d0919 100644 > > --- a/multipathd/main.h > > +++ b/multipathd/main.h > > @@ -34,7 +34,8 @@ void exit_daemon(void); > > const char *daemon_status(bool *pending_reconfig); > > enum daemon_status wait_for_state_change_if(enum daemon_status oldstate, > > unsigned long ms); > > -void schedule_reconfigure(enum force_reload_types requested_type); > > +void schedule_reconfigure(enum force_reload_types requested_type, > > + struct list_head *wait_node); > > int need_to_delay_reconfig (struct vectors *); > > int ev_add_path (struct path *, struct vectors *, int); > > int ev_remove_path (struct path *, struct vectors *, int); > > diff --git a/multipathd/multipathd.8.in b/multipathd/multipathd.8.in > > index 632cbe4..aee6700 100644 > > --- a/multipathd/multipathd.8.in > > +++ b/multipathd/multipathd.8.in > > @@ -274,13 +274,28 @@ group index, starting with 1. > > .B reconfigure > > Rereads the configuration, and reloads all changed multipath devices. This > > also happens at startup, when the service is reload, or when a SIGHUP is > > -received. > > +received. This command schedules the reconfiguration and returns immediately. > > +. > > +.TP > > +.B reconfigure wait > > +Rereads the configuration, and reloads all changed multipath devices. This > > +also happens at startup, when the service is reload, or when a SIGHUP is > > +received. This command waits for for the reconfiguration to complete before > > +returning > > Nit: "for for", missing period at end. > > The actual implementation waits for all scheduled reconfigure operations to end, > not just for "the" reconfiguration started by this command. Not sure if we need > to mention that, it may cause more confusion than insight, as overlapping > reconfigure requests are rare in practice. It didn't seem worthwhile to try and explain that. Also, like I said above, if we remove my lockless checking code, we can just wait for the next reconfigure to complete. -Ben > > . > > .TP > > .B reconfigure all > > Rereads the configuration, and reloads all multipath devices regardless of > > whether or not they have changed. This also happens when \fImultipath -r\fR is > > -run. > > +run. This command schedules the reconfiguration and returns immediately. > > +. > > +.TP > > +.B reconfigure all wait > > +Rereads the configuration, and reloads all multipath devices regardless of > > +whether or not they have changed. This also happens when \fImultipath -r\fR is > > +run. This command waits for for the reconfiguration to complete before > > +returning > > Same comment as for "reconfigure wait". > > -- > Martin Wilck