提交 36bac65d 编写于 作者: C Chen Fan 提交者: Eric Blake

qemu: Implement 'oncrash' coredump events when guest panicked

Add doDumpCoreToAutoPath to implement
'coredump-destroy' and 'coredump-restart' events of the 'on_crash'
in the XML when domain crashed.
上级 9aa527dc
......@@ -3633,6 +3633,59 @@ cleanup:
virObjectUnref(cfg);
}
static int
doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver,
virDomainObjPtr vm,
unsigned int flags)
{
int ret = -1;
char *dumpfile = NULL;
time_t curtime = time(NULL);
char timestr[100];
struct tm time_info;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
localtime_r(&curtime, &time_info);
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
if (virAsprintf(&dumpfile, "%s/%s-%s",
cfg->autoDumpPath,
vm->def->name,
timestr) < 0) {
virReportOOMError();
goto cleanup;
}
if (qemuDomainObjBeginAsyncJob(driver, vm,
QEMU_ASYNC_JOB_DUMP) < 0) {
goto cleanup;
}
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto endjob;
}
flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
ret = doCoreDump(driver, vm, dumpfile,
getCompressionType(driver), flags);
if (ret < 0)
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Dump failed"));
endjob:
/* Safe to ignore value since ref count was incremented in
* qemuProcessHandleGuestPanic().
*/
ignore_value(qemuDomainObjEndAsyncJob(driver, vm));
cleanup:
VIR_FREE(dumpfile);
virObjectUnref(cfg);
return ret;
}
static void
processGuestPanicEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
......@@ -3669,6 +3722,12 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
}
switch (action) {
case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) {
goto cleanup;
}
/* fall through */
case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY:
priv->beingDestroyed = true;
......@@ -3700,6 +3759,12 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
}
break;
case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART:
if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) {
goto cleanup;
}
/* fall through */
case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART:
qemuDomainSetFakeReboot(driver, vm, true);
qemuProcessShutdownOrReboot(driver, vm);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册