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