提交 ed978fa2 编写于 作者: E Erik Skultety

admin: Introduce listing clients

Finally add public method to retrieve the list of currently connected clients
to a given server.
Signed-off-by: NErik Skultety <eskultet@redhat.com>
上级 42b06aa6
......@@ -81,6 +81,12 @@ remoteAdmClientInitHook(virNetServerClientPtr client ATTRIBUTE_UNUSED,
/* Helpers */
static virNetServerPtr
get_nonnull_server(virNetDaemonPtr dmn, admin_nonnull_server srv)
{
return virNetDaemonGetServer(dmn, srv.name);
}
static void
make_nonnull_server(admin_nonnull_server *srv_dst,
virNetServerPtr srv_src)
......@@ -88,6 +94,15 @@ make_nonnull_server(admin_nonnull_server *srv_dst,
ignore_value(VIR_STRDUP_QUIET(srv_dst->name, virNetServerGetName(srv_src)));
}
static void
make_nonnull_client(admin_nonnull_client *clt_dst,
virNetServerClientPtr clt_src)
{
clt_dst->id = virNetServerClientGetID(clt_src);
clt_dst->timestamp = virNetServerClientGetTimestamp(clt_src);
clt_dst->transport = virNetServerClientGetTransport(clt_src);
}
/* Functions */
static int
adminDispatchConnectOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
......
......@@ -178,3 +178,26 @@ adminServerSetThreadPoolParameters(virNetServerPtr srv,
return 0;
}
int
adminServerListClients(virNetServerPtr srv,
virNetServerClientPtr **clients,
unsigned int flags)
{
int ret = -1;
virNetServerClientPtr *clts;
virCheckFlags(0, -1);
if ((ret = virNetServerGetClients(srv, &clts)) < 0)
goto cleanup;
if (clients) {
*clients = clts;
clts = NULL;
}
cleanup:
virObjectListFreeCount(clts, ret);
return ret;
}
......@@ -46,4 +46,8 @@ adminServerSetThreadPoolParameters(virNetServerPtr srv,
int nparams,
unsigned int flags);
int adminServerListClients(virNetServerPtr srv,
virNetServerClientPtr **clients,
unsigned int flags);
#endif /* __LIBVIRTD_ADMIN_SERVER_H__ */
......@@ -215,6 +215,10 @@ typedef enum {
# endif
} virClientTransport;
int virAdmServerListClients(virAdmServerPtr srv,
virAdmClientPtr **clients,
unsigned int flags);
# ifdef __cplusplus
}
# endif
......
......@@ -39,6 +39,9 @@ const ADMIN_SERVER_LIST_MAX = 16384;
/* Upper limit on number of threadpool parameters */
const ADMIN_SERVER_THREADPOOL_PARAMETERS_MAX = 32;
/* Upper limit on list of clients */
const ADMIN_CLIENT_LIST_MAX = 16384;
/* A long string, which may NOT be NULL. */
typedef string admin_nonnull_string<ADMIN_STRING_MAX>;
......@@ -124,6 +127,17 @@ struct admin_server_set_threadpool_parameters_args {
unsigned int flags;
};
struct admin_server_list_clients_args {
admin_nonnull_server srv;
unsigned int need_results;
unsigned int flags;
};
struct admin_server_list_clients_ret { /* insert@1 */
admin_nonnull_client clients<ADMIN_CLIENT_LIST_MAX>;
unsigned int ret;
};
/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1;
......@@ -179,5 +193,10 @@ enum admin_procedure {
/**
* @generate: none
*/
ADMIN_PROC_SERVER_SET_THREADPOOL_PARAMETERS = 7
ADMIN_PROC_SERVER_SET_THREADPOOL_PARAMETERS = 7,
/**
* @generate: both
*/
ADMIN_PROC_SERVER_LIST_CLIENTS = 8
};
......@@ -55,6 +55,12 @@ get_nonnull_server(virAdmConnectPtr conn, admin_nonnull_server server)
return virAdmGetServer(conn, server.name);
}
static virAdmClientPtr
get_nonnull_client(virAdmServerPtr srv, admin_nonnull_client client)
{
return virAdmGetClient(srv, client.id, client.timestamp, client.transport);
}
static void
make_nonnull_server(admin_nonnull_server *srv_dst, virAdmServerPtr srv_src)
{
......
......@@ -75,6 +75,18 @@ struct admin_server_set_threadpool_parameters_args {
} params;
u_int flags;
};
struct admin_server_list_clients_args {
admin_nonnull_server srv;
u_int need_results;
u_int flags;
};
struct admin_server_list_clients_ret {
struct {
u_int clients_len;
admin_nonnull_client * clients_val;
} clients;
u_int ret;
};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
......@@ -83,4 +95,5 @@ enum admin_procedure {
ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5,
ADMIN_PROC_SERVER_GET_THREADPOOL_PARAMETERS = 6,
ADMIN_PROC_SERVER_SET_THREADPOOL_PARAMETERS = 7,
ADMIN_PROC_SERVER_LIST_CLIENTS = 8,
};
......@@ -848,3 +848,44 @@ virAdmServerSetThreadPoolParameters(virAdmServerPtr srv,
virDispatchError(NULL);
return -1;
}
/**
* virAdmServerListClients:
* @srv: a valid server object reference
* @clients: pointer to a list to store an array containing objects or NULL
* if the list is not required (number of clients only)
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Collect list of all clients connected to daemon on server @srv.
*
* Returns the number of clients connected to daemon on server @srv -1 in case
* of a failure, setting @clients to NULL. There is a guaranteed extra element
* set to NULL in the @clients list returned to make the iteration easier,
* excluding this extra element from the final count.
* Caller is responsible to call virAdmClientFree() on each list element,
* followed by freeing @clients.
*/
int
virAdmServerListClients(virAdmServerPtr srv,
virAdmClientPtr **clients,
unsigned int flags)
{
int ret = -1;
VIR_DEBUG("srv=%p, clients=%p, flags=%x", srv, clients, flags);
virResetLastError();
virCheckFlagsGoto(0, error);
if (clients)
*clients = NULL;
virCheckAdmServerReturn(srv, -1);
if ((ret = remoteAdminServerListClients(srv, clients, flags)) < 0)
goto error;
return ret;
error:
virDispatchError(NULL);
return -1;
}
......@@ -14,6 +14,8 @@ xdr_admin_connect_lookup_server_ret;
xdr_admin_connect_open_args;
xdr_admin_server_get_threadpool_parameters_args;
xdr_admin_server_get_threadpool_parameters_ret;
xdr_admin_server_list_clients_args;
xdr_admin_server_list_clients_ret;
xdr_admin_server_set_threadpool_parameters_args;
# datatypes.h
......
......@@ -31,4 +31,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmServerFree;
virAdmConnectLookupServer;
virAdmServerSetThreadPoolParameters;
virAdmServerListClients;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册