mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 00:45:18 +00:00
admin: Introduce virAdmClientClose API
Once we're able to list and identify all clients connected to a specific server, we can then support force-closing a connection. This patch introduces a simple API calling virNetServerClientClose on a specific client, which can be later extended easily, e.g. by sending an event once the client is disconnected successfully. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
37675f6b66
commit
c22ac618b5
@ -94,6 +94,12 @@ make_nonnull_server(admin_nonnull_server *srv_dst,
|
||||
ignore_value(VIR_STRDUP_QUIET(srv_dst->name, virNetServerGetName(srv_src)));
|
||||
}
|
||||
|
||||
static virNetServerClientPtr
|
||||
get_nonnull_client(virNetServerPtr srv, admin_nonnull_client clnt)
|
||||
{
|
||||
return virNetServerGetClient(srv, clnt.id);
|
||||
}
|
||||
|
||||
static void
|
||||
make_nonnull_client(admin_nonnull_client *clt_dst,
|
||||
virNetServerClientPtr clt_src)
|
||||
|
@ -302,3 +302,12 @@ adminClientGetInfo(virNetServerClientPtr client,
|
||||
virObjectUnref(identity);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int adminClientClose(virNetServerClientPtr client,
|
||||
unsigned int flags)
|
||||
{
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
virNetServerClientClose(client);
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,4 +59,7 @@ int adminClientGetInfo(virNetServerClientPtr client,
|
||||
int *nparams,
|
||||
unsigned int flags);
|
||||
|
||||
int adminClientClose(virNetServerClientPtr client,
|
||||
unsigned int flags);
|
||||
|
||||
#endif /* __LIBVIRTD_ADMIN_SERVER_H__ */
|
||||
|
@ -349,6 +349,8 @@ int virAdmClientGetInfo(virAdmClientPtr client,
|
||||
int *nparams,
|
||||
unsigned int flags);
|
||||
|
||||
int virAdmClientClose(virAdmClientPtr client, unsigned int flags);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
@ -160,6 +160,11 @@ struct admin_client_get_info_ret { /* insert@1 */
|
||||
admin_typed_param params<ADMIN_CLIENT_INFO_PARAMETERS_MAX>;
|
||||
};
|
||||
|
||||
struct admin_client_close_args {
|
||||
admin_nonnull_client clnt;
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
/* Define the program number, protocol version and procedure numbers here. */
|
||||
const ADMIN_PROGRAM = 0x06900690;
|
||||
const ADMIN_PROTOCOL_VERSION = 1;
|
||||
@ -230,5 +235,10 @@ enum admin_procedure {
|
||||
/**
|
||||
* @generate: none
|
||||
*/
|
||||
ADMIN_PROC_CLIENT_GET_INFO = 10
|
||||
ADMIN_PROC_CLIENT_GET_INFO = 10,
|
||||
|
||||
/**
|
||||
* @generate: both
|
||||
*/
|
||||
ADMIN_PROC_CLIENT_CLOSE = 11
|
||||
};
|
||||
|
@ -105,6 +105,10 @@ struct admin_client_get_info_ret {
|
||||
admin_typed_param * params_val;
|
||||
} params;
|
||||
};
|
||||
struct admin_client_close_args {
|
||||
admin_nonnull_client clnt;
|
||||
u_int flags;
|
||||
};
|
||||
enum admin_procedure {
|
||||
ADMIN_PROC_CONNECT_OPEN = 1,
|
||||
ADMIN_PROC_CONNECT_CLOSE = 2,
|
||||
@ -116,4 +120,5 @@ enum admin_procedure {
|
||||
ADMIN_PROC_SERVER_LIST_CLIENTS = 8,
|
||||
ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9,
|
||||
ADMIN_PROC_CLIENT_GET_INFO = 10,
|
||||
ADMIN_PROC_CLIENT_CLOSE = 11,
|
||||
};
|
||||
|
@ -971,3 +971,32 @@ virAdmClientGetInfo(virAdmClientPtr client,
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virAdmClientClose:
|
||||
* @client: a valid client object reference
|
||||
* @flags: extra flags; not used yet, so callers should always pass 0
|
||||
*
|
||||
* Close @client's connection to daemon forcefully.
|
||||
*
|
||||
* Returns 0 if the daemon's connection with @client was closed successfully
|
||||
* or -1 in case of an error.
|
||||
*/
|
||||
int virAdmClientClose(virAdmClientPtr client,
|
||||
unsigned int flags)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
VIR_DEBUG("client=%p, flags=%x", client, flags);
|
||||
virResetLastError();
|
||||
|
||||
virCheckAdmClientGoto(client, error);
|
||||
|
||||
if ((ret = remoteAdminClientClose(client, flags)) < 0)
|
||||
goto error;
|
||||
|
||||
return ret;
|
||||
error:
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#
|
||||
|
||||
# admin/admin_protocol.x
|
||||
xdr_admin_client_close_args;
|
||||
xdr_admin_client_get_info_args;
|
||||
xdr_admin_client_get_info_ret;
|
||||
xdr_admin_connect_get_lib_version_ret;
|
||||
|
@ -34,4 +34,5 @@ LIBVIRT_ADMIN_1.3.0 {
|
||||
virAdmServerSetThreadPoolParameters;
|
||||
virAdmServerListClients;
|
||||
virAdmClientGetInfo;
|
||||
virAdmClientClose;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user