render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From 0ddfe33c33124b094bf701986c619380363d5f99 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <0ddfe33c33124b094bf701986c619380363d5f99@dist-git>
6ae9ed
From: Erik Skultety <eskultet@redhat.com>
6ae9ed
Date: Tue, 2 Aug 2016 15:20:52 +0200
6ae9ed
Subject: [PATCH] rpc: virnetserver: Add code to CheckLimits to handle
6ae9ed
 suspending of services
6ae9ed
6ae9ed
So far, virNetServerCheckLimits was only used to possibly re-enable accepting
6ae9ed
new clients that might have previously been disabled due to client limits
6ae9ed
violation (max_clients, max_anonymous_clients). This patch refactors
6ae9ed
virNetServerAddClient, which is currently the only place where the services get
6ae9ed
disabled, in order to use the virNetServerCheckLimits helper instead of
6ae9ed
checking the limits by itself.
6ae9ed
6ae9ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6ae9ed
(cherry picked from commit 5b9f735f16b1d49b11610d40d36ab26e6b48926d)
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1357776
6ae9ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6ae9ed
---
6ae9ed
 src/rpc/virnetserver.c | 45 ++++++++++++++++++++++-----------------------
6ae9ed
 1 file changed, 22 insertions(+), 23 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
6ae9ed
index 0c502d9..c5caef3 100644
6ae9ed
--- a/src/rpc/virnetserver.c
6ae9ed
+++ b/src/rpc/virnetserver.c
6ae9ed
@@ -239,24 +239,35 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
6ae9ed
  * @srv: server to check limits on
6ae9ed
  *
6ae9ed
  * Check if limits like max_clients or max_anonymous_clients
6ae9ed
- * are satisfied and if so, re-enable accepting new clients.
6ae9ed
+ * are satisfied. If so, re-enable accepting new clients. If these are violated
6ae9ed
+ * however, temporarily disable accepting new clients.
6ae9ed
  * The @srv must be locked when this function is called.
6ae9ed
  */
6ae9ed
 static void
6ae9ed
 virNetServerCheckLimits(virNetServerPtr srv)
6ae9ed
 {
6ae9ed
-    /* Enable services if we can accept a new client.
6ae9ed
-     * The new client can be accepted if both max_clients and
6ae9ed
-     * max_anonymous_clients wouldn't get overcommitted by
6ae9ed
-     * accepting it. */
6ae9ed
-    VIR_DEBUG("Considering re-enabling services: "
6ae9ed
-              "nclients=%zu nclients_max=%zu "
6ae9ed
+    VIR_DEBUG("Checking client-related limits to re-enable or temporarily "
6ae9ed
+              "suspend services: nclients=%zu nclients_max=%zu "
6ae9ed
               "nclients_unauth=%zu nclients_unauth_max=%zu",
6ae9ed
               srv->nclients, srv->nclients_max,
6ae9ed
               srv->nclients_unauth, srv->nclients_unauth_max);
6ae9ed
-    if (srv->nclients < srv->nclients_max &&
6ae9ed
-        (!srv->nclients_unauth_max ||
6ae9ed
-         srv->nclients_unauth < srv->nclients_unauth_max)) {
6ae9ed
+
6ae9ed
+    /* Check the max_anonymous_clients and max_clients limits so that we can
6ae9ed
+     * decide whether the services should be temporarily suspended, thus not
6ae9ed
+     * accepting any more clients for a while or re-enabling the previously
6ae9ed
+     * suspended services in order to accept new clients again.
6ae9ed
+     * A new client can only be accepted if both max_clients and
6ae9ed
+     * max_anonymous_clients wouldn't get overcommitted by accepting it.
6ae9ed
+     */
6ae9ed
+    if (srv->nclients >= srv->nclients_max ||
6ae9ed
+        (srv->nclients_unauth_max &&
6ae9ed
+         srv->nclients_unauth >= srv->nclients_unauth_max)) {
6ae9ed
+        /* Temporarily stop accepting new clients */
6ae9ed
+        VIR_INFO("Temporarily suspending services");
6ae9ed
+        virNetServerUpdateServicesLocked(srv, false);
6ae9ed
+    } else if (srv->nclients < srv->nclients_max &&
6ae9ed
+               (!srv->nclients_unauth_max ||
6ae9ed
+                srv->nclients_unauth < srv->nclients_unauth_max)) {
6ae9ed
         /* Now it makes sense to accept() a new client. */
6ae9ed
         VIR_INFO("Re-enabling services");
6ae9ed
         virNetServerUpdateServicesLocked(srv, true);
6ae9ed
@@ -286,19 +297,7 @@ int virNetServerAddClient(virNetServerPtr srv,
6ae9ed
     if (virNetServerClientNeedAuth(client))
6ae9ed
         virNetServerTrackPendingAuthLocked(srv);
6ae9ed
 
6ae9ed
-    if (srv->nclients_unauth_max &&
6ae9ed
-        srv->nclients_unauth == srv->nclients_unauth_max) {
6ae9ed
-        /* Temporarily stop accepting new clients */
6ae9ed
-        VIR_INFO("Temporarily suspending services "
6ae9ed
-                 "due to max_anonymous_clients");
6ae9ed
-        virNetServerUpdateServicesLocked(srv, false);
6ae9ed
-    }
6ae9ed
-
6ae9ed
-    if (srv->nclients == srv->nclients_max) {
6ae9ed
-        /* Temporarily stop accepting new clients */
6ae9ed
-        VIR_INFO("Temporarily suspending services due to max_clients");
6ae9ed
-        virNetServerUpdateServicesLocked(srv, false);
6ae9ed
-    }
6ae9ed
+    virNetServerCheckLimits(srv);
6ae9ed
 
6ae9ed
     virNetServerClientSetDispatcher(client,
6ae9ed
                                     virNetServerDispatchNewMessage,
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed