* [PATCH 0/4] multipath: add the ability to wait on events
@ 2026-11-26 5:24 Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 1/4] multipathd: make the wakeup and drain idle_fd code generic Benjamin Marzinski
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-26 5:24 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development, Martin Wilck
Multipathd doesn't react immediately to multiple things. Reconfiguration
doesn't happen immediately. Devices can be added and removed from the
system, and multipathd doesn't react until it gets a uevent. Sometimes
users need to wait for multipathd to finish handling these events before
doing further work. For instance a user script that reconfigures
multipath, and then verifies the new configuration can fail if the
reconfigure doesn't happen fast enough. User scripts might also need to
wait till a device is completely removed from multipath handling before
they can continue, or wait for a multipath device to be fully added
through udev, etc.
This patchset doesn't add all of these wait commands. It just adds the
architecture for doing them and adds the "reconfigure wait" and
"reconfigure all wait" commands, to schedule and then wait for a
reconfigure. Tracking uevent removes and additions (and first change
events for multipath devices) so these can be waited on is more
complicated and I haven't finished with them yet. But I wanted to make
sure that we agree on the overall waiting architecture.
Benjamin Marzinski (4):
multipathd: make the wakeup and drain idle_fd code generic
multipathd: add infrastructure for uxlsnr waiting on events
multipathd: make cli_handlers take a wait_node
multipathd: add commands to wait for reconfigures to complete
multipathd/callbacks.c | 3 +
multipathd/cli.c | 1 +
multipathd/cli.h | 7 +-
multipathd/cli_handlers.c | 246 ++++++++++++++++++++-----------------
multipathd/main.c | 22 +++-
multipathd/main.h | 3 +-
multipathd/multipathd.8.in | 19 ++-
multipathd/uxlsnr.c | 140 ++++++++++++++++++---
multipathd/uxlsnr.h | 4 +
9 files changed, 312 insertions(+), 133 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/4] multipathd: make the wakeup and drain idle_fd code generic
2026-11-26 5:24 [PATCH 0/4] multipath: add the ability to wait on events Benjamin Marzinski
@ 2026-11-26 5:24 ` Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events Benjamin Marzinski
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-26 5:24 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development, Martin Wilck
A future patch will add a new eventfd. Make the code to wake up
and drain an eventfd generic, so it can be reused.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipathd/uxlsnr.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index b8207306..e92784e5 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -384,21 +384,25 @@ static int execute_handler(struct client *c, struct vectors *vecs)
return c->handler->fn(c->cmdvec, &c->reply, vecs);
}
-static void wakeup_listener(void)
+static void wakeup_listener(int event_fd)
{
uint64_t one = 1;
- if (idle_fd != -1 &&
- write(idle_fd, &one, sizeof(one)) != sizeof(one))
+ if (event_fd != -1 && write(event_fd, &one, sizeof(one)) != sizeof(one))
condlog(1, "%s: failed", __func__);
}
-static void drain_idle_fd(int fd)
+static void wakeup_idle_listener(void)
+{
+ wakeup_listener(idle_fd);
+}
+
+static void drain_event_fd(int event_fd)
{
uint64_t val;
int rc;
- rc = read(fd, &val, sizeof(val));
+ rc = read(event_fd, &val, sizeof(val));
condlog(4, "%s: %d, %"PRIu64, __func__, rc, val);
}
@@ -665,7 +669,7 @@ void *uxsock_listen(int n_socks, long *ux_sock_in, void *trigger_data)
condlog(1, "failed to create idle fd");
exit_daemon();
} else
- set_wakeup_fn(&vecs->lock, wakeup_listener);
+ set_wakeup_fn(&vecs->lock, wakeup_idle_listener);
sigfillset(&mask);
sigdelset(&mask, SIGINT);
@@ -769,7 +773,7 @@ void *uxsock_listen(int n_socks, long *ux_sock_in, void *trigger_data)
if (polls[POLLFD_IDLE].fd != -1 &&
polls[POLLFD_IDLE].revents & POLLIN)
- drain_idle_fd(idle_fd);
+ drain_event_fd(idle_fd);
/* see if a client needs handling */
list_for_each_entry_safe(c, tmp, &clients, node) {
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events
2026-11-26 5:24 [PATCH 0/4] multipath: add the ability to wait on events Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 1/4] multipathd: make the wakeup and drain idle_fd code generic Benjamin Marzinski
@ 2026-11-26 5:24 ` Benjamin Marzinski
2026-11-26 11:42 ` Martin Wilck
2026-11-26 5:24 ` [PATCH 3/4] multipathd: make cli_handlers take a wait_node Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete Benjamin Marzinski
3 siblings, 1 reply; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-26 5:24 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development, Martin Wilck
There are multiple things that can happen to multipathd and the
devices it tracks, that multipathd only finishes handling later. User
programs may need to wait for these changes to complete before
continuing.
This commit add the architecture for waiting for events to occur. A
future patch will add the ability to actually register these wait
events. uxlnsr clients waiting for events will put themselves on a wait
list with wait_for_event(). If they exit early, they will take
themselves off with stop_waiting_for_event(). When the event occurs, the
thread processing the event will call wakeup_event_waiter() to remove
all clients from that wait list, and send a wakeup to the uslsnr thread.
This works via an eventfd, using the same code as idle_fd currently
does. Waiting clients check if their event has occured by checking if
they are still on a wait list.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipathd/main.c | 7 +++
multipathd/uxlsnr.c | 120 ++++++++++++++++++++++++++++++++++++++++----
multipathd/uxlsnr.h | 4 ++
3 files changed, 122 insertions(+), 9 deletions(-)
diff --git a/multipathd/main.c b/multipathd/main.c
index 9bce4d6b..1bb8eac8 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2009,6 +2009,12 @@ uxlsnrloop (void * ap)
goto out_sock;
}
+ if (init_wait_fd() < 0) {
+ condlog(1, "Failed to open wait_fd: %m");
+ exit_daemon();
+ goto out_sock;
+ }
+
/* Tell main thread that thread has started */
post_config_state(DAEMON_CONFIGURE);
@@ -3917,6 +3923,7 @@ static void cleanup_child(void)
cleanup_threads();
cleanup_vecs();
cleanup_bindings();
+ cleanup_wait_fd();
if (poll_dmevents)
cleanup_dmevent_waiter();
diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index e92784e5..09306918 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -49,11 +49,13 @@ enum {
CLT_PARSE,
CLT_LOCKED_WORK,
CLT_WORK,
+ CLT_WAIT,
CLT_SEND,
};
struct client {
struct list_head node;
+ struct list_head wait_node; /* for clients waiting on an event */
struct timespec expires;
int state;
int fd;
@@ -73,9 +75,13 @@ enum {
POLLFD_UX2,
POLLFD_NOTIFY,
POLLFD_IDLE,
+ POLLFD_WAIT,
POLLFDS_BASE,
};
+/* Add a new revents value to signal that a waiter wakeup event occurred */
+#define POLLWAIT 0x10000
+
#define POLLFD_CHUNK (4096 / sizeof(struct pollfd))
/* Minimum number of pollfds to reserve for clients */
#define MIN_POLLS (POLLFD_CHUNK - POLLFDS_BASE)
@@ -99,6 +105,8 @@ static LIST_HEAD(clients);
static struct pollfd *polls;
static int notify_fd = -1;
static int idle_fd = -1;
+static int wait_fd = -1;
+static pthread_mutex_t client_wait_lock = PTHREAD_MUTEX_INITIALIZER;
static bool clients_need_lock = false;
static bool _socket_client_is_root(int fd)
@@ -116,6 +124,8 @@ static bool _socket_client_is_root(int fd)
return false;
}
+static void stop_waiting_for_event(struct client *c);
+
/*
* kill off a dead client
*/
@@ -123,6 +133,7 @@ static void dead_client(struct client *c)
{
int fd = c->fd;
list_del_init(&c->node);
+ stop_waiting_for_event(c);
c->fd = -1;
reset_strbuf(&c->reply);
if (c->cmdvec)
@@ -152,6 +163,7 @@ static void new_client(int ux_sock, int non_root_clients)
return;
}
INIT_LIST_HEAD(&c->node);
+ INIT_LIST_HEAD(&c->wait_node);
c->fd = fd;
c->state = CLT_RECV;
c->is_root = _socket_client_is_root(c->fd);
@@ -384,6 +396,21 @@ static int execute_handler(struct client *c, struct vectors *vecs)
return c->handler->fn(c->cmdvec, &c->reply, vecs);
}
+int init_wait_fd(void)
+{
+ wait_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+
+ if (wait_fd < 0)
+ return -1;
+ return 0;
+}
+
+void cleanup_wait_fd(void)
+{
+ if (wait_fd >= 0)
+ close(wait_fd);
+}
+
static void wakeup_listener(int event_fd)
{
uint64_t one = 1;
@@ -397,6 +424,55 @@ static void wakeup_idle_listener(void)
wakeup_listener(idle_fd);
}
+void wait_for_event(struct list_head *wait_node, struct list_head *wait_list)
+{
+ pthread_mutex_lock(&client_wait_lock);
+ list_add(wait_node, wait_list);
+ pthread_mutex_unlock(&client_wait_lock);
+}
+
+void wakeup_event_waiter(struct list_head *wait_list)
+{
+ bool have_waiter = false;
+
+ pthread_mutex_lock(&client_wait_lock);
+ while (list_pop(wait_list))
+ have_waiter = true;
+ pthread_mutex_unlock(&client_wait_lock);
+ if (have_waiter)
+ wakeup_listener(wait_fd);
+}
+
+/* must only be called by uxlsnr_thr */
+static void stop_waiting_for_event(struct client *c)
+{
+ /*
+ * As long as clients will only be added to wait lists by uxlsnr_thr
+ * and only removed with list_del_init(), it is safe to check if
+ * wait_node is empty without holding client_wait_lock. uxlsnr_thr
+ * can't miss a client being added to the list, since a process is
+ * guaranteed to see all memory changes it did. It can miss a client
+ * being removed from the list or see a torn write from a concurrent
+ * removal, but this will just cause it to unnecessarily grab the lock
+ * and redo the removal.
+ */
+ if (!list_empty(&c->wait_node)) {
+ pthread_mutex_lock(&client_wait_lock);
+ list_del_init(&c->wait_node);
+ pthread_mutex_unlock(&client_wait_lock);
+ }
+}
+
+static bool finished_waiting(struct client *c)
+{
+ bool ret;
+
+ pthread_mutex_lock(&client_wait_lock);
+ ret = list_empty(&c->wait_node);
+ pthread_mutex_unlock(&client_wait_lock);
+ return ret;
+}
+
static void drain_event_fd(int event_fd)
{
uint64_t val;
@@ -466,8 +542,7 @@ enum {
STM_BREAK,
};
-static int client_state_machine(struct client *c, struct vectors *vecs,
- short revents)
+static int client_state_machine(struct client *c, struct vectors *vecs, int revents)
{
ssize_t n;
@@ -549,8 +624,15 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
check_for_locked_work(c);
pthread_cleanup_pop(1);
condlog(4, "%s: cli[%d] grabbed lock", __func__, c->fd);
- set_client_state(c, CLT_SEND);
- /* Wait for POLLOUT */
+ /*
+ * This list_empty() is safe to test without a lock for
+ * the same reason as in stop_waiting_for_event().
+ */
+ if (!c->error && !list_empty(&c->wait_node))
+ set_client_state(c, CLT_WAIT);
+ else
+ set_client_state(c, CLT_SEND);
+ /* Wait for POLLOUT or POLLWAIT */
return STM_BREAK;
} else {
condlog(4, "%s: cli[%d] waiting for lock", __func__, c->fd);
@@ -559,8 +641,18 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
case CLT_WORK:
c->error = execute_handler(c, vecs);
- set_client_state(c, CLT_SEND);
- /* Wait for POLLOUT */
+ if (!c->error && !list_empty(&c->wait_node))
+ set_client_state(c, CLT_WAIT);
+ else
+ set_client_state(c, CLT_SEND);
+ /* Wait for POLLOUT or POLLWAIT */
+ return STM_BREAK;
+
+ case CLT_WAIT:
+ if (!(revents & POLLWAIT))
+ return STM_BREAK;
+ if (finished_waiting(c))
+ set_client_state(c, CLT_SEND);
return STM_BREAK;
case CLT_SEND:
@@ -617,10 +709,11 @@ static void check_timeout(struct client *c)
c->fd, (long)c->expires.tv_sec, c->expires.tv_nsec / 1000000);
c->error = -ETIMEDOUT;
+ stop_waiting_for_event(c);
set_client_state(c, CLT_SEND);
}
-static void handle_client(struct client *c, struct vectors *vecs, short revents)
+static void handle_client(struct client *c, struct vectors *vecs, int revents)
{
if (revents & (POLLHUP|POLLERR)) {
c->error = -ECONNRESET;
@@ -677,6 +770,7 @@ void *uxsock_listen(int n_socks, long *ux_sock_in, void *trigger_data)
sigdelset(&mask, SIGHUP);
sigdelset(&mask, SIGUSR1);
while (1) {
+ int wait_event = 0;
struct client *c, *tmp;
int i, n_pfds, poll_count, num_clients, non_root_clients;
struct timespec __timeout, *timeout;
@@ -733,6 +827,9 @@ void *uxsock_listen(int n_socks, long *ux_sock_in, void *trigger_data)
else
polls[POLLFD_IDLE].events = 0;
+ polls[POLLFD_WAIT].fd = wait_fd;
+ polls[POLLFD_WAIT].events = POLLIN;
+
/* setup the clients */
i = POLLFDS_BASE;
list_for_each_entry(c, &clients, node) {
@@ -775,13 +872,18 @@ void *uxsock_listen(int n_socks, long *ux_sock_in, void *trigger_data)
polls[POLLFD_IDLE].revents & POLLIN)
drain_event_fd(idle_fd);
+ if (polls[POLLFD_WAIT].revents & POLLIN) {
+ drain_event_fd(wait_fd);
+ wait_event = POLLWAIT;
+ }
+
/* see if a client needs handling */
list_for_each_entry_safe(c, tmp, &clients, node) {
- short revents = 0;
+ int revents = wait_event;
for (i = POLLFDS_BASE; i < n_pfds; i++) {
if (polls[i].fd == c->fd) {
- revents = polls[i].revents;
+ revents |= polls[i].revents;
break;
}
}
diff --git a/multipathd/uxlsnr.h b/multipathd/uxlsnr.h
index a331e23b..d33920ea 100644
--- a/multipathd/uxlsnr.h
+++ b/multipathd/uxlsnr.h
@@ -6,5 +6,9 @@
bool waiting_clients(void);
void uxsock_cleanup(void *arg);
void *uxsock_listen(int n_socks, long *ux_sock, void *trigger_data);
+int init_wait_fd(void);
+void cleanup_wait_fd(void);
+void wait_for_event(struct list_head *wait_node, struct list_head *wait_list);
+void wakeup_event_waiter(struct list_head *wait_list);
#endif
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/4] multipathd: make cli_handlers take a wait_node
2026-11-26 5:24 [PATCH 0/4] multipath: add the ability to wait on events Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 1/4] multipathd: make the wakeup and drain idle_fd code generic Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events Benjamin Marzinski
@ 2026-11-26 5:24 ` Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete Benjamin Marzinski
3 siblings, 0 replies; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-26 5:24 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development, Martin Wilck
To enable client handler functions to add clients to wait lists, add
c->wait_node as a cli_handler argument.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipathd/cli.h | 4 +-
multipathd/cli_handlers.c | 224 ++++++++++++++++++++------------------
multipathd/uxlsnr.c | 2 +-
3 files changed, 120 insertions(+), 110 deletions(-)
diff --git a/multipathd/cli.h b/multipathd/cli.h
index 3e607389..6d599ca7 100644
--- a/multipathd/cli.h
+++ b/multipathd/cli.h
@@ -2,6 +2,7 @@
#define CLI_H_INCLUDED
#include <stdint.h>
+#include "list.h"
/*
* CLI commands consist of 4 bytes, a verb (byte 0) and up to
@@ -133,7 +134,8 @@ struct key {
struct strbuf;
-typedef int (cli_handler)(void *keywords, struct strbuf *reply, void *data);
+typedef int (cli_handler)(void *keywords, struct strbuf *reply,
+ struct list_head *wait_node, void *data);
struct handler {
uint32_t fingerprint;
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index f5a13c46..e5c43bd8 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -184,8 +184,8 @@ reset_stats(struct multipath * mpp)
mpp->stat_map_failures = 0;
}
-static int
-cli_list_config (void *v, struct strbuf *reply, void *data)
+static int cli_list_config(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(3, "list config (operator)");
@@ -197,8 +197,8 @@ static void v_free(void *x)
vector_free(x);
}
-static int
-cli_list_config_local (void *v, struct strbuf *reply, void *data)
+static int cli_list_config_local(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors *vecs = (struct vectors *)data;
vector hwes;
@@ -213,8 +213,8 @@ cli_list_config_local (void *v, struct strbuf *reply, void *data)
return ret;
}
-static int
-cli_list_paths (void *v, struct strbuf *reply, void *data)
+static int cli_list_paths(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -223,8 +223,8 @@ cli_list_paths (void *v, struct strbuf *reply, void *data)
return show_paths(reply, vecs, PRINT_PATH_CHECKER, 1);
}
-static int
-cli_list_paths_fmt (void *v, struct strbuf *reply, void *data)
+static int cli_list_paths_fmt(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * fmt = get_keyparam(v, KEY_FMT);
@@ -234,8 +234,8 @@ cli_list_paths_fmt (void *v, struct strbuf *reply, void *data)
return show_paths(reply, vecs, fmt, 1);
}
-static int
-cli_list_paths_raw (void *v, struct strbuf *reply, void * data)
+static int cli_list_paths_raw(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * fmt = get_keyparam(v, KEY_FMT);
@@ -245,8 +245,8 @@ cli_list_paths_raw (void *v, struct strbuf *reply, void * data)
return show_paths(reply, vecs, fmt, 0);
}
-static int
-cli_list_path (void *v, struct strbuf *reply, void *data)
+static int cli_list_path(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -262,8 +262,8 @@ cli_list_path (void *v, struct strbuf *reply, void *data)
return show_path(reply, vecs, pp, "%o");
}
-static int
-cli_list_map_topology (void *v, struct strbuf *reply, void *data)
+static int cli_list_map_topology(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -284,8 +284,8 @@ cli_list_map_topology (void *v, struct strbuf *reply, void *data)
return show_map_topology(reply, mpp, vecs, p_width);
}
-static int
-cli_list_maps_topology (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_topology(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -294,8 +294,8 @@ cli_list_maps_topology (void *v, struct strbuf *reply, void *data)
return show_maps_topology(reply, vecs);
}
-static int
-cli_list_map_json (void *v, struct strbuf *reply, void *data)
+static int cli_list_map_json(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -312,8 +312,8 @@ cli_list_map_json (void *v, struct strbuf *reply, void *data)
return show_map_json(reply, mpp, vecs);
}
-static int
-cli_list_maps_json (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_json(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -322,8 +322,8 @@ cli_list_maps_json (void *v, struct strbuf *reply, void *data)
return show_maps_json(reply, vecs);
}
-static int
-cli_list_wildcards (void *v, struct strbuf *reply, void *data)
+static int cli_list_wildcards(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
if (snprint_wildcards(reply) < 0)
return 1;
@@ -404,8 +404,8 @@ show_maps (struct strbuf *reply, struct vectors *vecs, char *style,
return 0;
}
-static int
-cli_list_maps_fmt (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_fmt(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * fmt = get_keyparam(v, KEY_FMT);
@@ -415,8 +415,8 @@ cli_list_maps_fmt (void *v, struct strbuf *reply, void *data)
return show_maps(reply, vecs, fmt, 1);
}
-static int
-cli_list_maps_raw (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_raw(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * fmt = get_keyparam(v, KEY_FMT);
@@ -426,8 +426,8 @@ cli_list_maps_raw (void *v, struct strbuf *reply, void *data)
return show_maps(reply, vecs, fmt, 0);
}
-static int
-cli_list_map_fmt (void *v, struct strbuf *reply, void *data)
+static int cli_list_map_fmt(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -448,8 +448,8 @@ cli_list_map_fmt (void *v, struct strbuf *reply, void *data)
return show_map(reply, mpp, fmt, width);
}
-static int
-cli_list_maps (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -458,8 +458,8 @@ cli_list_maps (void *v, struct strbuf *reply, void *data)
return show_maps(reply, vecs, PRINT_MAP_NAMES, 1);
}
-static int
-cli_list_status (void *v, struct strbuf *reply, void *data)
+static int cli_list_status(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -468,8 +468,8 @@ cli_list_status (void *v, struct strbuf *reply, void *data)
return show_status(reply, vecs);
}
-static int
-cli_list_maps_status (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_status(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -478,8 +478,8 @@ cli_list_maps_status (void *v, struct strbuf *reply, void *data)
return show_maps(reply, vecs, PRINT_MAP_STATUS, 1);
}
-static int
-cli_list_maps_stats (void *v, struct strbuf *reply, void *data)
+static int cli_list_maps_stats(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -488,16 +488,16 @@ cli_list_maps_stats (void *v, struct strbuf *reply, void *data)
return show_maps(reply, vecs, PRINT_MAP_STATS, 1);
}
-static int
-cli_list_daemon (void *v, struct strbuf *reply, void *data)
+static int cli_list_daemon(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(3, "list daemon (operator)");
return show_daemon(reply);
}
-static int
-cli_reset_maps_stats (void *v, struct strbuf *reply, void *data)
+static int cli_reset_maps_stats(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
int i;
@@ -511,8 +511,8 @@ cli_reset_maps_stats (void *v, struct strbuf *reply, void *data)
return 0;
}
-static int
-cli_reset_map_stats (void *v, struct strbuf *reply, void *data)
+static int cli_reset_map_stats(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
struct multipath * mpp;
@@ -560,8 +560,8 @@ add_partial_path(struct path *pp, struct vectors *vecs)
return finish_path_init(pp, vecs);
}
-static int
-cli_add_path (void *v, struct strbuf *reply, void *data)
+static int cli_add_path(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -680,8 +680,8 @@ blacklisted:
return 0;
}
-static int
-cli_del_path (void * v, struct strbuf *reply, void * data)
+static int cli_del_path(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -703,8 +703,8 @@ cli_del_path (void * v, struct strbuf *reply, void * data)
return (ret == REMOVE_PATH_FAILURE);
}
-static int
-cli_add_map (void * v, struct strbuf *reply, void * data)
+static int cli_add_map(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_MAP);
@@ -749,8 +749,8 @@ cli_add_map (void * v, struct strbuf *reply, void * data)
return rc;
}
-static int
-cli_del_map (void * v, struct strbuf *reply, void * data)
+static int cli_del_map(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_MAP);
@@ -773,8 +773,8 @@ cli_del_map (void * v, struct strbuf *reply, void * data)
return 1;
}
-static int
-cli_del_maps (void *v, struct strbuf *reply, void *data)
+static int cli_del_maps(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
struct multipath *mpp;
@@ -799,8 +799,8 @@ cli_del_maps (void *v, struct strbuf *reply, void *data)
return r;
}
-static int
-cli_reload(void *v, struct strbuf *reply, void *data)
+static int cli_reload(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * mapname = get_keyparam(v, KEY_MAP);
@@ -823,8 +823,8 @@ cli_reload(void *v, struct strbuf *reply, void *data)
return reload_and_sync_map(mpp, vecs);
}
-static int
-cli_resize(void *v, struct strbuf *reply, void *data)
+static int cli_resize(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * mapname = get_keyparam(v, KEY_MAP);
@@ -885,8 +885,8 @@ cli_resize(void *v, struct strbuf *reply, void *data)
return (ret != 0);
}
-static int
-cli_force_no_daemon_q(void * v, struct strbuf *reply, void * data)
+static int cli_force_no_daemon_q(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct config *conf;
@@ -898,8 +898,8 @@ cli_force_no_daemon_q(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_restore_no_daemon_q(void * v, struct strbuf *reply, void * data)
+static int cli_restore_no_daemon_q(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct config *conf;
@@ -911,8 +911,8 @@ cli_restore_no_daemon_q(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_restore_queueing(void *v, struct strbuf *reply, void *data)
+static int cli_restore_queueing(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * mapname = get_keyparam(v, KEY_MAP);
@@ -939,8 +939,8 @@ cli_restore_queueing(void *v, struct strbuf *reply, void *data)
return 0;
}
-static int
-cli_restore_all_queueing(void *v, struct strbuf *reply, void *data)
+static int cli_restore_all_queueing(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
struct multipath *mpp;
@@ -962,8 +962,8 @@ cli_restore_all_queueing(void *v, struct strbuf *reply, void *data)
return 0;
}
-static int
-cli_disable_queueing(void *v, struct strbuf *reply, void *data)
+static int cli_disable_queueing(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * mapname = get_keyparam(v, KEY_MAP);
@@ -985,8 +985,8 @@ cli_disable_queueing(void *v, struct strbuf *reply, void *data)
return 0;
}
-static int
-cli_disable_all_queueing(void *v, struct strbuf *reply, void *data)
+static int cli_disable_all_queueing(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
struct multipath *mpp;
@@ -1004,8 +1004,8 @@ cli_disable_all_queueing(void *v, struct strbuf *reply, void *data)
return 0;
}
-static int
-cli_switch_group(void * v, struct strbuf *reply, void * data)
+static int cli_switch_group(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
char * mapname = get_keyparam(v, KEY_MAP);
int groupnum = atoi(get_keyparam(v, KEY_GROUP));
@@ -1016,8 +1016,8 @@ cli_switch_group(void * v, struct strbuf *reply, void * data)
return dm_switchgroup(mapname, groupnum);
}
-static int
-cli_reconfigure(void * v, struct strbuf *reply, void * data)
+static int cli_reconfigure(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(2, "reconfigure (operator)");
@@ -1025,8 +1025,8 @@ cli_reconfigure(void * v, struct strbuf *reply, void * data)
return 0;
}
-int
-cli_reconfigure_all(void * v, struct strbuf *reply, void * data)
+int cli_reconfigure_all(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(2, "reconfigure all (operator)");
@@ -1034,8 +1034,8 @@ cli_reconfigure_all(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_suspend(void * v, struct strbuf *reply, void * data)
+static int cli_suspend(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_MAP);
@@ -1064,8 +1064,8 @@ cli_suspend(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_resume(void * v, struct strbuf *reply, void * data)
+static int cli_resume(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_MAP);
@@ -1096,8 +1096,8 @@ cli_resume(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_reinstate(void * v, struct strbuf *reply, void * data)
+static int cli_reinstate(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -1132,8 +1132,8 @@ cli_reinstate(void * v, struct strbuf *reply, void * data)
return dm_reinstate_path(pp->mpp->alias, pp->dev_t);
}
-static int
-cli_reassign (void * v, struct strbuf *reply, void * data)
+static int cli_reassign(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_MAP);
@@ -1157,7 +1157,7 @@ cli_reassign (void * v, struct strbuf *reply, void * data)
}
static int
-cli_fail(void * v, struct strbuf *reply, void * data)
+cli_fail(void *v, struct strbuf *reply, struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -1202,8 +1202,8 @@ show_blacklist (struct strbuf *reply)
return 0;
}
-static int
-cli_list_blacklist (void * v, struct strbuf *reply, void * data)
+static int cli_list_blacklist(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(3, "list blacklist (operator)");
@@ -1227,8 +1227,8 @@ show_devices (struct strbuf *reply, struct vectors *vecs)
return 0;
}
-static int
-cli_list_devices (void * v, struct strbuf *reply, void * data)
+static int cli_list_devices(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
@@ -1238,13 +1238,13 @@ cli_list_devices (void * v, struct strbuf *reply, void * data)
}
static int
-cli_quit (void * v, struct strbuf *reply, void * data)
+cli_quit(void *v, struct strbuf *reply, struct list_head *wait_node, void *data)
{
return 0;
}
-static int
-cli_shutdown (void * v, struct strbuf *reply, void * data)
+static int cli_shutdown(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
condlog(3, "shutdown (operator)");
exit_daemon();
@@ -1257,8 +1257,8 @@ static const char *const pr_str[] = {
[PR_SET] = "set\n",
};
-static int
-cli_getprstatus (void * v, struct strbuf *reply, void * data)
+static int cli_getprstatus(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -1303,12 +1303,14 @@ static int do_setprstatus(void *v, struct strbuf *reply, void *data,
return 0;
}
-static int cli_setprstatus(void *v, struct strbuf *reply, void *data)
+static int cli_setprstatus(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
return do_setprstatus(v, reply, data, NULL);
}
-static int cli_setprstatus_list(void *v, struct strbuf *reply, void *data)
+static int cli_setprstatus_list(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
int r;
struct vector_s registered_paths_vec = {.allocated = 0};
@@ -1331,8 +1333,8 @@ static int cli_setprstatus_list(void *v, struct strbuf *reply, void *data)
return r;
}
-static int
-cli_unsetprstatus(void * v, struct strbuf *reply, void * data)
+static int cli_unsetprstatus(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -1354,8 +1356,8 @@ cli_unsetprstatus(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_getprkey(void * v, struct strbuf *reply, void * data)
+static int cli_getprkey(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -1381,8 +1383,8 @@ cli_getprkey(void * v, struct strbuf *reply, void * data)
return 0;
}
-static int
-cli_unsetprkey(void * v, struct strbuf *reply, void * data)
+static int cli_unsetprkey(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -1405,8 +1407,8 @@ cli_unsetprkey(void * v, struct strbuf *reply, void * data)
return ret;
}
-static int
-cli_setprkey(void * v, struct strbuf *reply, void * data)
+static int cli_setprkey(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath * mpp;
struct vectors * vecs = (struct vectors *)data;
@@ -1452,17 +1454,20 @@ static int do_prhold(struct vectors *vecs, char *param, int prhold)
return 0;
}
-static int cli_setprhold(void *v, struct strbuf *reply, void *data)
+static int cli_setprhold(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
return do_prhold((struct vectors *)data, get_keyparam(v, KEY_MAP), PR_SET);
}
-static int cli_unsetprhold(void *v, struct strbuf *reply, void *data)
+static int cli_unsetprhold(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
return do_prhold((struct vectors *)data, get_keyparam(v, KEY_MAP), PR_UNSET);
}
-static int cli_getprhold(void *v, struct strbuf *reply, void *data)
+static int cli_getprhold(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct multipath *mpp;
struct vectors *vecs = (struct vectors *)data;
@@ -1479,7 +1484,8 @@ static int cli_getprhold(void *v, struct strbuf *reply, void *data)
return 0;
}
-static int cli_set_marginal(void * v, struct strbuf *reply, void * data)
+static int cli_set_marginal(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -1506,7 +1512,8 @@ static int cli_set_marginal(void * v, struct strbuf *reply, void * data)
return reload_and_sync_map(pp->mpp, vecs);
}
-static int cli_unset_marginal(void * v, struct strbuf *reply, void * data)
+static int cli_unset_marginal(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * param = get_keyparam(v, KEY_PATH);
@@ -1533,7 +1540,8 @@ static int cli_unset_marginal(void * v, struct strbuf *reply, void * data)
return reload_and_sync_map(pp->mpp, vecs);
}
-static int cli_unset_all_marginal(void * v, struct strbuf *reply, void * data)
+static int cli_unset_all_marginal(void *v, struct strbuf *reply,
+ struct list_head *wait_node, void *data)
{
struct vectors * vecs = (struct vectors *)data;
char * mapname = get_keyparam(v, KEY_MAP);
diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index 09306918..e8ce459d 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -393,7 +393,7 @@ static int execute_handler(struct client *c, struct vectors *vecs)
if (!c->handler || !c->handler->fn)
return -EINVAL;
- return c->handler->fn(c->cmdvec, &c->reply, vecs);
+ return c->handler->fn(c->cmdvec, &c->reply, &c->wait_node, vecs);
}
int init_wait_fd(void)
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete
2026-11-26 5:24 [PATCH 0/4] multipath: add the ability to wait on events Benjamin Marzinski
` (2 preceding siblings ...)
2026-11-26 5:24 ` [PATCH 3/4] multipathd: make cli_handlers take a wait_node Benjamin Marzinski
@ 2026-11-26 5:24 ` Benjamin Marzinski
2026-11-26 11:42 ` Martin Wilck
3 siblings, 1 reply; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-26 5:24 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development, Martin Wilck
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 <bmarzins@redhat.com>
---
multipathd/callbacks.c | 3 +++
multipathd/cli.c | 1 +
multipathd/cli.h | 3 +++
multipathd/cli_handlers.c | 22 ++++++++++++++++++++--
multipathd/main.c | 15 +++++++++++++--
multipathd/main.h | 3 ++-
multipathd/multipathd.8.in | 19 +++++++++++++++++--
7 files changed, 59 insertions(+), 7 deletions(-)
diff --git a/multipathd/callbacks.c b/multipathd/callbacks.c
index 2027c3a6..60647519 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 0d679c86..25dce4e5 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 6d599ca7..1c6c42e1 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 e5c43bd8..86f050a0 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 1bb8eac8..83773d90 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);
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);
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 b66208ec..76d09196 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 632cbe40..aee67004 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
.
.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
+.
.TP
.B suspend map|multipath $map
Sets map $map into suspend state.
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events
2026-11-26 5:24 ` [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events Benjamin Marzinski
@ 2026-11-26 11:42 ` Martin Wilck
2026-11-30 16:55 ` Benjamin Marzinski
0 siblings, 1 reply; 10+ messages in thread
From: Martin Wilck @ 2026-11-26 11:42 UTC (permalink / raw)
To: Benjamin Marzinski
Cc: Christophe Varoqui, device-mapper development, Martin Wilck
> There are multiple things that can happen to multipathd and the
> devices it tracks, that multipathd only finishes handling later. User
> programs may need to wait for these changes to complete before
> continuing.
>
> This commit add the architecture for waiting for events to occur. A
> future patch will add the ability to actually register these wait
> events. uxlnsr clients waiting for events will put themselves on a wait
> list with wait_for_event(). If they exit early, they will take
> themselves off with stop_waiting_for_event(). When the event occurs, the
> thread processing the event will call wakeup_event_waiter() to remove
> all clients from that wait list, and send a wakeup to the uslsnr thread.
> This works via an eventfd, using the same code as idle_fd currently
> does. Waiting clients check if their event has occured by checking if
> they are still on a wait list.
>
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
>
> diff --git a/multipathd/main.c b/multipathd/main.c
> index 9bce4d6..1bb8eac 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -2009,6 +2009,12 @@ uxlsnrloop (void * ap)
> goto out_sock;
> }
>
> + if (init_wait_fd() < 0) {
> + condlog(1, "Failed to open wait_fd: %m");
> + exit_daemon();
> + goto out_sock;
> + }
> +
> /* Tell main thread that thread has started */
> post_config_state(DAEMON_CONFIGURE);
>
> @@ -3917,6 +3923,7 @@ static void cleanup_child(void)
> cleanup_threads();
> cleanup_vecs();
> cleanup_bindings();
> + cleanup_wait_fd();
> if (poll_dmevents)
> cleanup_dmevent_waiter();
>
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index e92784e..0930691 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -49,11 +49,13 @@ enum {
> CLT_PARSE,
> CLT_LOCKED_WORK,
> CLT_WORK,
> + CLT_WAIT,
> CLT_SEND,
> };
>
> struct client {
> struct list_head node;
> + struct list_head wait_node; /* for clients waiting on an event */
> struct timespec expires;
> int state;
> int fd;
> @@ -73,9 +75,13 @@ enum {
> POLLFD_UX2,
> POLLFD_NOTIFY,
> POLLFD_IDLE,
> + POLLFD_WAIT,
> POLLFDS_BASE,
> };
>
> +/* Add a new revents value to signal that a waiter wakeup event occurred */
> +#define POLLWAIT 0x10000
> +
> #define POLLFD_CHUNK (4096 / sizeof(struct pollfd))
> /* Minimum number of pollfds to reserve for clients */
> #define MIN_POLLS (POLLFD_CHUNK - POLLFDS_BASE)
> @@ -99,6 +105,8 @@ static LIST_HEAD(clients);
> static struct pollfd *polls;
> static int notify_fd = -1;
> static int idle_fd = -1;
> +static int wait_fd = -1;
> +static pthread_mutex_t client_wait_lock = PTHREAD_MUTEX_INITIALIZER;
> static bool clients_need_lock = false;
>
> static bool _socket_client_is_root(int fd)
> @@ -116,6 +124,8 @@ static bool _socket_client_is_root(int fd)
> return false;
> }
>
> +static void stop_waiting_for_event(struct client *c);
> +
> /*
> * kill off a dead client
> */
> @@ -123,6 +133,7 @@ static void dead_client(struct client *c)
> {
> int fd = c->fd;
> list_del_init(&c->node);
> + stop_waiting_for_event(c);
> c->fd = -1;
> reset_strbuf(&c->reply);
> if (c->cmdvec)
> @@ -152,6 +163,7 @@ static void new_client(int ux_sock, int non_root_clients)
> return;
> }
> INIT_LIST_HEAD(&c->node);
> + INIT_LIST_HEAD(&c->wait_node);
> c->fd = fd;
> c->state = CLT_RECV;
> c->is_root = _socket_client_is_root(c->fd);
> @@ -384,6 +396,21 @@ static int execute_handler(struct client *c, struct vectors *vecs)
> return c->handler->fn(c->cmdvec, &c->reply, vecs);
> }
>
> +int init_wait_fd(void)
> +{
> + wait_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
> +
> + if (wait_fd < 0)
> + return -1;
> + return 0;
> +}
> +
> +void cleanup_wait_fd(void)
> +{
> + if (wait_fd >= 0)
> + close(wait_fd);
Nit: set wait_fd = -1 after closing.
> +}
> +
> static void wakeup_listener(int event_fd)
> {
> uint64_t one = 1;
> @@ -397,6 +424,55 @@ static void wakeup_idle_listener(void)
> wakeup_listener(idle_fd);
> }
>
> +void wait_for_event(struct list_head *wait_node, struct list_head *wait_list)
> +{
> + pthread_mutex_lock(&client_wait_lock);
> + list_add(wait_node, wait_list);
> + pthread_mutex_unlock(&client_wait_lock);
> +}
> +
> +void wakeup_event_waiter(struct list_head *wait_list)
> +{
> + bool have_waiter = false;
> +
> + pthread_mutex_lock(&client_wait_lock);
> + while (list_pop(wait_list))
> + have_waiter = true;
> + pthread_mutex_unlock(&client_wait_lock);
> + if (have_waiter)
> + wakeup_listener(wait_fd);
> +}
This function "wakes up" all waiters, even though the waiters may be waiting
for different conditions to come true.
> +
> +/* must only be called by uxlsnr_thr */
> +static void stop_waiting_for_event(struct client *c)
> +{
> + /*
> + * As long as clients will only be added to wait lists by uxlsnr_thr
> + * and only removed with list_del_init(), it is safe to check if
> + * wait_node is empty without holding client_wait_lock. uxlsnr_thr
> + * can't miss a client being added to the list, since a process is
> + * guaranteed to see all memory changes it did. It can miss a client
> + * being removed from the list or see a torn write from a concurrent
> + * removal, but this will just cause it to unnecessarily grab the lock
> + * and redo the removal.
> + */
> + if (!list_empty(&c->wait_node)) {
Tbh, I don't like this super-smart optimization. I would prefer just taking
the lock. If we find this to hurt performance, we could change the
implementation to RCU.
> + pthread_mutex_lock(&client_wait_lock);
> + list_del_init(&c->wait_node);
> + pthread_mutex_unlock(&client_wait_lock);
> + }
> +}
> +
> +static bool finished_waiting(struct client *c)
> +{
> + bool ret;
> +
> + pthread_mutex_lock(&client_wait_lock);
> + ret = list_empty(&c->wait_node);
> + pthread_mutex_unlock(&client_wait_lock);
> + return ret;
> +}
wakeup_event_waiter() will remove the wait_node from the list, regardless whether
the specific condition this thread is waiting for has come true. So the client
may return prematurely.
> +
> static void drain_event_fd(int event_fd)
> {
> uint64_t val;
> @@ -466,8 +542,7 @@ enum {
> STM_BREAK,
> };
>
> -static int client_state_machine(struct client *c, struct vectors *vecs,
> - short revents)
> +static int client_state_machine(struct client *c, struct vectors *vecs, int revents)
> {
> ssize_t n;
>
> @@ -549,8 +624,15 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
> check_for_locked_work(c);
> pthread_cleanup_pop(1);
> condlog(4, "%s: cli[%d] grabbed lock", __func__, c->fd);
> - set_client_state(c, CLT_SEND);
> - /* Wait for POLLOUT */
> + /*
> + * This list_empty() is safe to test without a lock for
> + * the same reason as in stop_waiting_for_event().
> + */
> + if (!c->error && !list_empty(&c->wait_node))
See above about the lock optimization.
> + set_client_state(c, CLT_WAIT);
> + else
> + set_client_state(c, CLT_SEND);
> + /* Wait for POLLOUT or POLLWAIT */
> return STM_BREAK;
> } else {
> condlog(4, "%s: cli[%d] waiting for lock", __func__, c->fd);
> @@ -559,8 +641,18 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
>
> case CLT_WORK:
> c->error = execute_handler(c, vecs);
> - set_client_state(c, CLT_SEND);
> - /* Wait for POLLOUT */
> + if (!c->error && !list_empty(&c->wait_node))
> + set_client_state(c, CLT_WAIT);
> + else
> + set_client_state(c, CLT_SEND);
> + /* Wait for POLLOUT or POLLWAIT */
> + return STM_BREAK;
> +
> + case CLT_WAIT:
> + if (!(revents & POLLWAIT))
> + return STM_BREAK;
> + if (finished_waiting(c))
> + set_client_state(c, CLT_SEND);
As noted above, any call to wakeup_event_waiter() will wake up this client and
make finished_waiting() return true. This is fine as long we have just a
single condition to wait for, but as soon as we use this mechanism more
widely, we will need a way to check whether our wait condition is actually
true and keep waiting otherwise, like __wait_event() in the kernel.
Or am I overlooking something here?
--
Martin Wilck <mwilck@suse.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete
2026-11-26 5:24 ` [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete Benjamin Marzinski
@ 2026-11-26 11:42 ` Martin Wilck
2026-11-30 19:05 ` Benjamin Marzinski
0 siblings, 1 reply; 10+ messages in thread
From: Martin Wilck @ 2026-11-26 11:42 UTC (permalink / raw)
To: Benjamin Marzinski
Cc: Christophe Varoqui, device-mapper development, Martin Wilck
> 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 <bmarzins@redhat.com>
>
> 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.
> 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.
> 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.
> .
> .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 <mwilck@suse.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events
2026-11-26 11:42 ` Martin Wilck
@ 2026-11-30 16:55 ` Benjamin Marzinski
2026-12-01 23:46 ` Benjamin Marzinski
0 siblings, 1 reply; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-30 16:55 UTC (permalink / raw)
To: Martin Wilck; +Cc: Christophe Varoqui, device-mapper development
On Thu, Nov 26, 2026 at 12:42:00PM +0100, Martin Wilck wrote:
> > There are multiple things that can happen to multipathd and the
> > devices it tracks, that multipathd only finishes handling later. User
> > programs may need to wait for these changes to complete before
> > continuing.
> >
> > This commit add the architecture for waiting for events to occur. A
> > future patch will add the ability to actually register these wait
> > events. uxlnsr clients waiting for events will put themselves on a wait
> > list with wait_for_event(). If they exit early, they will take
> > themselves off with stop_waiting_for_event(). When the event occurs, the
> > thread processing the event will call wakeup_event_waiter() to remove
> > all clients from that wait list, and send a wakeup to the uslsnr thread.
> > This works via an eventfd, using the same code as idle_fd currently
> > does. Waiting clients check if their event has occured by checking if
> > they are still on a wait list.
> >
> > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> >
> > diff --git a/multipathd/main.c b/multipathd/main.c
> > index 9bce4d6..1bb8eac 100644
> > --- a/multipathd/main.c
> > +++ b/multipathd/main.c
> > @@ -2009,6 +2009,12 @@ uxlsnrloop (void * ap)
> > goto out_sock;
> > }
> >
> > + if (init_wait_fd() < 0) {
> > + condlog(1, "Failed to open wait_fd: %m");
> > + exit_daemon();
> > + goto out_sock;
> > + }
> > +
> > /* Tell main thread that thread has started */
> > post_config_state(DAEMON_CONFIGURE);
> >
> > @@ -3917,6 +3923,7 @@ static void cleanup_child(void)
> > cleanup_threads();
> > cleanup_vecs();
> > cleanup_bindings();
> > + cleanup_wait_fd();
> > if (poll_dmevents)
> > cleanup_dmevent_waiter();
> >
> > diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> > index e92784e..0930691 100644
> > --- a/multipathd/uxlsnr.c
> > +++ b/multipathd/uxlsnr.c
> > @@ -49,11 +49,13 @@ enum {
> > CLT_PARSE,
> > CLT_LOCKED_WORK,
> > CLT_WORK,
> > + CLT_WAIT,
> > CLT_SEND,
> > };
> >
> > struct client {
> > struct list_head node;
> > + struct list_head wait_node; /* for clients waiting on an event */
> > struct timespec expires;
> > int state;
> > int fd;
> > @@ -73,9 +75,13 @@ enum {
> > POLLFD_UX2,
> > POLLFD_NOTIFY,
> > POLLFD_IDLE,
> > + POLLFD_WAIT,
> > POLLFDS_BASE,
> > };
> >
> > +/* Add a new revents value to signal that a waiter wakeup event occurred */
> > +#define POLLWAIT 0x10000
> > +
> > #define POLLFD_CHUNK (4096 / sizeof(struct pollfd))
> > /* Minimum number of pollfds to reserve for clients */
> > #define MIN_POLLS (POLLFD_CHUNK - POLLFDS_BASE)
> > @@ -99,6 +105,8 @@ static LIST_HEAD(clients);
> > static struct pollfd *polls;
> > static int notify_fd = -1;
> > static int idle_fd = -1;
> > +static int wait_fd = -1;
> > +static pthread_mutex_t client_wait_lock = PTHREAD_MUTEX_INITIALIZER;
> > static bool clients_need_lock = false;
> >
> > static bool _socket_client_is_root(int fd)
> > @@ -116,6 +124,8 @@ static bool _socket_client_is_root(int fd)
> > return false;
> > }
> >
> > +static void stop_waiting_for_event(struct client *c);
> > +
> > /*
> > * kill off a dead client
> > */
> > @@ -123,6 +133,7 @@ static void dead_client(struct client *c)
> > {
> > int fd = c->fd;
> > list_del_init(&c->node);
> > + stop_waiting_for_event(c);
> > c->fd = -1;
> > reset_strbuf(&c->reply);
> > if (c->cmdvec)
> > @@ -152,6 +163,7 @@ static void new_client(int ux_sock, int non_root_clients)
> > return;
> > }
> > INIT_LIST_HEAD(&c->node);
> > + INIT_LIST_HEAD(&c->wait_node);
> > c->fd = fd;
> > c->state = CLT_RECV;
> > c->is_root = _socket_client_is_root(c->fd);
> > @@ -384,6 +396,21 @@ static int execute_handler(struct client *c, struct vectors *vecs)
> > return c->handler->fn(c->cmdvec, &c->reply, vecs);
> > }
> >
> > +int init_wait_fd(void)
> > +{
> > + wait_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
> > +
> > + if (wait_fd < 0)
> > + return -1;
> > + return 0;
> > +}
> > +
> > +void cleanup_wait_fd(void)
> > +{
> > + if (wait_fd >= 0)
> > + close(wait_fd);
>
> Nit: set wait_fd = -1 after closing.
Sure.
> > +}
> > +
> > static void wakeup_listener(int event_fd)
> > {
> > uint64_t one = 1;
> > @@ -397,6 +424,55 @@ static void wakeup_idle_listener(void)
> > wakeup_listener(idle_fd);
> > }
> >
> > +void wait_for_event(struct list_head *wait_node, struct list_head *wait_list)
> > +{
> > + pthread_mutex_lock(&client_wait_lock);
> > + list_add(wait_node, wait_list);
> > + pthread_mutex_unlock(&client_wait_lock);
> > +}
> > +
> > +void wakeup_event_waiter(struct list_head *wait_list)
> > +{
> > + bool have_waiter = false;
> > +
> > + pthread_mutex_lock(&client_wait_lock);
> > + while (list_pop(wait_list))
> > + have_waiter = true;
> > + pthread_mutex_unlock(&client_wait_lock);
> > + if (have_waiter)
> > + wakeup_listener(wait_fd);
> > +}
>
> This function "wakes up" all waiters, even though the waiters may be waiting
> for different conditions to come true.
The way this is supposed to work is that there will be a list per event
that a client could wait on. For removing paths, for instance, there
will be a new per-path list_head (well, basically. There is extra issues
I want to deal with in the wait on addition and wait on remove code,
which I'm still working on). Multiple clients could be waiting for a
reconfigure or a device to get removed, and we want all of them woken.
But there shouldn't be clients on a list who aren't waiting for that
specific event.
> > +
> > +/* must only be called by uxlsnr_thr */
> > +static void stop_waiting_for_event(struct client *c)
> > +{
> > + /*
> > + * As long as clients will only be added to wait lists by uxlsnr_thr
> > + * and only removed with list_del_init(), it is safe to check if
> > + * wait_node is empty without holding client_wait_lock. uxlsnr_thr
> > + * can't miss a client being added to the list, since a process is
> > + * guaranteed to see all memory changes it did. It can miss a client
> > + * being removed from the list or see a torn write from a concurrent
> > + * removal, but this will just cause it to unnecessarily grab the lock
> > + * and redo the removal.
> > + */
> > + if (!list_empty(&c->wait_node)) {
>
> Tbh, I don't like this super-smart optimization. I would prefer just taking
> the lock. If we find this to hurt performance, we could change the
> implementation to RCU.
It just seems wrong to grab the lock every time any client exits. Would
you be o.k. with having a special return value from the client handler
functions to signal that the client needs to wait and a flag that
clients can set when they get this return? Clients who haven't set the
flag can skip the lock, just like with the current list empty code. Only
the uxlsnr thread would set and check the flag, so there's no locking
needed.
> > + pthread_mutex_lock(&client_wait_lock);
> > + list_del_init(&c->wait_node);
> > + pthread_mutex_unlock(&client_wait_lock);
> > + }
> > +}
> > +
> > +static bool finished_waiting(struct client *c)
> > +{
> > + bool ret;
> > +
> > + pthread_mutex_lock(&client_wait_lock);
> > + ret = list_empty(&c->wait_node);
> > + pthread_mutex_unlock(&client_wait_lock);
> > + return ret;
> > +}
>
> wakeup_event_waiter() will remove the wait_node from the list, regardless whether
> the specific condition this thread is waiting for has come true. So the client
> may return prematurely.
Like I said, clients will be on a list exclusively for the event they
are waiting on. When the get removed, their event occurred.
> > +
> > static void drain_event_fd(int event_fd)
> > {
> > uint64_t val;
> > @@ -466,8 +542,7 @@ enum {
> > STM_BREAK,
> > };
> >
> > -static int client_state_machine(struct client *c, struct vectors *vecs,
> > - short revents)
> > +static int client_state_machine(struct client *c, struct vectors *vecs, int revents)
> > {
> > ssize_t n;
> >
> > @@ -549,8 +624,15 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
> > check_for_locked_work(c);
> > pthread_cleanup_pop(1);
> > condlog(4, "%s: cli[%d] grabbed lock", __func__, c->fd);
> > - set_client_state(c, CLT_SEND);
> > - /* Wait for POLLOUT */
> > + /*
> > + * This list_empty() is safe to test without a lock for
> > + * the same reason as in stop_waiting_for_event().
> > + */
> > + if (!c->error && !list_empty(&c->wait_node))
>
> See above about the lock optimization.
We can avoid this with the client waiting flag as well. It might be
over-optimizing but it's not a fancy lock-skipping optimization and I'd
rather avoid grabbing a lock twice for every client, when almost none of
them are going to need it. If your really against that, that's fine. We
can just always check this under a lock.
> > + set_client_state(c, CLT_WAIT);
> > + else
> > + set_client_state(c, CLT_SEND);
> > + /* Wait for POLLOUT or POLLWAIT */
> > return STM_BREAK;
> > } else {
> > condlog(4, "%s: cli[%d] waiting for lock", __func__, c->fd);
> > @@ -559,8 +641,18 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
> >
> > case CLT_WORK:
> > c->error = execute_handler(c, vecs);
> > - set_client_state(c, CLT_SEND);
> > - /* Wait for POLLOUT */
> > + if (!c->error && !list_empty(&c->wait_node))
> > + set_client_state(c, CLT_WAIT);
> > + else
> > + set_client_state(c, CLT_SEND);
> > + /* Wait for POLLOUT or POLLWAIT */
> > + return STM_BREAK;
> > +
> > + case CLT_WAIT:
> > + if (!(revents & POLLWAIT))
> > + return STM_BREAK;
> > + if (finished_waiting(c))
> > + set_client_state(c, CLT_SEND);
>
> As noted above, any call to wakeup_event_waiter() will wake up this client and
> make finished_waiting() return true. This is fine as long we have just a
> single condition to wait for, but as soon as we use this mechanism more
> widely, we will need a way to check whether our wait condition is actually
> true and keep waiting otherwise, like __wait_event() in the kernel.
>
> Or am I overlooking something here?
See above.
-Ben
>
> --
> Martin Wilck <mwilck@suse.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete
2026-11-26 11:42 ` Martin Wilck
@ 2026-11-30 19:05 ` Benjamin Marzinski
0 siblings, 0 replies; 10+ messages in thread
From: Benjamin Marzinski @ 2026-11-30 19:05 UTC (permalink / raw)
To: Martin Wilck; +Cc: Christophe Varoqui, device-mapper development
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 <bmarzins@redhat.com>
> >
> > 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 <mwilck@suse.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events
2026-11-30 16:55 ` Benjamin Marzinski
@ 2026-12-01 23:46 ` Benjamin Marzinski
0 siblings, 0 replies; 10+ messages in thread
From: Benjamin Marzinski @ 2026-12-01 23:46 UTC (permalink / raw)
To: Martin Wilck; +Cc: Christophe Varoqui, device-mapper development
On Mon, Nov 30, 2026 at 11:55:04AM -0500, Benjamin Marzinski wrote:
> On Thu, Nov 26, 2026 at 12:42:00PM +0100, Martin Wilck wrote:
> > > +/* must only be called by uxlsnr_thr */
> > > +static void stop_waiting_for_event(struct client *c)
> > > +{
> > > + /*
> > > + * As long as clients will only be added to wait lists by uxlsnr_thr
> > > + * and only removed with list_del_init(), it is safe to check if
> > > + * wait_node is empty without holding client_wait_lock. uxlsnr_thr
> > > + * can't miss a client being added to the list, since a process is
> > > + * guaranteed to see all memory changes it did. It can miss a client
> > > + * being removed from the list or see a torn write from a concurrent
> > > + * removal, but this will just cause it to unnecessarily grab the lock
> > > + * and redo the removal.
> > > + */
> > > + if (!list_empty(&c->wait_node)) {
> >
> > Tbh, I don't like this super-smart optimization. I would prefer just taking
> > the lock. If we find this to hurt performance, we could change the
> > implementation to RCU.
>
> It just seems wrong to grab the lock every time any client exits. Would
> you be o.k. with having a special return value from the client handler
> functions to signal that the client needs to wait and a flag that
> clients can set when they get this return? Clients who haven't set the
> flag can skip the lock, just like with the current list empty code. Only
> the uxlsnr thread would set and check the flag, so there's no locking
> needed.
O.k. so that specific idea won't work. If the uxlsnr thread gets
cancelled between when the wait_node got added to the list and when the
cli_handler returned, the flag wouldn't be set and thus dead_client()
wouldn't remove the client from the wait list. That opens a small window
where another thread could be accessing the freed memory while calling
wakeup_event_waiter(). Instead, I could just set the flag directly when
the client's wait_node is added to the list in wait_for_event(). The
rest of the argument is the same.
-Ben
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-01 23:46 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 5:24 [PATCH 0/4] multipath: add the ability to wait on events Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 1/4] multipathd: make the wakeup and drain idle_fd code generic Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 2/4] multipathd: add infrastructure for uxlsnr waiting on events Benjamin Marzinski
2026-11-26 11:42 ` Martin Wilck
2026-11-30 16:55 ` Benjamin Marzinski
2026-12-01 23:46 ` Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 3/4] multipathd: make cli_handlers take a wait_node Benjamin Marzinski
2026-11-26 5:24 ` [PATCH 4/4] multipathd: add commands to wait for reconfigures to complete Benjamin Marzinski
2026-11-26 11:42 ` Martin Wilck
2026-11-30 19:05 ` Benjamin Marzinski
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.