Just one of the simplest functions that returns string "Clients: X"
where X is the number of connected clients to daemon's first
subserver (the original one), so it can be tested using virsh, ipython,
etc.
The subserver is gathered by incrementing its reference
counter (similarly to getting qemu capabilities), so there is no
deadlock with admin subserver in this API.
Here you can see how functions should be named in the client (virAdm*)
and server (adm*).
There is also a parameter @flags that must be 0, which helps testing
proper error propagation into the client.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
daemon/admin_server.c | 22 ++++++++++++++++++++++
include/libvirt/libvirt-admin.h | 1 +
po/POTFILES.in | 1 +
src/admin/admin_protocol.x | 15 ++++++++++++++-
src/admin_protocol-structs | 9 +++++++++
src/libvirt-admin.c | 26 ++++++++++++++++++++++++++
src/libvirt_admin.syms | 1 +
7 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/daemon/admin_server.c b/daemon/admin_server.c
index 3f0939a..bbbef4d 100644
--- a/daemon/admin_server.c
+++ b/daemon/admin_server.c
@@ -94,4 +94,26 @@ adminDispatchConnectOpen(virNetSubServerPtr subserver
ATTRIBUTE_UNUSED,
return ret;
}
+static char *
+admHello(virNetServerPtr srv,
+ unsigned int flags)
+{
+ char *ret = NULL;
+ virNetSubServerPtr subsrv = NULL;
+ size_t nclients;
+
+ virCheckFlags(0, NULL);
+
+ if (!(subsrv = virNetServerGetSubServer(srv, 0)))
+ return NULL;
+
+ nclients = virNetSubServerGetNClients(subsrv);
+ if (virAsprintf(&ret, "Clients: %zu", nclients) < 0)
+ goto cleanup;
+
+ cleanup:
+ virObjectUnref(subsrv);
+ return ret;
+}
+
#include "admin_dispatch.h"
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 7fe03cf..f1f59b5 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -54,6 +54,7 @@ virAdmConnectPtr virAdmConnectOpen(unsigned int flags);
int virAdmConnectClose(virAdmConnectPtr conn);
int virAdmConnectRef(virAdmConnectPtr conn);
+char *virAdmHello(virAdmConnectPtr conn, unsigned int flags);
# ifdef __cplusplus
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0378166..ae8ba19 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,4 @@
+daemon/admin_dispatch.h
daemon/admin_server.c
daemon/libvirtd-config.c
daemon/libvirtd.c
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index 3e1b28e..f1addaf 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -30,6 +30,14 @@ struct admin_connect_open_args {
unsigned int flags;
};
+struct admin_hello_args {
+ unsigned int flags;
+};
+
+struct admin_hello_ret {
+ remote_string greeting;
+};
+
/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
@@ -56,5 +64,10 @@ enum admin_procedure {
/**
* @generate: none
*/
- ADMIN_PROC_CONNECT_OPEN = 1
+ ADMIN_PROC_CONNECT_OPEN = 1,
+
+ /**
+ * @generate: both
+ */
+ ADMIN_PROC_HELLO = 2
};
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 6b2460d..ed1dd04 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -3,6 +3,15 @@ struct admin_connect_open_args {
unsigned int flags;
};
+struct admin_hello_args {
+ unsigned int flags;
+};
+
+struct admin_hello_ret {
+ remote_string greeting;
+};
+
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
+ ADMIN_PROC_HELLO = 2,
};
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index e47089d..c69753c 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -335,3 +335,29 @@ virAdmConnectRef(virAdmConnectPtr conn)
return 0;
}
+
+
+/**
+ * virAdmHello:
+ * @conn: a connection object
+ * @flags: unused, 0 for now
+ *
+ * Testing function.
+ *
+ * Returns the number of connected clients as a string. Yes, as a
+ * string. Because it's just for testing.
+ */
+char *
+virAdmHello(virAdmConnectPtr conn,
+ unsigned int flags)
+{
+ char *ret = NULL;
+
+ virResetLastError();
+
+ ret = remoteAdminHello(conn, flags);
+ if (!ret)
+ virDispatchError(conn);
+
+ return ret;
+}
diff --git a/src/libvirt_admin.syms b/src/libvirt_admin.syms
index 292433f..d6d2bc3 100644
--- a/src/libvirt_admin.syms
+++ b/src/libvirt_admin.syms
@@ -15,4 +15,5 @@ LIBVIRT_ADMIN_1.2.3 {
virAdmInitialize;
virAdmConnectOpen;
virAdmConnectClose;
+ virAdmHello;
};
--
2.3.5