[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/5] qemu: Make autodestroy utilize connection close callbacks



---
 src/qemu/qemu_conf.h    |    5 --
 src/qemu/qemu_driver.c  |    5 --
 src/qemu/qemu_process.c |  107 ++++++++++------------------------------------
 3 files changed, 24 insertions(+), 93 deletions(-)

diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a22ce0c..3306014 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -141,11 +141,6 @@ struct qemud_driver {
 
     virLockManagerPluginPtr lockManager;
 
-    /* Mapping of 'char *uuidstr' -> virConnectPtr
-     * of guests which will be automatically killed
-     * when the virConnectPtr is closed*/
-    virHashTablePtr autodestroy;
-
     /* Mapping of 'char *uuidstr' -> qemuDriverCloseDefPtr of domains
      * which want a specific cleanup to be done when a connection is
      * closed. Such cleanup may be to automatically destroy  the
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ce82535..3a5ef09 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -659,9 +659,6 @@ qemudStartup(int privileged) {
         qemu_driver->hugepage_path = mempath;
     }
 
-    if (qemuProcessAutoDestroyInit(qemu_driver) < 0)
-        goto error;
-
     if (qemuDriverCloseCallbackInit(qemu_driver) < 0)
         goto error;
 
@@ -803,7 +800,6 @@ qemudShutdown(void) {
 
     virSysinfoDefFree(qemu_driver->hostsysinfo);
 
-    qemuProcessAutoDestroyShutdown(qemu_driver);
     qemuDriverCloseCallbackShutdown(qemu_driver);
 
     VIR_FREE(qemu_driver->configDir);
@@ -925,7 +921,6 @@ static int qemudClose(virConnectPtr conn) {
     qemuDriverLock(driver);
     virDomainEventStateDeregisterConn(conn,
                                       driver->domainEventState);
-    qemuProcessAutoDestroyRun(driver, conn);
     qemuDriverCloseCallbackRunAll(driver, conn);
     qemuDriverUnlock(driver);
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 1945864..8915a9a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4120,124 +4120,65 @@ cleanup:
 }
 
 
-int qemuProcessAutoDestroyInit(struct qemud_driver *driver)
+static virDomainObjPtr
+qemuProcessAutoDestroy(struct qemud_driver *driver,
+                       virDomainObjPtr dom,
+                       virConnectPtr conn)
 {
-    if (!(driver->autodestroy = virHashCreate(5, NULL)))
-        return -1;
-
-    return 0;
-}
-
-struct qemuProcessAutoDestroyData {
-    struct qemud_driver *driver;
-    virConnectPtr conn;
-};
-
-static void qemuProcessAutoDestroyDom(void *payload,
-                                      const void *name,
-                                      void *opaque)
-{
-    struct qemuProcessAutoDestroyData *data = opaque;
-    virConnectPtr conn = payload;
-    const char *uuidstr = name;
-    unsigned char uuid[VIR_UUID_BUFLEN];
-    virDomainObjPtr dom;
-    qemuDomainObjPrivatePtr priv;
+    qemuDomainObjPrivatePtr priv = dom->privateData;
     virDomainEventPtr event = NULL;
 
-    VIR_DEBUG("conn=%p uuidstr=%s thisconn=%p", conn, uuidstr, data->conn);
+    VIR_DEBUG("vm=%s, conn=%p", dom->def->name, conn);
 
-    if (data->conn != conn)
-        return;
-
-    if (virUUIDParse(uuidstr, uuid) < 0) {
-        VIR_WARN("Failed to parse %s", uuidstr);
-        return;
-    }
-
-    if (!(dom = virDomainFindByUUID(&data->driver->domains,
-                                    uuid))) {
-        VIR_DEBUG("No domain object to kill");
-        return;
-    }
-
-    priv = dom->privateData;
     if (priv->job.asyncJob) {
         VIR_DEBUG("vm=%s has long-term job active, cancelling",
                   dom->def->name);
-        qemuDomainObjDiscardAsyncJob(data->driver, dom);
+        qemuDomainObjDiscardAsyncJob(driver, dom);
     }
 
-    if (qemuDomainObjBeginJobWithDriver(data->driver, dom,
+    if (qemuDomainObjBeginJobWithDriver(driver, dom,
                                         QEMU_JOB_DESTROY) < 0)
         goto cleanup;
 
     VIR_DEBUG("Killing domain");
-    qemuProcessStop(data->driver, dom, 1, VIR_DOMAIN_SHUTOFF_DESTROYED);
+    qemuProcessStop(driver, dom, 1, VIR_DOMAIN_SHUTOFF_DESTROYED);
     virDomainAuditStop(dom, "destroyed");
     event = virDomainEventNewFromObj(dom,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
-    if (qemuDomainObjEndJob(data->driver, dom) == 0)
+
+    if (qemuDomainObjEndJob(driver, dom) == 0)
         dom = NULL;
     if (dom && !dom->persistent)
-        qemuDomainRemoveInactive(data->driver, dom);
-
-cleanup:
-    if (dom)
-        virDomainObjUnlock(dom);
+        qemuDomainRemoveInactive(driver, dom);
     if (event)
-        qemuDomainEventQueue(data->driver, event);
-    virHashRemoveEntry(data->driver->autodestroy, uuidstr);
-}
-
-/*
- * Precondition: driver is locked
- */
-void qemuProcessAutoDestroyRun(struct qemud_driver *driver, virConnectPtr conn)
-{
-    struct qemuProcessAutoDestroyData data = {
-        driver, conn
-    };
-    VIR_DEBUG("conn=%p", conn);
-    virHashForEach(driver->autodestroy, qemuProcessAutoDestroyDom, &data);
-}
+        qemuDomainEventQueue(driver, event);
 
-void qemuProcessAutoDestroyShutdown(struct qemud_driver *driver)
-{
-    virHashFree(driver->autodestroy);
+cleanup:
+    return dom;
 }
 
 int qemuProcessAutoDestroyAdd(struct qemud_driver *driver,
                               virDomainObjPtr vm,
                               virConnectPtr conn)
 {
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
-    virUUIDFormat(vm->def->uuid, uuidstr);
-    VIR_DEBUG("vm=%s uuid=%s conn=%p", vm->def->name, uuidstr, conn);
-    if (virHashAddEntry(driver->autodestroy, uuidstr, conn) < 0)
-        return -1;
-    return 0;
+    VIR_DEBUG("vm=%s, conn=%p", vm->def->name, conn);
+    return qemuDriverCloseCallbackSet(driver, vm, conn,
+                                      qemuProcessAutoDestroy);
 }
 
 int qemuProcessAutoDestroyRemove(struct qemud_driver *driver,
                                  virDomainObjPtr vm)
 {
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
-    virUUIDFormat(vm->def->uuid, uuidstr);
-    VIR_DEBUG("vm=%s uuid=%s", vm->def->name, uuidstr);
-    if (virHashRemoveEntry(driver->autodestroy, uuidstr) < 0)
-        return -1;
-    return 0;
+    VIR_DEBUG("vm=%s", vm->def->name);
+    return qemuDriverCloseCallbackUnset(driver, vm, qemuProcessAutoDestroy);
 }
 
 bool qemuProcessAutoDestroyActive(struct qemud_driver *driver,
                                   virDomainObjPtr vm)
 {
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
-    virUUIDFormat(vm->def->uuid, uuidstr);
-    VIR_DEBUG("vm=%s uuid=%s", vm->def->name, uuidstr);
-    if (virHashLookup(driver->autodestroy, uuidstr) != NULL)
-        return true;
-    return false;
+    qemuDriverCloseCallback cb;
+    VIR_DEBUG("vm=%s", vm->def->name);
+    cb = qemuDriverCloseCallbackGet(driver, vm, NULL);
+    return cb == qemuProcessAutoDestroy;
 }
-- 
1.7.8.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]