[PATCH V2 07/13] libxl: use job functions when cleaning up a domain

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

 



When explicitly destroying a domain (libxlDomainDestroyFlags), or
handling an out-of-band domain shutdown event, cleanup the domain
in the context of a job.  Introduce libxlVmCleanupJob to wrap
libxlVmCleanup in a job block.

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---

V2:
  Introduce libxlVmCleanupJob and call it when needing libxlVmCleanup
  in a job block.
  Check libxlDomainObjEndJob() return value

 src/libxl/libxl_driver.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 36fc9f5..0c2c1d7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -317,6 +317,26 @@ libxlVmCleanup(libxlDriverPrivatePtr driver,
 }
 
 /*
+ * Cleanup function for domain that has reached shutoff state.
+ * Executed in the context of a job.
+ *
+ * virDomainObjPtr should be locked on invocation
+ * Returns true if references remain on virDomainObjPtr, false otherwise.
+ */
+static bool
+libxlVmCleanupJob(libxlDriverPrivatePtr driver,
+                  virDomainObjPtr vm,
+                  virDomainShutoffReason reason)
+{
+    if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_DESTROY) < 0)
+        return true;
+
+    libxlVmCleanup(driver, vm, reason);
+
+    return libxlDomainObjEndJob(driver, vm);
+}
+
+/*
  * Handle previously registered event notification from libxenlight.
  *
  * Note: Xen 4.3 removed the const from the event handler signature.
@@ -364,10 +384,11 @@ libxlDomainShutdownThread(void *opaque)
                 reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
             }
             libxl_domain_destroy(ctx, vm->def->id, NULL);
-            libxlVmCleanup(driver, vm, reason);
-            if (!vm->persistent) {
-                virDomainObjListRemove(driver->domains, vm);
-                vm = NULL;
+            if (libxlVmCleanupJob(driver, vm, reason)) {
+                if (!vm->persistent) {
+                    virDomainObjListRemove(driver->domains, vm);
+                    vm = NULL;
+                }
             }
             break;
         case LIBXL_SHUTDOWN_REASON_REBOOT:
@@ -1561,10 +1582,11 @@ libxlDomainDestroyFlags(virDomainPtr dom,
         goto cleanup;
     }
 
-    libxlVmCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
-    if (!vm->persistent) {
-        virDomainObjListRemove(driver->domains, vm);
-        vm = NULL;
+    if (libxlVmCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED)) {
+        if (!vm->persistent) {
+            virDomainObjListRemove(driver->domains, vm);
+            vm = NULL;
+        }
     }
 
     ret = 0;
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]