* [PATCH] multipathd: cleanup global queues after threads exit
@ 2026-11-12 15:33 Ganesh Andhale
2026-11-19 17:36 ` Benjamin Marzinski
0 siblings, 1 reply; 2+ messages in thread
From: Ganesh Andhale @ 2026-11-12 15:33 UTC (permalink / raw)
To: christophe.varoqui; +Cc: dm-devel, bmarzins, mwilck
cleanup_global_uevq() and cleanup_global_purge_queue() were registered
as pthread cleanup handlers in worker threads. During shutdown, these
handlers could run as soon as their owning thread was cancelled, while
another thread that also accessed the same global queue had not been
joined yet.
This allowed the global uevent or purge queue to be cleaned while a
producer or consumer thread could still touch it.
Move the global queue cleanup to cleanup_queues(), which is called
after cleanup_threads(), once all related threads have been joined.
Keep the pthread cleanup handlers only for thread-local temporary lists
and other resources owned by the cancelling thread.
Export cleanup_global_uevq() from libmultipath so multipathd can call
it during daemon shutdown.
Signed-off-by: Ganesh Andhale <gandhale@redhat.com>
---
libmultipath/libmultipath.version | 1 +
libmultipath/uevent.c | 4 +---
libmultipath/uevent.h | 2 ++
multipathd/main.c | 12 ++++++++++++
multipathd/purge.c | 4 +---
multipathd/purge.h | 2 ++
6 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version
index f631f453..93f213b6 100644
--- a/libmultipath/libmultipath.version
+++ b/libmultipath/libmultipath.version
@@ -203,6 +203,7 @@ global:
trigger_path_udev_change;
trigger_paths_udev_change;
udev;
+ cleanup_global_uevq;
uevent_dispatch;
uevent_get_dm_str;
uevent_get_env_positive_int;
diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
index b0c43340..e1c8aa72 100644
--- a/libmultipath/uevent.c
+++ b/libmultipath/uevent.c
@@ -503,7 +503,7 @@ static void cleanup_uevq(void *arg)
uevq_cleanup(arg);
}
-static void cleanup_global_uevq(void *arg __attribute__((unused)))
+void cleanup_global_uevq(void)
{
pthread_mutex_lock(uevq_lockp);
uevq_cleanup(&uevq);
@@ -726,7 +726,6 @@ int uevent_listen(struct udev *udev)
goto out;
}
- pthread_cleanup_push(cleanup_global_uevq, NULL);
pthread_cleanup_push(cleanup_uevq, &uevlisten_tmp);
while (1) {
int fdcount, events;
@@ -755,7 +754,6 @@ int uevent_listen(struct udev *udev)
pthread_mutex_unlock(uevq_lockp);
}
pthread_cleanup_pop(1);
- pthread_cleanup_pop(1);
out:
pthread_cleanup_pop(1);
out_udev:
diff --git a/libmultipath/uevent.h b/libmultipath/uevent.h
index 69296789..f21419ea 100644
--- a/libmultipath/uevent.h
+++ b/libmultipath/uevent.h
@@ -28,6 +28,8 @@ struct uevent {
struct uevent *alloc_uevent(void);
int is_uevent_busy(void);
+void cleanup_global_uevq(void);
+
int uevent_listen(struct udev *udev);
int uevent_dispatch(int (*store_uev)(struct uevent *, void * trigger_data),
void * trigger_data);
diff --git a/multipathd/main.c b/multipathd/main.c
index 9bce4d6b..11bd1d01 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3812,6 +3812,17 @@ static void cleanup_vecs(void)
gvecs = NULL;
}
+static void cleanup_queues(void)
+{
+ /*
+ * Shared queues must be cleaned only after every producer and
+ * consumer has been joined. Worker cleanup handlers must not
+ * free these globals while another thread may still access them.
+ */
+ cleanup_global_purge_queue();
+ cleanup_global_uevq();
+}
+
static void cleanup_threads(void)
{
stop_io_err_stat_thread();
@@ -3915,6 +3926,7 @@ static void cleanup_rcu(void)
static void cleanup_child(void)
{
cleanup_threads();
+ cleanup_queues();
cleanup_vecs();
cleanup_bindings();
if (poll_dmevents)
diff --git a/multipathd/purge.c b/multipathd/purge.c
index 68db8ced..078b4079 100644
--- a/multipathd/purge.c
+++ b/multipathd/purge.c
@@ -235,7 +235,7 @@ void cleanup_purge_list(void *arg)
* Cleanup handler for the global purge queue.
* Used during shutdown to free any remaining queued items.
*/
-static void cleanup_global_purge_queue(void *arg __attribute__((unused)))
+void cleanup_global_purge_queue(void)
{
pthread_mutex_lock(&purge_mutex);
cleanup_purge_list(&purge_queue);
@@ -268,7 +268,6 @@ void *purgeloop(void *ap __attribute__((unused)))
* Cleanup handler for global purge_queue.
* This handles items that were queued but not yet moved to purge_list.
*/
- pthread_cleanup_push(cleanup_global_purge_queue, NULL);
while (1) {
LIST_HEAD(purge_list);
@@ -320,7 +319,6 @@ void *purgeloop(void *ap __attribute__((unused)))
pthread_cleanup_pop(0);
}
- pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
return NULL;
}
diff --git a/multipathd/purge.h b/multipathd/purge.h
index 1fe755f3..81ed952b 100644
--- a/multipathd/purge.h
+++ b/multipathd/purge.h
@@ -33,6 +33,8 @@ void build_purge_list(struct vectors *vecs, struct list_head *tmpq);
*/
void cleanup_purge_list(void *arg);
+void cleanup_global_purge_queue(void);
+
/*
* Main purge thread loop
*/
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] multipathd: cleanup global queues after threads exit
2026-11-12 15:33 [PATCH] multipathd: cleanup global queues after threads exit Ganesh Andhale
@ 2026-11-19 17:36 ` Benjamin Marzinski
0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Marzinski @ 2026-11-19 17:36 UTC (permalink / raw)
To: Ganesh Andhale; +Cc: christophe.varoqui, dm-devel, mwilck
On Thu, Nov 12, 2026 at 09:03:10PM +0530, Ganesh Andhale wrote:
> cleanup_global_uevq() and cleanup_global_purge_queue() were registered
> as pthread cleanup handlers in worker threads. During shutdown, these
> handlers could run as soon as their owning thread was cancelled, while
> another thread that also accessed the same global queue had not been
> joined yet.
>
> This allowed the global uevent or purge queue to be cleaned while a
> producer or consumer thread could still touch it.
>
> Move the global queue cleanup to cleanup_queues(), which is called
> after cleanup_threads(), once all related threads have been joined.
> Keep the pthread cleanup handlers only for thread-local temporary lists
> and other resources owned by the cancelling thread.
>
> Export cleanup_global_uevq() from libmultipath so multipathd can call
> it during daemon shutdown.
>
> Signed-off-by: Ganesh Andhale <gandhale@redhat.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 17:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 15:33 [PATCH] multipathd: cleanup global queues after threads exit Ganesh Andhale
2026-11-19 17:36 ` 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.