]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuProcessLaunch: Setup handling of 'on_reboot' via QMP when starting the process
authorPeter Krempa <pkrempa@redhat.com>
Mon, 23 Aug 2021 14:40:46 +0000 (16:40 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Aug 2021 13:32:45 +0000 (15:32 +0200)
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 <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_process.c

index 3e87ddc11e11133e4ce5502076c5b42486b6c898..0fcc847ab8df88062b00aa7bf394d6fb7ed64dd1 100644 (file)
@@ -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: