]> xenbits.xensource.com Git - libvirt.git/commitdiff
Check for domain liveness in qemuDomainObjExitMonitor
authorJán Tomko <jtomko@redhat.com>
Fri, 12 Dec 2014 15:57:21 +0000 (16:57 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 14 Jan 2015 18:30:32 +0000 (19:30 +0100)
The domain might disappear during the time in monitor when
the virDomainObjPtr is unlocked, so the caller needs to check
if it's still alive.

Since most of the callers are going to need it, put the
check inside qemuDomainObjExitMonitor and return -1 if
the domain died in the meantime.

src/qemu/THREADS.txt
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index add2a35508ed6ae4f31af0fafdeb77066b693c44..dfa372b5bd167410757646910bc55e7e486b0bff 100644 (file)
@@ -160,6 +160,11 @@ To acquire the QEMU monitor lock
     - Acquires the virDomainObjPtr lock
 
   These functions must not be used by an asynchronous job.
+  Note that the virDomainObj is unlocked during the time in
+  monitor and it can be changed, e.g. if QEMU dies, qemuProcessStop
+  may free the live domain definition and put the persistent
+  definition back in vm->def. The callers should check the return
+  value of ExitMonitor to see if the domain is still alive.
 
 
 To acquire the QEMU monitor lock as part of an asynchronous job
index b75b4e08f14046d5f346543a1c0b4e7f23a7c0a3..0b4913bbf0a5ac1070d8d792d78db432e0c0f6c7 100644 (file)
@@ -1586,11 +1586,23 @@ void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
 /* obj must NOT be locked before calling
  *
  * Should be paired with an earlier qemuDomainObjEnterMonitor() call
+ *
+ * Returns -1 if the domain is no longer alive after exiting the monitor.
+ * In that case, the caller should be careful when using obj's data,
+ * e.g. the live definition in vm->def has been freed by qemuProcessStop
+ * and replaced by the persistent definition, so pointers stolen
+ * from the live definition could no longer be valid.
  */
-void qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
-                              virDomainObjPtr obj)
+int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
+                             virDomainObjPtr obj)
 {
     qemuDomainObjExitMonitorInternal(driver, obj);
+    if (!virDomainObjIsActive(obj)) {
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("domain is no longer running"));
+        return -1;
+    }
+    return 0;
 }
 
 /*
index 6b52f03522f8392a3104edaeccd6a08b5ad4e37a..fd91d837ff5009735c95467496801096fc6a4e43 100644 (file)
@@ -245,8 +245,8 @@ void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
 void qemuDomainObjEnterMonitor(virQEMUDriverPtr driver,
                                virDomainObjPtr obj)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-void qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
-                              virDomainObjPtr obj)
+int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
+                             virDomainObjPtr obj)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 int qemuDomainObjEnterMonitorAsync(virQEMUDriverPtr driver,
                                    virDomainObjPtr obj,