edecca
From a2e308060512eb7d4ee00f7baddb7394d6e9e4e6 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <a2e308060512eb7d4ee00f7baddb7394d6e9e4e6@dist-git>
edecca
From: Jiri Denemark <jdenemar@redhat.com>
edecca
Date: Mon, 10 Sep 2018 19:41:53 +0200
edecca
Subject: [PATCH] qemu: Pass running reason to RESUME event handler
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
Whenever we get the RESUME event from QEMU, we change the state of the
edecca
affected domain to VIR_DOMAIN_RUNNING with VIR_DOMAIN_RUNNING_UNPAUSED
edecca
reason. This is fine if the domain is resumed unexpectedly, but when we
edecca
sent "cont" to QEMU we usually have a better reason for the state
edecca
change. The better reason is used in qemuProcessStartCPUs which also
edecca
sets the domain state to running if qemuMonitorStartCPUs reports
edecca
success. Thus we may end up with two state updates in a row, but the
edecca
final reason is correct.
edecca
edecca
This patch is a preparation for dropping the state change done in
edecca
qemuMonitorStartCPUs for which we need to pass the actual running reason
edecca
to the RESUME event handler and use it there instead of
edecca
VIR_DOMAIN_RUNNING_UNPAUSED.
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
Reviewed-by: John Ferlan <jferlan@redhat.com>
edecca
(cherry picked from commit 5dab984ed0cd0332e59d719420ab2f9d009b952f)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1634758
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1634759
edecca
edecca
Conflicts:
edecca
	src/qemu/qemu_domain.h
edecca
            - nodenames code is not backported
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 src/qemu/qemu_domain.h  |  4 ++++
edecca
 src/qemu/qemu_process.c | 23 +++++++++++++++++------
edecca
 2 files changed, 21 insertions(+), 6 deletions(-)
edecca
edecca
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
edecca
index e748d78adb..6a96f27a5f 100644
edecca
--- a/src/qemu/qemu_domain.h
edecca
+++ b/src/qemu/qemu_domain.h
edecca
@@ -363,6 +363,10 @@ struct _qemuDomainObjPrivate {
edecca
 
edecca
     /* true if qemu-pr-helper process is running for the domain */
edecca
     bool prDaemonRunning;
edecca
+
edecca
+    /* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
edecca
+     * RESUME event handler to use it */
edecca
+    virDomainRunningReason runningReason;
edecca
 };
edecca
 
edecca
 # define QEMU_DOMAIN_PRIVATE(vm) \
edecca
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
edecca
index 26979faa72..7325bc4c90 100644
edecca
--- a/src/qemu/qemu_process.c
edecca
+++ b/src/qemu/qemu_process.c
edecca
@@ -692,21 +692,28 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
edecca
     virQEMUDriverPtr driver = opaque;
edecca
     virObjectEventPtr event = NULL;
edecca
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
edecca
+    qemuDomainObjPrivatePtr priv;
edecca
+    virDomainRunningReason reason = VIR_DOMAIN_RUNNING_UNPAUSED;
edecca
 
edecca
     virObjectLock(vm);
edecca
-    if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
edecca
-        qemuDomainObjPrivatePtr priv = vm->privateData;
edecca
 
edecca
+    priv = vm->privateData;
edecca
+    if (priv->runningReason != VIR_DOMAIN_RUNNING_UNKNOWN) {
edecca
+        reason = priv->runningReason;
edecca
+        priv->runningReason = VIR_DOMAIN_RUNNING_UNKNOWN;
edecca
+    }
edecca
+
edecca
+    if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
edecca
         if (priv->gotShutdown) {
edecca
             VIR_DEBUG("Ignoring RESUME event after SHUTDOWN");
edecca
             goto unlock;
edecca
         }
edecca
 
edecca
-        VIR_DEBUG("Transitioned guest %s out of paused into resumed state",
edecca
-                  vm->def->name);
edecca
+        VIR_DEBUG("Transitioned guest %s out of paused into resumed state, "
edecca
+                  "reason '%s'",
edecca
+                  vm->def->name, virDomainRunningReasonTypeToString(reason));
edecca
 
edecca
-        virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
edecca
-                                 VIR_DOMAIN_RUNNING_UNPAUSED);
edecca
+        virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
edecca
         event = virDomainEventLifecycleNewFromObj(vm,
edecca
                                          VIR_DOMAIN_EVENT_RESUMED,
edecca
                                          VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
edecca
@@ -3051,6 +3058,8 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
edecca
     }
edecca
     VIR_FREE(priv->lockState);
edecca
 
edecca
+    priv->runningReason = reason;
edecca
+
edecca
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
edecca
         goto release;
edecca
 
edecca
@@ -3068,6 +3077,7 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm,
edecca
     return ret;
edecca
 
edecca
  release:
edecca
+    priv->runningReason = VIR_DOMAIN_RUNNING_UNKNOWN;
edecca
     if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
edecca
         VIR_WARN("Unable to release lease on %s", vm->def->name);
edecca
     VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState));
edecca
@@ -5928,6 +5938,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
edecca
     priv->monError = false;
edecca
     priv->monStart = 0;
edecca
     priv->gotShutdown = false;
edecca
+    priv->runningReason = VIR_DOMAIN_RUNNING_UNKNOWN;
edecca
 
edecca
     VIR_DEBUG("Updating guest CPU definition");
edecca
     if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, caps, flags) < 0)
edecca
-- 
edecca
2.19.1
edecca