[libvirt] [PATCH 3/3] qemu: implement state driver shutdown function

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Wed Sep 27 12:45:38 UTC 2017


Let's close agent and qemu monitors. This should trigger
any API calls awaiting response to finish eventually.
---
 src/qemu/qemu_driver.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4855c90..31d100c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1067,6 +1067,44 @@ qemuStateStop(void)
     return ret;
 }
 
+
+static int
+qemuDomainDisconnect(virDomainObjPtr vm, void *opaque ATTRIBUTE_UNUSED)
+{
+
+    qemuDomainObjPrivatePtr priv;
+
+    virObjectLock(vm);
+    priv = vm->privateData;
+
+    if (priv->mon) {
+        /* Take extra reference to monitor so it won't be disposed
+         * by qemuMonitorClose last unref. */
+        virObjectRef(priv->mon);
+        qemuMonitorClose(priv->mon);
+    }
+
+    if (priv->agent) {
+        /* Other threads are ready for priv->agent to became NULL meanwhile */
+        qemuAgentClose(priv->agent);
+        priv->agent = NULL;
+    }
+
+    virObjectUnlock(vm);
+    return 0;
+}
+
+
+static void
+qemuStateShutdown(void)
+{
+    if (!qemu_driver)
+        return;
+
+    virDomainObjListForEach(qemu_driver->domains, qemuDomainDisconnect, NULL);
+}
+
+
 /**
  * qemuStateCleanup:
  *
@@ -21147,6 +21185,7 @@ static virStateDriver qemuStateDriver = {
     .stateCleanup = qemuStateCleanup,
     .stateReload = qemuStateReload,
     .stateStop = qemuStateStop,
+    .stateShutdown = qemuStateShutdown,
 };
 
 int qemuRegister(void)
-- 
1.8.3.1




More information about the libvir-list mailing list