From fddede73c79403832312b1a2253b17ca4f5db3cd Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 4 Oct 2026 07:28:09 +0000 Subject: [PATCH] vmspawn: stop the QMP pump on fatal errors The next commit drains the QMP client before resuming the VM, while boot-time devices are being set up. Callbacks report fatal setup errors by logging them and requesting the event loop to exit. As the loop isn't running yet, the pump would not notice and continue. Stop it instead, and return the error. Signed-off-by: Martin Pitt (cherry picked from commit 50063acf50dc81b194780758d3cd2c5fb0a709f4) --- src/vmspawn/vmspawn-qmp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/vmspawn/vmspawn-qmp.c b/src/vmspawn/vmspawn-qmp.c index f9e5376127..3c951d6151 100644 --- a/src/vmspawn/vmspawn-qmp.c +++ b/src/vmspawn/vmspawn-qmp.c @@ -2014,7 +2014,21 @@ static int vmspawn_qmp_bridge_drain(VmspawnQmpBridge *bridge) { assert(bridge); - while (!qmp_client_is_idle(bridge->qmp)) { + sd_event *event = qmp_client_get_event(bridge->qmp); + + for (;;) { + int code; + /* Callbacks of fatal boot-time errors request the event loop to exit, but that isn't running + * yet; stop draining then. */ + if (sd_event_get_exit_code(event, &code) >= 0) { + if (code < 0) + return code; + return log_error_errno(SYNTHETIC_ERRNO(ECANCELED), "Exit requested during QMP device setup."); + } + + if (qmp_client_is_idle(bridge->qmp)) + return 0; + r = qmp_client_process(bridge->qmp); if (r < 0) return log_error_errno(r, "Failed to process QMP messages: %m"); @@ -2025,8 +2039,6 @@ static int vmspawn_qmp_bridge_drain(VmspawnQmpBridge *bridge) { if (r < 0) return log_error_errno(r, "Failed to wait for QMP messages: %m"); } - - return 0; } int vmspawn_qmp_probe_features(VmspawnQmpBridge *bridge) {