[libvirt] [PATCH 3/3] qemu: Clarify usage of DomainObjIsActive for SetTime

Cole Robinson crobinso at redhat.com
Fri Apr 15 14:00:14 UTC 2016


This converts SetTime to the common obj->agent->isactive pattern
(which adds a _third_ IsActive check), and documents the extra
checks
---
 src/qemu/qemu_driver.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f8dfa27..43f22f1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18725,9 +18725,9 @@ qemuDomainSetTime(virDomainPtr dom,
 
     priv = vm->privateData;
 
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
-        goto cleanup;
-
+    /* We also perform this check further down after grabbing the
+       job lock, but do it here too so we can throw an error for
+       an invalid config, before trying to talk to the guest agent */
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("domain is not running"));
@@ -18746,9 +18746,18 @@ qemuDomainSetTime(virDomainPtr dom,
         goto endjob;
     }
 
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+        goto cleanup;
+
     if (!qemuDomainAgentAvailable(vm, true))
         goto endjob;
 
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is not running"));
+        goto endjob;
+    }
+
     qemuDomainObjEnterAgent(vm);
     rv = qemuAgentSetTime(priv->agent, seconds, nseconds, rtcSync);
     qemuDomainObjExitAgent(vm);
@@ -18756,6 +18765,7 @@ qemuDomainSetTime(virDomainPtr dom,
     if (rv < 0)
         goto endjob;
 
+    /* The VM may have shut down inbetween, check state again */
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("domain is not running"));
-- 
2.7.3




More information about the libvir-list mailing list