Skip to content

Commit

Permalink
monitor: cleanup detection of qmp_dispatcher_co shutting down
Browse files Browse the repository at this point in the history
Instead of overloading qmp_dispatcher_co_busy, make the coroutine
pointer NULL.  This will make things break spectacularly if somebody
tries to start a request after monitor_cleanup().

AIO_WAIT_WHILE_UNLOCKED() does not need qatomic_mb_read(), because
the macro contains all the necessary memory barriers.

Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed May 25, 2023
1 parent 6ee7c82 commit 3e6bed6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void monitor_cleanup(void)

AIO_WAIT_WHILE_UNLOCKED(NULL,
(aio_poll(iohandler_get_aio_context(), false),
qatomic_mb_read(&qmp_dispatcher_co_busy)));
qatomic_read(&qmp_dispatcher_co)));

/*
* We need to explicitly stop the I/O thread (but not destroy it),
Expand Down
2 changes: 2 additions & 0 deletions monitor/qmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)

/* On shutdown, don't take any more requests from the queue */
if (qmp_dispatcher_co_shutdown) {
qatomic_set(&qmp_dispatcher_co, NULL);
return;
}

Expand All @@ -250,6 +251,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
* yielded and were reentered from monitor_cleanup()
*/
if (qmp_dispatcher_co_shutdown) {
qatomic_set(&qmp_dispatcher_co, NULL);
return;
}
}
Expand Down

0 comments on commit 3e6bed6

Please sign in to comment.