提交 c778fe96 编写于 作者: J Jiri Denemark

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.
上级 aefaeb3d
......@@ -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 ?
......@@ -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
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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册