From 2b792b35a4cc6c0acfc592033ccb0c21336f0c5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 17 Dec 2024 17:06:18 +0000 Subject: [PATCH] remote: always invoke virStateStop for all daemons MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently the virStateStop method is only wired up to run save for the unprivileged daemons, so there is no functional change. IOW, session exit, or host OS shutdown will trigger VM managed saved for QEMU session daemon, but not the system daemon. This changes the daemon code to always run virStateStop for all daemons. Instead the QEMU driver is responsible for skipping its own logic when running privileged...for now. This means that virStateStop will now be triggered by logind's PrepareForShutdown signal. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrangé --- src/qemu/qemu_driver.c | 3 ++- src/remote/remote_daemon.c | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5f0f456184..8ccbd97828 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -968,7 +968,8 @@ qemuStateStop(void) .uri = cfg->uri, }; - virDomainDriverAutoShutdown(&ascfg); + if (!qemu_driver->privileged) + virDomainDriverAutoShutdown(&ascfg); return 0; } diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index d90355c0d2..2f6cef1828 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -628,30 +628,32 @@ static void daemonRunStateInit(void *opaque) virStateShutdownPrepare, virStateShutdownWait); - /* Tie the non-privileged daemons to the session/shutdown lifecycle */ + /* Signal for VM shutdown when desktop session is terminated, in + * unprivileged daemons */ if (!virNetDaemonIsPrivileged(dmn)) { - if (virGDBusHasSessionBus()) { sessionBus = virGDBusGetSessionBus(); if (sessionBus != NULL) g_dbus_connection_add_filter(sessionBus, handleSessionMessageFunc, dmn, NULL); } + } - if (virGDBusHasSystemBus()) { - systemBus = virGDBusGetSystemBus(); - if (systemBus != NULL) - g_dbus_connection_signal_subscribe(systemBus, - "org.freedesktop.login1", - "org.freedesktop.login1.Manager", - "PrepareForShutdown", - NULL, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - handleSystemMessageFunc, - dmn, - NULL); - } + if (virGDBusHasSystemBus()) { + /* Signal for VM shutdown when host OS shutdown is requested, in + * both privileged and unprivileged daemons */ + systemBus = virGDBusGetSystemBus(); + if (systemBus != NULL) + g_dbus_connection_signal_subscribe(systemBus, + "org.freedesktop.login1", + "org.freedesktop.login1.Manager", + "PrepareForShutdown", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + handleSystemMessageFunc, + dmn, + NULL); } /* Only now accept clients from network */ -- 2.47.3