[PATCH] qemu: Distinguish between domain shutdown and crash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When we get an EOF event on monitor connection, it may be a result of
either crash or graceful shutdown. QEMU which supports async events
(i.e., we are talking to it using JSON monitor) emits SHUTDOWN event on
graceful shutdown. In case we don't get this event by the time monitor
connection is closed, we assume the associated domain crashed.
---
 src/qemu/qemu_driver.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4e65f3b..ab42a6d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -129,6 +129,7 @@ struct _qemuDomainObjPrivate {
     virDomainChrDefPtr monConfig;
     int monJSON;
     int monitor_warned;
+    bool gotShutdown;
 
     int nvcpupids;
     int *vcpupids;
@@ -919,11 +920,19 @@ qemuHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
                      int hasError) {
     struct qemud_driver *driver = qemu_driver;
     virDomainEventPtr event = NULL;
+    qemuDomainObjPrivatePtr priv;
 
     VIR_DEBUG("Received EOF on %p '%s'", vm, vm->def->name);
 
     virDomainObjLock(vm);
 
+    priv = vm->privateData;
+    if (!hasError && priv->monJSON && !priv->gotShutdown) {
+        VIR_DEBUG("Monitor connection to '%s' closed without SHUTDOWN event; "
+                  "assuming the domain crashed", vm->def->name);
+        hasError = 1;
+    }
+
     event = virDomainEventNewFromObj(vm,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      hasError ?
@@ -1120,6 +1129,18 @@ qemuHandleDomainReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 
 
 static int
+qemuHandleDomainShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
+                         virDomainObjPtr vm)
+{
+    virDomainObjLock(vm);
+    ((qemuDomainObjPrivatePtr) vm->privateData)->gotShutdown = true;
+    virDomainObjUnlock(vm);
+
+    return 0;
+}
+
+
+static int
 qemuHandleDomainStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
                      virDomainObjPtr vm)
 {
@@ -1382,6 +1403,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
     .destroy = qemuHandleMonitorDestroy,
     .eofNotify = qemuHandleMonitorEOF,
     .diskSecretLookup = findVolumeQcowPassphrase,
+    .domainShutdown = qemuHandleDomainShutdown,
     .domainStop = qemuHandleDomainStop,
     .domainReset = qemuHandleDomainReset,
     .domainRTCChange = qemuHandleDomainRTCChange,
@@ -3997,6 +4019,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
         priv->monJSON = 0;
 
     priv->monitor_warned = 0;
+    priv->gotShutdown = false;
 
     if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
         virReportSystemError(ret,
-- 
1.7.3.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]