mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
rpc: virnetserver: Add code to CheckLimits to handle suspending of services
So far, virNetServerCheckLimits was only used to possibly re-enable accepting new clients that might have previously been disabled due to client limits violation (max_clients, max_anonymous_clients). This patch refactors virNetServerAddClient, which is currently the only place where the services get disabled, in order to use the virNetServerCheckLimits helper instead of checking the limits by itself. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
17bc333411
commit
5b9f735f16
@ -239,24 +239,35 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
|||||||
* @srv: server to check limits on
|
* @srv: server to check limits on
|
||||||
*
|
*
|
||||||
* Check if limits like max_clients or max_anonymous_clients
|
* Check if limits like max_clients or max_anonymous_clients
|
||||||
* are satisfied and if so, re-enable accepting new clients.
|
* are satisfied. If so, re-enable accepting new clients. If these are violated
|
||||||
|
* however, temporarily disable accepting new clients.
|
||||||
* The @srv must be locked when this function is called.
|
* The @srv must be locked when this function is called.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
virNetServerCheckLimits(virNetServerPtr srv)
|
virNetServerCheckLimits(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
/* Enable services if we can accept a new client.
|
VIR_DEBUG("Checking client-related limits to re-enable or temporarily "
|
||||||
* The new client can be accepted if both max_clients and
|
"suspend services: nclients=%zu nclients_max=%zu "
|
||||||
* max_anonymous_clients wouldn't get overcommitted by
|
|
||||||
* accepting it. */
|
|
||||||
VIR_DEBUG("Considering re-enabling services: "
|
|
||||||
"nclients=%zu nclients_max=%zu "
|
|
||||||
"nclients_unauth=%zu nclients_unauth_max=%zu",
|
"nclients_unauth=%zu nclients_unauth_max=%zu",
|
||||||
srv->nclients, srv->nclients_max,
|
srv->nclients, srv->nclients_max,
|
||||||
srv->nclients_unauth, srv->nclients_unauth_max);
|
srv->nclients_unauth, srv->nclients_unauth_max);
|
||||||
if (srv->nclients < srv->nclients_max &&
|
|
||||||
(!srv->nclients_unauth_max ||
|
/* Check the max_anonymous_clients and max_clients limits so that we can
|
||||||
srv->nclients_unauth < srv->nclients_unauth_max)) {
|
* decide whether the services should be temporarily suspended, thus not
|
||||||
|
* accepting any more clients for a while or re-enabling the previously
|
||||||
|
* suspended services in order to accept new clients again.
|
||||||
|
* A new client can only be accepted if both max_clients and
|
||||||
|
* max_anonymous_clients wouldn't get overcommitted by accepting it.
|
||||||
|
*/
|
||||||
|
if (srv->nclients >= srv->nclients_max ||
|
||||||
|
(srv->nclients_unauth_max &&
|
||||||
|
srv->nclients_unauth >= srv->nclients_unauth_max)) {
|
||||||
|
/* Temporarily stop accepting new clients */
|
||||||
|
VIR_INFO("Temporarily suspending services");
|
||||||
|
virNetServerUpdateServicesLocked(srv, false);
|
||||||
|
} else if (srv->nclients < srv->nclients_max &&
|
||||||
|
(!srv->nclients_unauth_max ||
|
||||||
|
srv->nclients_unauth < srv->nclients_unauth_max)) {
|
||||||
/* Now it makes sense to accept() a new client. */
|
/* Now it makes sense to accept() a new client. */
|
||||||
VIR_INFO("Re-enabling services");
|
VIR_INFO("Re-enabling services");
|
||||||
virNetServerUpdateServicesLocked(srv, true);
|
virNetServerUpdateServicesLocked(srv, true);
|
||||||
@ -286,19 +297,7 @@ int virNetServerAddClient(virNetServerPtr srv,
|
|||||||
if (virNetServerClientNeedAuth(client))
|
if (virNetServerClientNeedAuth(client))
|
||||||
virNetServerTrackPendingAuthLocked(srv);
|
virNetServerTrackPendingAuthLocked(srv);
|
||||||
|
|
||||||
if (srv->nclients_unauth_max &&
|
virNetServerCheckLimits(srv);
|
||||||
srv->nclients_unauth == srv->nclients_unauth_max) {
|
|
||||||
/* Temporarily stop accepting new clients */
|
|
||||||
VIR_INFO("Temporarily suspending services "
|
|
||||||
"due to max_anonymous_clients");
|
|
||||||
virNetServerUpdateServicesLocked(srv, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (srv->nclients == srv->nclients_max) {
|
|
||||||
/* Temporarily stop accepting new clients */
|
|
||||||
VIR_INFO("Temporarily suspending services due to max_clients");
|
|
||||||
virNetServerUpdateServicesLocked(srv, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
virNetServerClientSetDispatcher(client,
|
virNetServerClientSetDispatcher(client,
|
||||||
virNetServerDispatchNewMessage,
|
virNetServerDispatchNewMessage,
|
||||||
|
Loading…
Reference in New Issue
Block a user