ed8822
From 919834294448ac9d1569a1f2620ea01d79a86e96 Mon Sep 17 00:00:00 2001
ed8822
Message-Id: <919834294448ac9d1569a1f2620ea01d79a86e96@dist-git>
ed8822
From: Jiri Denemark <jdenemar@redhat.com>
ed8822
Date: Tue, 11 Sep 2018 15:13:08 +0200
ed8822
Subject: [PATCH] qemu: Map running reason to resume event detail
ed8822
MIME-Version: 1.0
ed8822
Content-Type: text/plain; charset=UTF-8
ed8822
Content-Transfer-Encoding: 8bit
ed8822
ed8822
Thanks to the previous commit the RESUME event handler knows what reason
ed8822
should be used when changing the domain state to VIR_DOMAIN_RUNNING, but
ed8822
the emitted VIR_DOMAIN_EVENT_RESUMED event still uses a generic
ed8822
VIR_DOMAIN_EVENT_RESUMED_UNPAUSED detail. Luckily, the event detail can
ed8822
be easily deduced from the running reason, which saves us from having to
ed8822
pass one more value to the handler.
ed8822
ed8822
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
ed8822
Reviewed-by: John Ferlan <jferlan@redhat.com>
ed8822
(cherry picked from commit 8ae9b49f5a4a02f57a1dfa20d4fe04c3d40a4665)
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.c
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.c  | 29 +++++++++++++++++++++++++++++
ed8822
 src/qemu/qemu_domain.h  |  3 +++
ed8822
 src/qemu/qemu_process.c | 11 +++++++----
ed8822
 3 files changed, 39 insertions(+), 4 deletions(-)
ed8822
ed8822
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
ed8822
index 17be6e5537..d80f9b393e 100644
ed8822
--- a/src/qemu/qemu_domain.c
ed8822
+++ b/src/qemu/qemu_domain.c
ed8822
@@ -13149,3 +13149,32 @@ qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv)
ed8822
 
ed8822
     return ret;
ed8822
 }
ed8822
+
ed8822
+
ed8822
+virDomainEventResumedDetailType
ed8822
+qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason)
ed8822
+{
ed8822
+    switch (reason) {
ed8822
+    case VIR_DOMAIN_RUNNING_RESTORED:
ed8822
+    case VIR_DOMAIN_RUNNING_FROM_SNAPSHOT:
ed8822
+        return VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT;
ed8822
+
ed8822
+    case VIR_DOMAIN_RUNNING_MIGRATED:
ed8822
+    case VIR_DOMAIN_RUNNING_MIGRATION_CANCELED:
ed8822
+        return VIR_DOMAIN_EVENT_RESUMED_MIGRATED;
ed8822
+
ed8822
+    case VIR_DOMAIN_RUNNING_POSTCOPY:
ed8822
+        return VIR_DOMAIN_EVENT_RESUMED_POSTCOPY;
ed8822
+
ed8822
+    case VIR_DOMAIN_RUNNING_UNKNOWN:
ed8822
+    case VIR_DOMAIN_RUNNING_SAVE_CANCELED:
ed8822
+    case VIR_DOMAIN_RUNNING_BOOTED:
ed8822
+    case VIR_DOMAIN_RUNNING_UNPAUSED:
ed8822
+    case VIR_DOMAIN_RUNNING_WAKEUP:
ed8822
+    case VIR_DOMAIN_RUNNING_CRASHED:
ed8822
+    case VIR_DOMAIN_RUNNING_LAST:
ed8822
+        break;
ed8822
+    }
ed8822
+
ed8822
+    return VIR_DOMAIN_EVENT_RESUMED_UNPAUSED;
ed8822
+}
ed8822
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
ed8822
index 6a96f27a5f..cc406e3ca0 100644
ed8822
--- a/src/qemu/qemu_domain.h
ed8822
+++ b/src/qemu/qemu_domain.h
ed8822
@@ -1066,4 +1066,7 @@ qemuDomainDiskCachemodeFlags(int cachemode,
ed8822
 
ed8822
 char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);
ed8822
 
ed8822
+virDomainEventResumedDetailType
ed8822
+qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason);
ed8822
+
ed8822
 #endif /* __QEMU_DOMAIN_H__ */
ed8822
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
ed8822
index 7325bc4c90..37568165b7 100644
ed8822
--- a/src/qemu/qemu_process.c
ed8822
+++ b/src/qemu/qemu_process.c
ed8822
@@ -694,6 +694,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
ed8822
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
ed8822
     qemuDomainObjPrivatePtr priv;
ed8822
     virDomainRunningReason reason = VIR_DOMAIN_RUNNING_UNPAUSED;
ed8822
+    virDomainEventResumedDetailType eventDetail;
ed8822
 
ed8822
     virObjectLock(vm);
ed8822
 
ed8822
@@ -709,14 +710,16 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
ed8822
             goto unlock;
ed8822
         }
ed8822
 
ed8822
+        eventDetail = qemuDomainRunningReasonToResumeEvent(reason);
ed8822
         VIR_DEBUG("Transitioned guest %s out of paused into resumed state, "
ed8822
-                  "reason '%s'",
ed8822
-                  vm->def->name, virDomainRunningReasonTypeToString(reason));
ed8822
+                  "reason '%s', event detail %d",
ed8822
+                  vm->def->name, virDomainRunningReasonTypeToString(reason),
ed8822
+                  eventDetail);
ed8822
 
ed8822
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
ed8822
         event = virDomainEventLifecycleNewFromObj(vm,
ed8822
-                                         VIR_DOMAIN_EVENT_RESUMED,
ed8822
-                                         VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
ed8822
+                                                  VIR_DOMAIN_EVENT_RESUMED,
ed8822
+                                                  eventDetail);
ed8822
 
ed8822
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) {
ed8822
             VIR_WARN("Unable to save status on vm %s after state change",
ed8822
-- 
ed8822
2.19.1
ed8822