Implements 'rename-restart' behavior of the 'on_crash'
in the XML when domain crashed.
---
src/qemu/qemu_driver.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index eefe7a2..a166468 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3566,6 +3566,55 @@ cleanup:
return ret;
}
+static int
+qemuProcessVmRenameAlive(virQEMUDriverPtr driver,
+ virDomainObjPtr vm, char *alias)
+{
+ int ret = -1;
+ char *oldname = NULL;
+ char *newDefname = NULL;
+ char ebuf[1024];
+ char *statefile = NULL;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+ if (strstr(vm->def->name, "-crashed")) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ oldname = vm->def->name;
+ vm->def->name = alias;
+
+ if (vm->newDef) {
+ if (VIR_STRDUP(newDefname, oldname) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ VIR_FREE(vm->newDef->name);
+ vm->newDef->name = newDefname;
+ }
+
+ if (virAsprintf(&statefile, "%s/%s.xml", cfg->stateDir, oldname)
< 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (unlink(statefile) < 0 && errno != ENOENT && errno != ENOTDIR)
+ VIR_WARN("Failed to remove domain XML for %s: %s",
+ oldname, virStrerror(errno, ebuf, sizeof(ebuf)));
+
+ if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
+ VIR_WARN("Failed to save status on vm %s", vm->def->name);
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(statefile);
+ VIR_FREE(oldname);
+ virObjectUnref(cfg);
+ return ret;
+}
+
static void
processGuestPanicEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3650,6 +3699,24 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
qemuProcessShutdownOrReboot(driver, vm);
break;
+ case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
+ {
+ char *alias = NULL;
+ if (virAsprintf(&alias, "%s-crashed",
+ vm->def->name) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ if (qemuProcessVmRenameAlive(driver, vm, alias) < 0) {
+ VIR_FREE(alias);
+ goto cleanup;
+ }
+
+ qemuDomainSetFakeReboot(driver, vm, true);
+ qemuProcessShutdownOrReboot(driver, vm);
+ }
+ break;
+
case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
break;
--
1.8.1.4