mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 14:05:18 +00:00
qemu: Distinguish between domain shutdown and crash
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.
This commit is contained in:
parent
aefaeb3d48
commit
c778fe9678
@ -129,6 +129,7 @@ struct _qemuDomainObjPrivate {
|
|||||||
virDomainChrDefPtr monConfig;
|
virDomainChrDefPtr monConfig;
|
||||||
int monJSON;
|
int monJSON;
|
||||||
int monitor_warned;
|
int monitor_warned;
|
||||||
|
bool gotShutdown;
|
||||||
|
|
||||||
int nvcpupids;
|
int nvcpupids;
|
||||||
int *vcpupids;
|
int *vcpupids;
|
||||||
@ -919,11 +920,19 @@ qemuHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|||||||
int hasError) {
|
int hasError) {
|
||||||
struct qemud_driver *driver = qemu_driver;
|
struct qemud_driver *driver = qemu_driver;
|
||||||
virDomainEventPtr event = NULL;
|
virDomainEventPtr event = NULL;
|
||||||
|
qemuDomainObjPrivatePtr priv;
|
||||||
|
|
||||||
VIR_DEBUG("Received EOF on %p '%s'", vm, vm->def->name);
|
VIR_DEBUG("Received EOF on %p '%s'", vm, vm->def->name);
|
||||||
|
|
||||||
virDomainObjLock(vm);
|
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,
|
event = virDomainEventNewFromObj(vm,
|
||||||
VIR_DOMAIN_EVENT_STOPPED,
|
VIR_DOMAIN_EVENT_STOPPED,
|
||||||
hasError ?
|
hasError ?
|
||||||
@ -1119,6 +1128,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
|
static int
|
||||||
qemuHandleDomainStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
qemuHandleDomainStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
@ -1382,6 +1403,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
|
|||||||
.destroy = qemuHandleMonitorDestroy,
|
.destroy = qemuHandleMonitorDestroy,
|
||||||
.eofNotify = qemuHandleMonitorEOF,
|
.eofNotify = qemuHandleMonitorEOF,
|
||||||
.diskSecretLookup = findVolumeQcowPassphrase,
|
.diskSecretLookup = findVolumeQcowPassphrase,
|
||||||
|
.domainShutdown = qemuHandleDomainShutdown,
|
||||||
.domainStop = qemuHandleDomainStop,
|
.domainStop = qemuHandleDomainStop,
|
||||||
.domainReset = qemuHandleDomainReset,
|
.domainReset = qemuHandleDomainReset,
|
||||||
.domainRTCChange = qemuHandleDomainRTCChange,
|
.domainRTCChange = qemuHandleDomainRTCChange,
|
||||||
@ -3997,6 +4019,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
priv->monJSON = 0;
|
priv->monJSON = 0;
|
||||||
|
|
||||||
priv->monitor_warned = 0;
|
priv->monitor_warned = 0;
|
||||||
|
priv->gotShutdown = false;
|
||||||
|
|
||||||
if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
|
if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
|
||||||
virReportSystemError(ret,
|
virReportSystemError(ret,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user