]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuProcessReconnect: Continue reconnection if VM untergoes fake-reboot
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Nov 2025 09:19:29 +0000 (10:19 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 Nov 2025 15:40:24 +0000 (16:40 +0100)
'qemuProcessShutdownOrReboot' may or may not kill the VM. In
'qemuProcessReconnect' if we decided that the VM was in a state
requiring 'qemuProcessShutdownOrReboot' to be called we'd stop the
reconnection unconditionally.

Now if the VM ought to undergo a fake reboot we really need to reconnect
to the process because the process will be kept around for much longer.

Make qemuProcessShutdownOrReboot return whether it killed the VM and
continue the reconnection if it didn't.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index 1e0289b35db68f61c8d6aac12fdf66d3aa8ac797..f2e024dae374b129408756c6f3f976662d5ef81b 100644 (file)
@@ -3557,7 +3557,7 @@ processGuestPanicEvent(virQEMUDriver *driver,
 
     case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART:
         qemuDomainSetFakeReboot(vm, true);
-        qemuProcessShutdownOrReboot(vm);
+        ignore_value(qemuProcessShutdownOrReboot(vm));
         break;
 
     case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE:
index 4ac81c9f937cf036b64d27c0937ed38642f2edfd..e256e1933802b180d770d8f8fc8885af18a492ad 100644 (file)
@@ -597,7 +597,16 @@ qemuProcessFakeReboot(void *opaque)
 }
 
 
-void
+/**
+ * qemuProcessShutdownOrReboot:
+ * @vm: domain object
+ *
+ * Perform the appropriate action when the guest OS shuts down. This can be
+ * either fake reboot (the VM is reset started again) or the VM is terminated.
+ *
+ * The function returns true if the VM was terminated.
+ */
+bool
 qemuProcessShutdownOrReboot(virDomainObj *vm)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
@@ -620,9 +629,14 @@ qemuProcessShutdownOrReboot(virDomainObj *vm)
             qemuDomainSetFakeReboot(vm, false);
             virObjectUnref(vm);
         }
+
+        return false;
     } else {
         ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_NOWAIT));
+        return true;
     }
+
+    return false;
 }
 
 
@@ -714,7 +728,7 @@ qemuProcessHandleShutdown(qemuMonitor *mon G_GNUC_UNUSED,
     if (priv->agent)
         qemuAgentNotifyEvent(priv->agent, QEMU_AGENT_EVENT_SHUTDOWN);
 
-    qemuProcessShutdownOrReboot(vm);
+    ignore_value(qemuProcessShutdownOrReboot(vm));
 
  unlock:
     virObjectUnlock(vm);
@@ -9705,8 +9719,11 @@ qemuProcessReconnect(void *opaque)
          reason == VIR_DOMAIN_PAUSED_USER)) {
         VIR_DEBUG("Finishing shutdown sequence for domain %s",
                   obj->def->name);
-        qemuProcessShutdownOrReboot(obj);
-        goto cleanup;
+        /* qemuProcessShutdownOrReboot returns 'true' if the VM was terminated.
+         * If the VM is kept (e.g. for fake reboot) we need to continue the
+         * reconnection */
+        if (qemuProcessShutdownOrReboot(obj))
+            goto cleanup;
     }
 
     /* if domain requests security driver we haven't loaded, report error, but
index 9f783790ac757743acfaf965d9bfa4ff026d30af..426e11d79e8e13e276c6b39dac4794eb7e8f3bb9 100644 (file)
@@ -192,7 +192,8 @@ int qemuProcessKill(virDomainObj *vm, unsigned int flags);
 
 int qemuProcessFakeRebootViaRecreate(virDomainObj *vm, bool locked);
 
-void qemuProcessShutdownOrReboot(virDomainObj *vm);
+bool qemuProcessShutdownOrReboot(virDomainObj *vm)
+    G_GNUC_WARN_UNUSED_RESULT;
 
 void qemuProcessAutoDestroy(virDomainObj *dom,
                             virConnectPtr conn);