[libvirt] [PATCH] qemu_agent: fix deadlock in qemuProcessHandleAgentEOF

Wang Yufei james.wangyufei at huawei.com
Sat Sep 26 12:18:03 UTC 2015

We shutdown a VM A by qemu agent,meanwhile an agent EOF
of VM A happened, there's a chance that deadlock occurred:

qemuProcessHandleAgentEOF in main thread
A)  priv->agent = NULL; //A happened before B

    //deadlock when we get agent lock which's held by worker thread

qemuDomainObjExitAgent called by qemuDomainShutdownFlags in worker thread
B)  hasRefs = virObjectUnref(priv->agent); //priv->agent is NULL, return false

    if (hasRefs)
        virObjectUnlock(priv->agent); //agent lock will not be released here

So I close agent first, then set priv->agent NULL to fix the deadlock.

Signed-off-by: Wang Yufei <james.wangyufei at huawei.com>
Reviewed-by: Ren Guannan <renguannan at huawei.com>
 src/qemu/qemu_process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f2586a1..8c9622e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -150,11 +150,10 @@ qemuProcessHandleAgentEOF(qemuAgentPtr agent,
         goto unlock;
+    qemuAgentClose(agent);
     priv->agent = NULL;
-    qemuAgentClose(agent);

More information about the libvir-list mailing list