[PATCH 2/6] virNetDaemonAutoShutdown: Allow live update of shutdown timeout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/locking/lock_daemon.c  |  5 ++---
 src/logging/log_daemon.c   |  5 ++---
 src/remote/remote_daemon.c |  4 ++--
 src/rpc/virnetdaemon.c     | 29 +++++++++++++++++++++--------
 src/rpc/virnetdaemon.h     |  4 ++--
 5 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 75f6c708db..59c110f62b 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -1051,9 +1051,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) {
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 8ab334ff6d..8345d31a8c 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -859,9 +859,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) {
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index b8ecc51758..9ad71c37db 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -1126,8 +1126,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) {
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index 7bf27eed9d..84af1adc06 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -75,6 +75,7 @@ struct _virNetDaemon {
     bool finished;
     bool graceful;
     bool execRestart;
+    bool running; /* the daemon has reached the running phase */

     unsigned int autoShutdownTimeout;
     int autoShutdownTimerID;
@@ -424,7 +425,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,
@@ -442,7 +443,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
@@ -450,13 +451,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);
@@ -466,13 +469,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;
 }


@@ -811,9 +826,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. */
diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h
index f91b59a4fd..bfee155a4b 100644
--- a/src/rpc/virnetdaemon.h
+++ b/src/rpc/virnetdaemon.h
@@ -49,8 +49,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);
-- 
2.36.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux