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@xxxxxxxxxx> --- daemon/admin.c | 6 ++++++ daemon/admin_server.c | 9 +++++++++ daemon/admin_server.h | 3 +++ include/libvirt/libvirt-admin.h | 2 ++ src/admin/admin_protocol.x | 12 +++++++++++- src/admin/admin_remote.c | 10 ++++++++++ src/admin_protocol-structs | 5 +++++ src/libvirt-admin.c | 30 ++++++++++++++++++++++++++++++ src/libvirt_admin_private.syms | 1 + src/libvirt_admin_public.syms | 1 + 10 files changed, 78 insertions(+), 1 deletion(-) diff --git a/daemon/admin.c b/daemon/admin.c index fcbdee5..fe797a6 100644 --- a/daemon/admin.c +++ b/daemon/admin.c @@ -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) diff --git a/daemon/admin_server.c b/daemon/admin_server.c index 9ea1164..c555d6d 100644 --- a/daemon/admin_server.c +++ b/daemon/admin_server.c @@ -211,3 +211,12 @@ adminServerLookupClient(virNetServerPtr srv, return virNetServerGetClient(srv, id); } + +int adminClientClose(virNetServerClientPtr client, + unsigned int flags) +{ + virCheckFlags(0, -1); + + virNetServerClientClose(client); + return 0; +} diff --git a/daemon/admin_server.h b/daemon/admin_server.h index a593251..1ac98a4 100644 --- a/daemon/admin_server.h +++ b/daemon/admin_server.h @@ -54,4 +54,7 @@ virNetServerClientPtr adminServerLookupClient(virNetServerPtr srv, unsigned long long id, unsigned int flags); +int adminClientClose(virNetServerClientPtr client, + unsigned int flags); + #endif /* __LIBVIRTD_ADMIN_SERVER_H__ */ diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h index e51f2ba..4a58638 100644 --- a/include/libvirt/libvirt-admin.h +++ b/include/libvirt/libvirt-admin.h @@ -224,6 +224,8 @@ virAdmServerLookupClient(virAdmServerPtr srv, unsigned long long id, unsigned int flags); +int virAdmClientClose(virAdmClientPtr client, unsigned int flags); + # ifdef __cplusplus } # endif diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x index da21db8..d639b1a 100644 --- a/src/admin/admin_protocol.x +++ b/src/admin/admin_protocol.x @@ -148,6 +148,11 @@ struct admin_server_lookup_client_ret { admin_nonnull_client clnt; }; +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; @@ -213,5 +218,10 @@ enum admin_procedure { /** * @generate: both */ - ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9 + ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9, + + /** + * @generate: both + */ + ADMIN_PROC_CLIENT_CLOSE = 10 }; diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c index b833ea4..04906d6 100644 --- a/src/admin/admin_remote.c +++ b/src/admin/admin_remote.c @@ -67,6 +67,16 @@ make_nonnull_server(admin_nonnull_server *srv_dst, virAdmServerPtr srv_src) srv_dst->name = srv_src->name; } +static void +make_nonnull_client(admin_nonnull_client *client_dst, + virAdmClientPtr client_src) +{ + client_dst->id = client_src->id; + client_dst->transport = client_src->transport; + client_dst->timestamp = client_src->timestamp; + make_nonnull_server(&client_dst->srv, client_src->srv); +} + static int callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED, remoteAdminPrivPtr priv, diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs index dc2220e..5f44b76 100644 --- a/src/admin_protocol-structs +++ b/src/admin_protocol-structs @@ -95,6 +95,10 @@ struct admin_server_lookup_client_args { struct admin_server_lookup_client_ret { admin_nonnull_client clnt; }; +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, @@ -105,4 +109,5 @@ enum admin_procedure { ADMIN_PROC_SERVER_SET_THREADPOOL_PARAMETERS = 7, ADMIN_PROC_SERVER_LIST_CLIENTS = 8, ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9, + ADMIN_PROC_CLIENT_CLOSE = 10, }; diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index 5d0755f..a06c5d9 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -925,3 +925,33 @@ virAdmServerLookupClient(virAdmServerPtr srv, virDispatchError(NULL); return NULL; } + +/** + * 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); + virCheckFlagsGoto(0, error); + + if ((ret = remoteAdminClientClose(client, 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 3d7ecbc..ec4cf39 100644 --- a/src/libvirt_admin_private.syms +++ b/src/libvirt_admin_private.syms @@ -6,6 +6,7 @@ # # admin/admin_protocol.x +xdr_admin_client_close_args; xdr_admin_connect_get_lib_version_ret; xdr_admin_connect_list_servers_args; xdr_admin_connect_list_servers_ret; diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms index 066ae0c..4ee4c65 100644 --- a/src/libvirt_admin_public.syms +++ b/src/libvirt_admin_public.syms @@ -33,4 +33,5 @@ LIBVIRT_ADMIN_1.3.0 { virAdmConnectLookupServer; virAdmServerSetThreadPoolParameters; virAdmServerListClients; + virAdmClientClose; }; -- 2.4.11 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list