render / rpms / libvirt

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