|
|
3e5111 |
From f0747aa9c94a5a79c9766959fcd479e04a56da3e Mon Sep 17 00:00:00 2001
|
|
|
3e5111 |
Message-Id: <f0747aa9c94a5a79c9766959fcd479e04a56da3e@dist-git>
|
|
|
3e5111 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
3e5111 |
Date: Wed, 31 May 2017 08:21:33 +0200
|
|
|
3e5111 |
Subject: [PATCH] qemu: Report shutdown event details
|
|
|
3e5111 |
|
|
|
3e5111 |
QEMU will likely report the details of it shutting down, particularly
|
|
|
3e5111 |
whether the shutdown was initiated by the guest or host. We should
|
|
|
3e5111 |
forward that information along, at least for shutdown events. Reset
|
|
|
3e5111 |
has that as well, however that is not a lifecycle event and would add
|
|
|
3e5111 |
extra constants that might not be used. It can be added later on.
|
|
|
3e5111 |
|
|
|
3e5111 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1384007
|
|
|
3e5111 |
|
|
|
3e5111 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
3e5111 |
(cherry picked from commit a8eba5036cb4b0e2ec827e9e6e019ce70e451377)
|
|
|
3e5111 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
3e5111 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
3e5111 |
---
|
|
|
3e5111 |
examples/object-events/event-test.c | 6 ++++++
|
|
|
3e5111 |
include/libvirt/libvirt-domain.h | 11 ++++++++++-
|
|
|
3e5111 |
src/qemu/qemu_monitor.c | 6 +++---
|
|
|
3e5111 |
src/qemu/qemu_monitor.h | 3 ++-
|
|
|
3e5111 |
src/qemu/qemu_monitor_json.c | 10 ++++++++--
|
|
|
3e5111 |
src/qemu/qemu_process.c | 21 +++++++++++++++++++--
|
|
|
3e5111 |
tools/virsh-domain.c | 4 +++-
|
|
|
3e5111 |
7 files changed, 51 insertions(+), 10 deletions(-)
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
|
|
|
3e5111 |
index 12690cac0..78d200806 100644
|
|
|
3e5111 |
--- a/examples/object-events/event-test.c
|
|
|
3e5111 |
+++ b/examples/object-events/event-test.c
|
|
|
3e5111 |
@@ -240,6 +240,12 @@ eventDetailToString(int event,
|
|
|
3e5111 |
case VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED:
|
|
|
3e5111 |
return "Finished";
|
|
|
3e5111 |
|
|
|
3e5111 |
+ case VIR_DOMAIN_EVENT_SHUTDOWN_GUEST:
|
|
|
3e5111 |
+ return "Guest request";
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ case VIR_DOMAIN_EVENT_SHUTDOWN_HOST:
|
|
|
3e5111 |
+ return "Host request";
|
|
|
3e5111 |
+
|
|
|
3e5111 |
case VIR_DOMAIN_EVENT_SHUTDOWN_LAST:
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
|
|
|
3e5111 |
index c9e96a6c9..720db32f7 100644
|
|
|
3e5111 |
--- a/include/libvirt/libvirt-domain.h
|
|
|
3e5111 |
+++ b/include/libvirt/libvirt-domain.h
|
|
|
3e5111 |
@@ -2983,7 +2983,16 @@ typedef enum {
|
|
|
3e5111 |
* Details on the cause of a 'shutdown' lifecycle event
|
|
|
3e5111 |
*/
|
|
|
3e5111 |
typedef enum {
|
|
|
3e5111 |
- VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED = 0, /* Guest finished shutdown sequence */
|
|
|
3e5111 |
+ /* Guest finished shutdown sequence */
|
|
|
3e5111 |
+ VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED = 0,
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ /* Domain finished shutting down after request from the guest itself
|
|
|
3e5111 |
+ * (e.g. hardware-specific action) */
|
|
|
3e5111 |
+ VIR_DOMAIN_EVENT_SHUTDOWN_GUEST = 1,
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ /* Domain finished shutting down after request from the host (e.g. killed by
|
|
|
3e5111 |
+ * a signal) */
|
|
|
3e5111 |
+ VIR_DOMAIN_EVENT_SHUTDOWN_HOST = 2,
|
|
|
3e5111 |
|
|
|
3e5111 |
# ifdef VIR_ENUM_SENTINELS
|
|
|
3e5111 |
VIR_DOMAIN_EVENT_SHUTDOWN_LAST
|
|
|
3e5111 |
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
|
|
|
3e5111 |
index 488d761fb..b5e890607 100644
|
|
|
3e5111 |
--- a/src/qemu/qemu_monitor.c
|
|
|
3e5111 |
+++ b/src/qemu/qemu_monitor.c
|
|
|
3e5111 |
@@ -1303,12 +1303,12 @@ qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event,
|
|
|
3e5111 |
|
|
|
3e5111 |
|
|
|
3e5111 |
int
|
|
|
3e5111 |
-qemuMonitorEmitShutdown(qemuMonitorPtr mon)
|
|
|
3e5111 |
+qemuMonitorEmitShutdown(qemuMonitorPtr mon, virTristateBool guest)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
int ret = -1;
|
|
|
3e5111 |
- VIR_DEBUG("mon=%p", mon);
|
|
|
3e5111 |
+ VIR_DEBUG("mon=%p guest=%u", mon, guest);
|
|
|
3e5111 |
|
|
|
3e5111 |
- QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm);
|
|
|
3e5111 |
+ QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm, guest);
|
|
|
3e5111 |
return ret;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
|
|
|
3e5111 |
index c1506b0fc..9901203b1 100644
|
|
|
3e5111 |
--- a/src/qemu/qemu_monitor.h
|
|
|
3e5111 |
+++ b/src/qemu/qemu_monitor.h
|
|
|
3e5111 |
@@ -130,6 +130,7 @@ typedef int (*qemuMonitorDomainEventCallback)(qemuMonitorPtr mon,
|
|
|
3e5111 |
void *opaque);
|
|
|
3e5111 |
typedef int (*qemuMonitorDomainShutdownCallback)(qemuMonitorPtr mon,
|
|
|
3e5111 |
virDomainObjPtr vm,
|
|
|
3e5111 |
+ virTristateBool guest,
|
|
|
3e5111 |
void *opaque);
|
|
|
3e5111 |
typedef int (*qemuMonitorDomainResetCallback)(qemuMonitorPtr mon,
|
|
|
3e5111 |
virDomainObjPtr vm,
|
|
|
3e5111 |
@@ -342,7 +343,7 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
|
|
|
3e5111 |
int qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event,
|
|
|
3e5111 |
long long seconds, unsigned int micros,
|
|
|
3e5111 |
const char *details);
|
|
|
3e5111 |
-int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
|
|
|
3e5111 |
+int qemuMonitorEmitShutdown(qemuMonitorPtr mon, virTristateBool guest);
|
|
|
3e5111 |
int qemuMonitorEmitReset(qemuMonitorPtr mon);
|
|
|
3e5111 |
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
|
|
|
3e5111 |
int qemuMonitorEmitStop(qemuMonitorPtr mon);
|
|
|
3e5111 |
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
|
|
|
3e5111 |
index 601aa3e74..f22df3007 100644
|
|
|
3e5111 |
--- a/src/qemu/qemu_monitor_json.c
|
|
|
3e5111 |
+++ b/src/qemu/qemu_monitor_json.c
|
|
|
3e5111 |
@@ -523,9 +523,15 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
|
|
|
3e5111 |
-static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
3e5111 |
+static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
- qemuMonitorEmitShutdown(mon);
|
|
|
3e5111 |
+ bool guest = false;
|
|
|
3e5111 |
+ virTristateBool guest_initiated = VIR_TRISTATE_BOOL_ABSENT;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (virJSONValueObjectGetBoolean(data, "guest", &guest) == 0)
|
|
|
3e5111 |
+ guest_initiated = guest ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ qemuMonitorEmitShutdown(mon, guest_initiated);
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
3e5111 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
3e5111 |
index 6f0d07242..998dbeb6b 100644
|
|
|
3e5111 |
--- a/src/qemu/qemu_process.c
|
|
|
3e5111 |
+++ b/src/qemu/qemu_process.c
|
|
|
3e5111 |
@@ -634,12 +634,14 @@ qemuProcessHandleEvent(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|
|
3e5111 |
static int
|
|
|
3e5111 |
qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|
|
3e5111 |
virDomainObjPtr vm,
|
|
|
3e5111 |
+ virTristateBool guest_initiated,
|
|
|
3e5111 |
void *opaque)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
virQEMUDriverPtr driver = opaque;
|
|
|
3e5111 |
qemuDomainObjPrivatePtr priv;
|
|
|
3e5111 |
virObjectEventPtr event = NULL;
|
|
|
3e5111 |
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
|
|
3e5111 |
+ int detail = 0;
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_DEBUG("vm=%p", vm);
|
|
|
3e5111 |
|
|
|
3e5111 |
@@ -662,9 +664,24 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|
|
3e5111 |
virDomainObjSetState(vm,
|
|
|
3e5111 |
VIR_DOMAIN_SHUTDOWN,
|
|
|
3e5111 |
VIR_DOMAIN_SHUTDOWN_UNKNOWN);
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ switch (guest_initiated) {
|
|
|
3e5111 |
+ case VIR_TRISTATE_BOOL_YES:
|
|
|
3e5111 |
+ detail = VIR_DOMAIN_EVENT_SHUTDOWN_GUEST;
|
|
|
3e5111 |
+ break;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ case VIR_TRISTATE_BOOL_NO:
|
|
|
3e5111 |
+ detail = VIR_DOMAIN_EVENT_SHUTDOWN_HOST;
|
|
|
3e5111 |
+ break;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ default:
|
|
|
3e5111 |
+ detail = VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED;
|
|
|
3e5111 |
+ break;
|
|
|
3e5111 |
+ }
|
|
|
3e5111 |
+
|
|
|
3e5111 |
event = virDomainEventLifecycleNewFromObj(vm,
|
|
|
3e5111 |
- VIR_DOMAIN_EVENT_SHUTDOWN,
|
|
|
3e5111 |
- VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED);
|
|
|
3e5111 |
+ VIR_DOMAIN_EVENT_SHUTDOWN,
|
|
|
3e5111 |
+ detail);
|
|
|
3e5111 |
|
|
|
3e5111 |
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) {
|
|
|
3e5111 |
VIR_WARN("Unable to save status on vm %s after state change",
|
|
|
3e5111 |
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
|
|
|
3e5111 |
index bc0ded686..3374f2c8b 100644
|
|
|
3e5111 |
--- a/tools/virsh-domain.c
|
|
|
3e5111 |
+++ b/tools/virsh-domain.c
|
|
|
3e5111 |
@@ -12385,7 +12385,9 @@ VIR_ENUM_IMPL(virshDomainEventStopped,
|
|
|
3e5111 |
VIR_ENUM_DECL(virshDomainEventShutdown)
|
|
|
3e5111 |
VIR_ENUM_IMPL(virshDomainEventShutdown,
|
|
|
3e5111 |
VIR_DOMAIN_EVENT_SHUTDOWN_LAST,
|
|
|
3e5111 |
- N_("Finished"))
|
|
|
3e5111 |
+ N_("Finished"),
|
|
|
3e5111 |
+ N_("Finished after guest request"),
|
|
|
3e5111 |
+ N_("Finished after host request"))
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_ENUM_DECL(virshDomainEventPMSuspended)
|
|
|
3e5111 |
VIR_ENUM_IMPL(virshDomainEventPMSuspended,
|
|
|
3e5111 |
--
|
|
|
3e5111 |
2.13.0
|
|
|
3e5111 |
|