[PATCH 08/26] remote: always invoke virStateStop for all daemons

Daniel P. Berrangé posted 26 patches 1 week, 5 days ago
[PATCH 08/26] remote: always invoke virStateStop for all daemons
Posted by Daniel P. Berrangé 1 week, 5 days ago
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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/qemu/qemu_driver.c     |  3 ++-
 src/remote/remote_daemon.c | 28 +++++++++++++++-------------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c16566ce8..103369ac93 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -949,7 +949,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 d44a365000..c4b930cb70 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -628,27 +628,29 @@ 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)) {
-
         sessionBus = virGDBusGetSessionBus();
         if (sessionBus != NULL)
             g_dbus_connection_add_filter(sessionBus,
                                          handleSessionMessageFunc, dmn, NULL);
+    }
 
-        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,
+    /* 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 */
     virNetDaemonUpdateServices(dmn, true);
-- 
2.47.1