Skip to contentSkip to conversation

qemu: send stop event after bdrv_flush_all

PATCH Superseded tianren 1 participant 1 message Dec 4, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

tianren

author
#0 lore raw

PATCH 1/1 qemu: send stop event after bdrv_flush_all

From: Tianren Zhang <[email protected]>

The stop process is not finished until bdrv_flush_all is done. Some users (e.g., libvirt) detects the STOP event and invokes some lock release logic to revoke the disk lock held by current qemu when such event is emitted. In such case, if the bdrv_flush_all is after the stop event, it's possible that the disk lock is released while the qemu is still waiting for I/O. Therefore, it's better to have the stop event generated after the whole stop process is done.

Change-Id Ia2f95cd55edfdeb71ee2e04005ac216cfabffa22
---
 system/cpus.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
system/cpus.c +4 -3
index a444a747f0..b0421f3e22 100644
@@ -268,15 +268,16 @@ static int do_vm_stop(RunState state, bool send_stop)
         cpu_disable_ticks();
         pause_all_vcpus();
         vm_state_notify(0, state);
-        if (send_stop) {
-            qapi_event_send_stop();
-        }
     }
 
     bdrv_drain_all();
     ret = bdrv_flush_all();
     trace_vm_stop_flush_all(ret);
 
+    if (runstate_is_running() && send_stop) {
+        qapi_event_send_stop();
+    }
+
     return ret;
 }
 
Signature · 1 line
2.38.1