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(a)redhat.com>
---
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_protocol-structs | 5 +++++
src/libvirt-admin.c | 30 ++++++++++++++++++++++++++++++
src/libvirt_admin_private.syms | 1 +
src/libvirt_admin_public.syms | 1 +
9 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/daemon/admin.c b/daemon/admin.c
index 3de09ca..5fa906f 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 2fc4675..93a463a 100644
--- a/daemon/admin_server.c
+++ b/daemon/admin_server.c
@@ -303,3 +303,12 @@ adminClientGetInfo(virNetServerClientPtr client,
virObjectUnref(identity);
return ret;
}
+
+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 95c76b9..2953e10 100644
--- a/daemon/admin_server.h
+++ b/daemon/admin_server.h
@@ -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__ */
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 0a1ea61..4e6074e 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -349,6 +349,8 @@ int virAdmClientGetInfo(virAdmClientPtr client,
int *nparams,
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 67bdbf3..1da7f90 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -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
};
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index ea9adf6..b4db415 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -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,
};
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 4ad816b..4c86dd7 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -976,3 +976,33 @@ 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);
+ 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 affe8c1..e55b91e 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_client_get_info_args;
xdr_admin_client_get_info_ret;
xdr_admin_connect_get_lib_version_ret;
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index 27e4a1d..57df1f4 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -34,4 +34,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmServerSetThreadPoolParameters;
virAdmServerListClients;
virAdmClientGetInfo;
+ virAdmClientClose;
};
--
2.4.11