]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetDaemonAutoShutdown: Allow live update of shutdown timeout
authorPeter Krempa <pkrempa@redhat.com>
Mon, 13 Jun 2022 12:25:06 +0000 (14:25 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 7 Jul 2022 12:35:30 +0000 (14:35 +0200)
Modify the code so that calling 'virNetDaemonAutoShutdown' will update
the auto shutdown timeout also for running daemons.

This involves changing the logic when to do the update of the timer so
that it can be called from both when the daemon is not yet runnign and
when doing a live update.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/locking/lock_daemon.c
src/logging/log_daemon.c
src/remote/remote_daemon.c
src/rpc/virnetdaemon.c
src/rpc/virnetdaemon.h

index a83ea33b4fbd039c5a72f9924aa77a699e6c408d..c997d327c4f291f7ca6599b994dfd5a5c770ecf9 100644 (file)
@@ -1049,9 +1049,8 @@ int main(int argc, char **argv) {
     }
 
     if (timeout > 0) {
-        VIR_DEBUG("Registering shutdown timeout %d", timeout);
-        virNetDaemonAutoShutdown(lockDaemon->dmn,
-                                 timeout);
+        if (virNetDaemonAutoShutdown(lockDaemon->dmn, timeout) < 0)
+            goto cleanup;
     }
 
     if ((virLockDaemonSetupSignals(lockDaemon->dmn)) < 0) {
index 91ed119c7f130ee828b5478ad7352f6fca567f6d..00fc4148fd6ce68693238f6535788ebc9f7aa8a0 100644 (file)
@@ -854,9 +854,8 @@ int main(int argc, char **argv) {
     }
 
     if (timeout > 0) {
-        VIR_DEBUG("Registering shutdown timeout %d", timeout);
-        virNetDaemonAutoShutdown(logDaemon->dmn,
-                                 timeout);
+        if (virNetDaemonAutoShutdown(logDaemon->dmn, timeout) < 0)
+            return -1;
     }
 
     if ((virLogDaemonSetupSignals(logDaemon->dmn)) < 0) {
index 2e64e4da7f7be14e905f64f6194a824da5e81fa6..23a5eeb20078ff7f4f24ad2fadde31a6d79b17d0 100644 (file)
@@ -1123,8 +1123,8 @@ int main(int argc, char **argv) {
     }
 
     if (timeout > 0) {
-        VIR_DEBUG("Registering shutdown timeout %d", timeout);
-        virNetDaemonAutoShutdown(dmn, timeout);
+        if (virNetDaemonAutoShutdown(dmn, timeout) < 0)
+            goto cleanup;
     }
 
     if ((daemonSetupSignals(dmn)) < 0) {
index 9355c7a5fa6fe159b71a37345fba9e4cdbff32e4..ac12d2d412f1f4fef48e5237958643eacfd39831 100644 (file)
@@ -73,6 +73,7 @@ struct _virNetDaemon {
     bool finished;
     bool graceful;
     bool execRestart;
+    bool running; /* the daemon has reached the running phase */
 
     unsigned int autoShutdownTimeout;
     int autoShutdownTimerID;
@@ -422,7 +423,7 @@ virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED,
 static int
 virNetDaemonShutdownTimerRegister(virNetDaemon *dmn)
 {
-    if (dmn->autoShutdownTimeout == 0)
+    if (dmn->autoShutdownTimerID != -1)
         return 0;
 
     if ((dmn->autoShutdownTimerID = virEventAddTimeout(-1,
@@ -440,7 +441,7 @@ virNetDaemonShutdownTimerRegister(virNetDaemon *dmn)
 static void
 virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
 {
-    if (dmn->autoShutdownTimeout == 0)
+    if (dmn->autoShutdownTimerID == -1)
         return;
 
     /* A shutdown timeout is specified, so check
@@ -448,13 +449,15 @@ virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
      * shutdown after timeout seconds
      */
     if (dmn->autoShutdownTimerActive) {
-        if (virNetDaemonHasClients(dmn)) {
+        if (virNetDaemonHasClients(dmn) ||
+            dmn->autoShutdownTimeout == 0) {
             VIR_DEBUG("Deactivating shutdown timer %d", dmn->autoShutdownTimerID);
             virEventUpdateTimeout(dmn->autoShutdownTimerID, -1);
             dmn->autoShutdownTimerActive = false;
         }
     } else {
-        if (!virNetDaemonHasClients(dmn)) {
+        if (!virNetDaemonHasClients(dmn) &&
+            dmn->autoShutdownTimeout != 0) {
             VIR_DEBUG("Activating shutdown timer %d", dmn->autoShutdownTimerID);
             virEventUpdateTimeout(dmn->autoShutdownTimerID,
                                   dmn->autoShutdownTimeout * 1000);
@@ -464,13 +467,25 @@ virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
 }
 
 
-void
+int
 virNetDaemonAutoShutdown(virNetDaemon *dmn,
                          unsigned int timeout)
 {
     VIR_LOCK_GUARD lock = virObjectLockGuard(dmn);
 
+    VIR_DEBUG("Registering shutdown timeout %u", timeout);
+
+    if (timeout > 0) {
+        if (virNetDaemonShutdownTimerRegister(dmn) < 0)
+            return -1;
+    }
+
     dmn->autoShutdownTimeout = timeout;
+
+    if (dmn->running)
+        virNetDaemonShutdownTimerUpdate(dmn);
+
+    return 0;
 }
 
 
@@ -809,9 +824,7 @@ virNetDaemonRun(virNetDaemon *dmn)
     dmn->finishTimer = -1;
     dmn->finished = false;
     dmn->graceful = false;
-
-    if (virNetDaemonShutdownTimerRegister(dmn) < 0)
-        goto cleanup;
+    dmn->running = true;
 
     /* We are accepting connections now. Notify systemd
      * so it can start dependent services. */
index d588f86799c4b4f2560d15fa666add9c01007f31..31a355adb4114c1eb453efe121d5f955470e1a27 100644 (file)
@@ -46,8 +46,8 @@ virJSONValue *virNetDaemonPreExecRestart(virNetDaemon *dmn);
 
 bool virNetDaemonIsPrivileged(virNetDaemon *dmn);
 
-void virNetDaemonAutoShutdown(virNetDaemon *dmn,
-                              unsigned int timeout);
+int virNetDaemonAutoShutdown(virNetDaemon *dmn,
+                             unsigned int timeout) G_GNUC_WARN_UNUSED_RESULT;
 
 void virNetDaemonAddShutdownInhibition(virNetDaemon *dmn);
 void virNetDaemonRemoveShutdownInhibition(virNetDaemon *dmn);