]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Honor 'restart' action for 'on_poweroff'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 19 Aug 2021 12:44:51 +0000 (14:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Aug 2021 13:32:44 +0000 (15:32 +0200)
We simply terminate qemu instead of issuing a reset as the semantics of
the setting dictate.

Fix it by handling it identically to 'fake reboot'.

We need to forbid the combination of 'onReboot' -> 'destroy' and
'onPoweroff' -> reboot though as the handling would be hairy and it
honetly makes no sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatdomain.rst
src/qemu/qemu_process.c
src/qemu/qemu_validate.c

index a894a51c004151f804bbf8d7a99284606382cfca..1f3136b3f27e2e7424c3c9733a8e42ea1643a1c5 100644 (file)
@@ -1747,7 +1747,8 @@ Each of these states allow for the same four possible actions.
    supported by the libxl hypervisor driver.)
 
 QEMU/KVM supports the ``on_poweroff`` and ``on_reboot`` events handling the
-``destroy`` and ``restart`` actions.
+``destroy`` and ``restart`` actions, but the combiatnion of ``on_poweroff`` set
+to ``restart`` and ``on_reboot`` set to ``destroy`` is forbidden.
 
 The ``on_crash`` event supports these additional actions :since:`since 0.8.4` .
 
index df3bd66c0cda577f4dfb4a21e483872eeacf6c2a..a07231976fb1d42c28d0c7ac0c9cb29f8854e068 100644 (file)
@@ -543,7 +543,8 @@ qemuProcessShutdownOrReboot(virQEMUDriver *driver,
 {
     qemuDomainObjPrivate *priv = vm->privateData;
 
-    if (priv->fakeReboot) {
+    if (priv->fakeReboot ||
+        vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART) {
         g_autofree char *name = g_strdup_printf("reboot-%s", vm->def->name);
         virThread th;
 
@@ -619,7 +620,8 @@ qemuProcessHandleShutdown(qemuMonitor *mon G_GNUC_UNUSED,
 
     /* In case of fake reboot qemu shutdown state is transient so don't
      * change domain state nor send events. */
-    if (!priv->fakeReboot) {
+    if (!priv->fakeReboot ||
+        vm->def->onPoweroff != VIR_DOMAIN_LIFECYCLE_ACTION_RESTART) {
         VIR_DEBUG("Transitioned guest %s to shutdown state",
                   vm->def->name);
         virDomainObjSetState(vm,
index d27c3b6c6c9c6dd3e0406a0ff148867a9cad2d3c..8906aa52d9e14ebaf6f8802506371102a70618cb 100644 (file)
@@ -1089,6 +1089,15 @@ qemuValidateLifecycleAction(virDomainLifecycleAction onPoweroff,
         return -1;
     }
 
+    /* the qemu driver can't meaningfully handle
+     * onPoweroff -> reboot + onReboot -> destroy */
+    if (onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART &&
+        onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("qemu driver doesn't support 'onReboot' set to 'destroy and 'onPoweroff' set to 'reboot'"));
+        return -1;
+    }
+
     return 0;
 }