render / rpms / libvirt

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