Enable retrieval of the number of maximum clients connected to all sockets combined as well as the number of maximum clients waiting for authentication, in order to be successfully connected. These are the attributes configurable through libvirtd.conf, however, it could be handy to not only know values for these limits, but also the values for the current number of clients connected and number of clients currently waiting for authentication which are changing dynamically. This API does both, retrieves the limits as well as the current dynamic values. Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> --- daemon/admin.c | 44 ++++++++++++++++++++++++++++++++++++++++ daemon/admin_server.c | 41 +++++++++++++++++++++++++++++++++++++ daemon/admin_server.h | 5 +++++ include/libvirt/libvirt-admin.h | 5 +++++ src/admin/admin_protocol.x | 19 ++++++++++++++++- src/admin/admin_remote.c | 45 +++++++++++++++++++++++++++++++++++++++++ src/admin_protocol-structs | 11 ++++++++++ src/libvirt-admin.c | 43 +++++++++++++++++++++++++++++++++++++++ src/libvirt_admin_private.syms | 2 ++ src/libvirt_admin_public.syms | 1 + 10 files changed, 215 insertions(+), 1 deletion(-) diff --git a/daemon/admin.c b/daemon/admin.c index 18ac22b..2510e4f 100644 --- a/daemon/admin.c +++ b/daemon/admin.c @@ -134,4 +134,48 @@ adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED, return 0; } +static int +adminDispatchServerGetClientProcessingControls(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED, + admin_server_get_client_processing_controls_args *args, + admin_server_get_client_processing_controls_ret *ret) +{ + int rv = -1; + virNetServerPtr srv = NULL; + virTypedParameterPtr params = NULL; + int nparams = 0; + struct daemonAdmClientPrivate *priv = + virNetServerClientGetPrivateData(client); + + if (!(srv = virNetDaemonGetServer(priv->dmn, args->srv.name))) + goto cleanup; + + if (adminServerGetClientProcessingControls(srv, ¶ms, &nparams, + args->flags) < 0) + goto cleanup; + + if (nparams > ADMIN_SERVER_CLIENT_PROCESSING_CONTROLS_MAX) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Number of client processing parameters %d exceeds " + "max allowed limit: %d"), nparams, + ADMIN_SERVER_CLIENT_PROCESSING_CONTROLS_MAX); + goto cleanup; + } + + if (virTypedParamsSerialize(params, nparams, + (virTypedParameterRemotePtr *) &ret->params.params_val, + &ret->params.params_len, 0) < 0) + goto cleanup; + + rv = 0; + cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + virTypedParamsFree(params, nparams); + virObjectUnref(srv); + return rv; +} + #include "admin_dispatch.h" diff --git a/daemon/admin_server.c b/daemon/admin_server.c index e2ed1fe..56fa4b5 100644 --- a/daemon/admin_server.c +++ b/daemon/admin_server.c @@ -69,3 +69,44 @@ adminConnectLookupServer(virNetDaemonPtr dmn, return virNetDaemonGetServer(dmn, name); } + +int +adminServerGetClientProcessingControls(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; +} diff --git a/daemon/admin_server.h b/daemon/admin_server.h index 9d0adf0..f172474 100644 --- a/daemon/admin_server.h +++ b/daemon/admin_server.h @@ -35,4 +35,9 @@ virNetServerPtr adminConnectLookupServer(virNetDaemonPtr dmn, const char *name, unsigned int flags); +int adminServerGetClientProcessingControls(virNetServerPtr srv, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); + #endif /* __LIBVIRTD_ADMIN_SERVER_H__ */ diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h index 5cd9e72..faf57ad 100644 --- a/include/libvirt/libvirt-admin.h +++ b/include/libvirt/libvirt-admin.h @@ -152,6 +152,11 @@ virAdmServerPtr virAdmConnectLookupServer(virAdmConnectPtr conn, # define VIR_SERVER_CLIENTS_UNAUTH_CURRENT "nclients_unauth" +int virAdmServerGetClientProcessingControls(virAdmServerPtr srv, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); + # ifdef __cplusplus } # endif diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x index 57dbb6b..f907b87 100644 --- a/src/admin/admin_protocol.x +++ b/src/admin/admin_protocol.x @@ -36,6 +36,9 @@ const ADMIN_STRING_MAX = 4194304; /* Upper limit on list of servers */ const ADMIN_SERVER_LIST_MAX = 16384; +/* Upper limit on number of client processing controls */ +const ADMIN_SERVER_CLIENT_PROCESSING_CONTROLS_MAX = 32; + /* A long string, which may NOT be NULL. */ typedef string admin_nonnull_string<ADMIN_STRING_MAX>; @@ -98,6 +101,15 @@ struct admin_connect_lookup_server_ret { admin_nonnull_server srv; }; +struct admin_server_get_client_processing_controls_args { + admin_nonnull_server srv; + unsigned int flags; +}; + +struct admin_server_get_client_processing_controls_ret { + admin_typed_param params<ADMIN_SERVER_CLIENT_PROCESSING_CONTROLS_MAX>; +}; + /* Define the program number, protocol version and procedure numbers here. */ const ADMIN_PROGRAM = 0x06900690; const ADMIN_PROTOCOL_VERSION = 1; @@ -143,5 +155,10 @@ enum admin_procedure { /** * @generate: both */ - ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5 + ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5, + + /** + * @generate: none + */ + ADMIN_PROC_SERVER_GET_CLIENT_PROCESSING_CONTROLS = 6 }; diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c index a1b2f84..d56237d 100644 --- a/src/admin/admin_remote.c +++ b/src/admin/admin_remote.c @@ -39,6 +39,12 @@ struct _remoteAdminPriv { static virClassPtr remoteAdminPrivClass; static void +make_nonnull_server(admin_nonnull_server *srv_dst, virAdmServerPtr srv_src) +{ + srv_dst->name = srv_src->name; +} + +static void remoteAdminPrivDispose(void *opaque) { remoteAdminPrivPtr priv = opaque; @@ -225,3 +231,42 @@ remoteAdminPrivNew(const char *sock_path) virObjectUnref(priv); return NULL; } + +static int +remoteAdminServerGetClientProcessingControls(virAdmServerPtr srv, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + int rv = -1; + admin_server_get_client_processing_controls_args args; + admin_server_get_client_processing_controls_ret ret; + remoteAdminPrivPtr priv = srv->conn->privateData; + + args.flags = flags; + make_nonnull_server(&args.srv, srv); + + memset(&ret, 0, sizeof(ret)); + virObjectLock(priv); + + if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_CLIENT_PROCESSING_CONTROLS, + (xdrproc_t) xdr_admin_server_get_client_processing_controls_args, + (char *) &args, + (xdrproc_t) xdr_admin_server_get_client_processing_controls_ret, + (char *) &ret) == -1) + goto cleanup; + + if (virTypedParamsDeserialize((virTypedParameterRemotePtr) ret.params.params_val, + ret.params.params_len, + ADMIN_SERVER_CLIENT_PROCESSING_CONTROLS_MAX, + params, + nparams) < 0) + goto cleanup; + + rv = 0; + xdr_free((xdrproc_t) xdr_admin_server_get_client_processing_controls_ret, + (char *) &ret); + cleanup: + virObjectUnlock(priv); + return rv; +} diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs index 26c8443..b248a37 100644 --- a/src/admin_protocol-structs +++ b/src/admin_protocol-structs @@ -51,10 +51,21 @@ struct admin_connect_lookup_server_args { struct admin_connect_lookup_server_ret { admin_nonnull_server srv; }; +struct admin_server_get_client_processing_controls_args { + admin_nonnull_server srv; + u_int flags; +}; +struct admin_server_get_client_processing_controls_ret { + struct { + u_int params_len; + admin_typed_param * params_val; + } params; +}; enum admin_procedure { ADMIN_PROC_CONNECT_OPEN = 1, ADMIN_PROC_CONNECT_CLOSE = 2, ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3, ADMIN_PROC_CONNECT_LIST_SERVERS = 4, ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5, + ADMIN_PROC_SERVER_GET_CLIENT_PROCESSING_CONTROLS = 6, }; diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index 6577c87..563d7d3 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -674,3 +674,46 @@ virAdmConnectLookupServer(virAdmConnectPtr conn, virDispatchError(NULL); return ret; } + +/** + * virAdmServerGetClientProcessingControls: + * @srv: a valid server object reference + * @params: pointer to client processing controls object + * (return value, allocated automatically) + * @nparams: pointer to number of parameters returned in @params + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Retrieve client processing controls. These include: + * - current number of clients connected to @srv, + * - maximum number of clients connected to @srv, + * - current number of clients connected to @srv waiting for authentication, + * - maximum number of clients connected to @srv that can be wainting for + * authentication. + * + * Returns 0 on success, allocating @params to size returned in @nparams, or + * -1 in case of an error. Caller is responsible for deallocating @params. + */ +int +virAdmServerGetClientProcessingControls(virAdmServerPtr srv, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + int ret = -1; + + VIR_DEBUG("srv=%p, flags=%x", srv, flags); + virResetLastError(); + + virCheckAdmServerGoto(srv, error); + virCheckFlagsGoto(0, error); + + if ((ret = remoteAdminServerGetClientProcessingControls(srv, params, + nparams, + flags)) < 0) + goto error; + + return ret; + error: + virDispatchError(NULL); + return -1; +} diff --git a/src/libvirt_admin_private.syms b/src/libvirt_admin_private.syms index 268f1e6..ca08ff1 100644 --- a/src/libvirt_admin_private.syms +++ b/src/libvirt_admin_private.syms @@ -12,6 +12,8 @@ xdr_admin_connect_list_servers_ret; xdr_admin_connect_lookup_server_args; xdr_admin_connect_lookup_server_ret; xdr_admin_connect_open_args; +xdr_admin_server_get_client_processing_controls_args; +xdr_admin_server_get_client_processing_controls_ret; # datatypes.h virAdmConnectClass; diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms index 58d085e..c0e0da2 100644 --- a/src/libvirt_admin_public.syms +++ b/src/libvirt_admin_public.syms @@ -25,4 +25,5 @@ LIBVIRT_ADMIN_1.3.0 { virAdmServerGetName; virAdmServerFree; virAdmConnectLookupServer; + virAdmServerGetClientProcessingControls; }; -- 2.4.11 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list