2015-08-14 07:17:01 +00:00
|
|
|
/*
|
|
|
|
* admin_server.c: admin methods to manage daemons and clients
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Erik Skultety <eskultet@redhat.com>
|
|
|
|
* Martin Kletzander <mkletzan@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "admin_server.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virerror.h"
|
2016-04-22 11:05:42 +00:00
|
|
|
#include "viridentity.h"
|
2015-08-14 07:17:01 +00:00
|
|
|
#include "virlog.h"
|
|
|
|
#include "virnetdaemon.h"
|
|
|
|
#include "virnetserver.h"
|
|
|
|
#include "virstring.h"
|
2015-11-23 11:41:32 +00:00
|
|
|
#include "virthreadpool.h"
|
admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
1) setting the minimum
a) When the limit is increased, depending on the current number of
threads, new threads are possibly spawned if the current number of
threads is less than the new minimum limit
b) Decreasing the minimum limit has no possible effect on the current
number of threads
2) setting the maximum
a) Icreasing the maximum limit has no immediate effect on the current
number of threads, it only allows the threadpool to spawn more
threads when new jobs, that would otherwise end up queued, arrive.
b) Decreasing the maximum limit may affect the current number of
threads, if the current number of threads is less than the new
maximum limit. Since there may be some ongoing time-consuming jobs
that would effectively block this API from killing any threads.
Therefore, this API is asynchronous with best-effort execution,
i.e. the necessary number of workers will be terminated once they
finish their previous job, unless other workers had already
terminated, decreasing the limit to the requested value.
3) setting priority workers
- both increase and decrease in count of these workers have an
immediate impact on the current number of workers, new ones will be
spawned or some of them get terminated respectively.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-22 13:24:04 +00:00
|
|
|
#include "virtypedparam.h"
|
2015-08-14 07:17:01 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ADMIN
|
|
|
|
|
|
|
|
VIR_LOG_INIT("daemon.admin_server");
|
|
|
|
|
|
|
|
int
|
2016-03-02 14:32:55 +00:00
|
|
|
adminConnectListServers(virNetDaemonPtr dmn,
|
|
|
|
virNetServerPtr **servers,
|
|
|
|
unsigned int flags)
|
2015-08-14 07:17:01 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-03-01 14:31:18 +00:00
|
|
|
virNetServerPtr *srvs = NULL;
|
2015-08-14 07:17:01 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2016-03-01 15:28:58 +00:00
|
|
|
if ((ret = virNetDaemonGetServers(dmn, &srvs)) < 0)
|
2015-08-14 07:17:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (servers) {
|
|
|
|
*servers = srvs;
|
|
|
|
srvs = NULL;
|
|
|
|
}
|
|
|
|
cleanup:
|
2016-03-25 09:18:00 +00:00
|
|
|
if (ret > 0)
|
|
|
|
virObjectListFreeCount(srvs, ret);
|
2015-08-14 07:17:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-03-01 16:33:37 +00:00
|
|
|
|
|
|
|
virNetServerPtr
|
|
|
|
adminConnectLookupServer(virNetDaemonPtr dmn,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(flags, NULL);
|
|
|
|
|
|
|
|
return virNetDaemonGetServer(dmn, name);
|
|
|
|
}
|
2015-11-23 11:41:32 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminServerGetThreadPoolParameters(virNetServerPtr srv,
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int maxparams = 0;
|
|
|
|
size_t minWorkers;
|
|
|
|
size_t maxWorkers;
|
|
|
|
size_t nWorkers;
|
|
|
|
size_t freeWorkers;
|
|
|
|
size_t nPrioWorkers;
|
|
|
|
size_t jobQueueDepth;
|
|
|
|
virTypedParameterPtr tmpparams = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (virNetServerGetThreadPoolParameters(srv, &minWorkers, &maxWorkers,
|
|
|
|
&nWorkers, &freeWorkers,
|
|
|
|
&nPrioWorkers,
|
|
|
|
&jobQueueDepth) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to retrieve threadpool parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_WORKERS_MIN,
|
|
|
|
minWorkers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_WORKERS_MAX,
|
|
|
|
maxWorkers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_WORKERS_CURRENT,
|
|
|
|
nWorkers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_WORKERS_FREE,
|
|
|
|
freeWorkers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_WORKERS_PRIORITY,
|
|
|
|
nPrioWorkers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams,
|
|
|
|
&maxparams, VIR_THREADPOOL_JOB_QUEUE_DEPTH,
|
|
|
|
jobQueueDepth) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*params = tmpparams;
|
|
|
|
tmpparams = NULL;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virTypedParamsFree(tmpparams, *nparams);
|
|
|
|
return ret;
|
|
|
|
}
|
admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
1) setting the minimum
a) When the limit is increased, depending on the current number of
threads, new threads are possibly spawned if the current number of
threads is less than the new minimum limit
b) Decreasing the minimum limit has no possible effect on the current
number of threads
2) setting the maximum
a) Icreasing the maximum limit has no immediate effect on the current
number of threads, it only allows the threadpool to spawn more
threads when new jobs, that would otherwise end up queued, arrive.
b) Decreasing the maximum limit may affect the current number of
threads, if the current number of threads is less than the new
maximum limit. Since there may be some ongoing time-consuming jobs
that would effectively block this API from killing any threads.
Therefore, this API is asynchronous with best-effort execution,
i.e. the necessary number of workers will be terminated once they
finish their previous job, unless other workers had already
terminated, decreasing the limit to the requested value.
3) setting priority workers
- both increase and decrease in count of these workers have an
immediate impact on the current number of workers, new ones will be
spawned or some of them get terminated respectively.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-22 13:24:04 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminServerSetThreadPoolParameters(virNetServerPtr srv,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
long long int minWorkers = -1;
|
|
|
|
long long int maxWorkers = -1;
|
|
|
|
long long int prioWorkers = -1;
|
|
|
|
virTypedParameterPtr param = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_THREADPOOL_WORKERS_MIN,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
VIR_THREADPOOL_WORKERS_MAX,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
VIR_THREADPOOL_WORKERS_PRIORITY,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
NULL) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((param = virTypedParamsGet(params, nparams,
|
|
|
|
VIR_THREADPOOL_WORKERS_MIN)))
|
|
|
|
minWorkers = param->value.ui;
|
|
|
|
|
|
|
|
if ((param = virTypedParamsGet(params, nparams,
|
|
|
|
VIR_THREADPOOL_WORKERS_MAX)))
|
|
|
|
maxWorkers = param->value.ui;
|
|
|
|
|
|
|
|
if ((param = virTypedParamsGet(params, nparams,
|
|
|
|
VIR_THREADPOOL_WORKERS_PRIORITY)))
|
|
|
|
prioWorkers = param->value.ui;
|
|
|
|
|
|
|
|
if (virNetServerSetThreadPoolParameters(srv, minWorkers,
|
|
|
|
maxWorkers, prioWorkers) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-14 22:20:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminServerListClients(virNetServerPtr srv,
|
|
|
|
virNetServerClientPtr **clients,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virNetServerClientPtr *clts;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if ((ret = virNetServerGetClients(srv, &clts)) < 0)
|
2016-05-05 22:32:25 +00:00
|
|
|
return -1;
|
2016-04-14 22:20:11 +00:00
|
|
|
|
|
|
|
if (clients) {
|
|
|
|
*clients = clts;
|
|
|
|
clts = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virObjectListFreeCount(clts, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-22 07:47:09 +00:00
|
|
|
|
|
|
|
virNetServerClientPtr
|
|
|
|
adminServerLookupClient(virNetServerPtr srv,
|
|
|
|
unsigned long long id,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
return virNetServerGetClient(srv, id);
|
|
|
|
}
|
2016-04-22 11:05:42 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminClientGetInfo(virNetServerClientPtr client,
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int maxparams = 0;
|
|
|
|
bool readonly;
|
2016-06-29 05:03:13 +00:00
|
|
|
char *sock_addr = NULL;
|
2016-04-22 11:05:42 +00:00
|
|
|
const char *attr = NULL;
|
|
|
|
virTypedParameterPtr tmpparams = NULL;
|
|
|
|
virIdentityPtr identity = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (virNetServerClientGetInfo(client, &readonly,
|
|
|
|
&sock_addr, &identity) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddBoolean(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_READONLY,
|
|
|
|
readonly) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-07-19 06:55:31 +00:00
|
|
|
if (virIdentityGetSASLUserName(identity, &attr) < 0 ||
|
|
|
|
(attr &&
|
|
|
|
virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_SASL_USER_NAME,
|
|
|
|
attr) < 0))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-04-22 11:05:42 +00:00
|
|
|
if (!virNetServerClientIsLocal(client)) {
|
|
|
|
if (virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_SOCKET_ADDR,
|
|
|
|
sock_addr) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virIdentityGetX509DName(identity, &attr) < 0 ||
|
|
|
|
(attr &&
|
|
|
|
virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_X509_DISTINGUISHED_NAME,
|
|
|
|
attr) < 0))
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
pid_t pid;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
if (virIdentityGetUNIXUserID(identity, &uid) < 0 ||
|
|
|
|
virTypedParamsAddInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_UNIX_USER_ID, uid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virIdentityGetUNIXUserName(identity, &attr) < 0 ||
|
|
|
|
virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_UNIX_USER_NAME,
|
|
|
|
attr) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virIdentityGetUNIXGroupID(identity, &gid) < 0 ||
|
|
|
|
virTypedParamsAddInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_UNIX_GROUP_ID, gid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virIdentityGetUNIXGroupName(identity, &attr) < 0 ||
|
|
|
|
virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_UNIX_GROUP_NAME,
|
|
|
|
attr) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virIdentityGetUNIXProcessID(identity, &pid) < 0 ||
|
|
|
|
virTypedParamsAddInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_UNIX_PROCESS_ID, pid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virIdentityGetSELinuxContext(identity, &attr) < 0 ||
|
|
|
|
(attr &&
|
|
|
|
virTypedParamsAddString(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_CLIENT_INFO_SELINUX_CONTEXT, attr) < 0))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*params = tmpparams;
|
|
|
|
tmpparams = NULL;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnref(identity);
|
2016-06-29 05:03:13 +00:00
|
|
|
VIR_FREE(sock_addr);
|
2016-04-22 11:05:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-04-28 08:26:25 +00:00
|
|
|
|
|
|
|
int adminClientClose(virNetServerClientPtr client,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
virNetServerClientClose(client);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-04 08:28:22 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminServerGetClientLimits(virNetServerPtr srv,
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
int *nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int maxparams = 0;
|
|
|
|
virTypedParameterPtr tmpparams = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_SERVER_CLIENTS_MAX,
|
|
|
|
virNetServerGetMaxClients(srv)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_SERVER_CLIENTS_CURRENT,
|
|
|
|
virNetServerGetCurrentClients(srv)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_SERVER_CLIENTS_UNAUTH_MAX,
|
|
|
|
virNetServerGetMaxUnauthClients(srv)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams,
|
|
|
|
VIR_SERVER_CLIENTS_UNAUTH_CURRENT,
|
|
|
|
virNetServerGetCurrentUnauthClients(srv)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*params = tmpparams;
|
|
|
|
tmpparams = NULL;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virTypedParamsFree(tmpparams, *nparams);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-04 12:24:52 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adminServerSetClientLimits(virNetServerPtr srv,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
long long int maxClients = -1;
|
|
|
|
long long int maxClientsUnauth = -1;
|
|
|
|
virTypedParameterPtr param = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_SERVER_CLIENTS_MAX,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
VIR_SERVER_CLIENTS_UNAUTH_MAX,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
NULL) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((param = virTypedParamsGet(params, nparams,
|
|
|
|
VIR_SERVER_CLIENTS_MAX)))
|
|
|
|
maxClients = param->value.ui;
|
|
|
|
|
|
|
|
if ((param = virTypedParamsGet(params, nparams,
|
|
|
|
VIR_SERVER_CLIENTS_UNAUTH_MAX)))
|
|
|
|
maxClientsUnauth = param->value.ui;
|
|
|
|
|
|
|
|
if (virNetServerSetClientProcessingControls(srv, maxClients,
|
|
|
|
maxClientsUnauth) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|