From d0fad4ab2ea95ad7e54e3bc6577e30ed09c391be Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 23 Aug 2021 16:40:46 +0200 Subject: [PATCH] qemuProcessLaunch: Setup handling of 'on_reboot' via QMP when starting the process Rather than using '-no-reboot' use the QMP command to update the lifecycle action of 'on_reboot'. This will be identical to how we set the behaviour during lifetime and also avoids problems with use of the 'system-reset' QMP command during bringup of the VM (used to update the firmware table of disks when disks were hotplugged as part of startup). Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3e87ddc11e..0fcc847ab8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7024,6 +7024,37 @@ qemuProcessSetupDisksTransient(virDomainObj *vm, } +static int +qemuProcessSetupLifecycleActions(virDomainObj *vm, + qemuDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv = vm->privateData; + int rc; + + if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_SET_ACTION))) + return 0; + + /* for now we handle only onReboot->destroy here as an alternative to + * '-no-reboot' on the commandline */ + if (vm->def->onReboot != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY) + return 0; + + if (qemuDomainObjEnterMonitorAsync(priv->driver, vm, asyncJob) < 0) + return -1; + + rc = qemuMonitorSetAction(priv->mon, + QEMU_MONITOR_ACTION_SHUTDOWN_KEEP, + QEMU_MONITOR_ACTION_REBOOT_SHUTDOWN, + QEMU_MONITOR_ACTION_WATCHDOG_KEEP, + QEMU_MONITOR_ACTION_PANIC_KEEP); + + if (qemuDomainObjExitMonitor(priv->driver, vm) < 0 || rc < 0) + return -1; + + return 0; +} + + /** * qemuProcessLaunch: * @@ -7382,6 +7413,10 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; } + VIR_DEBUG("Setting handling of lifecycle actions"); + if (qemuProcessSetupLifecycleActions(vm, asyncJob) < 0) + goto cleanup; + ret = 0; cleanup: