For now, the list copy is done simply by locking the whole server, walking the
original and increasing the refcount on each object. We may want to change
the list to a lockable object (like list of domains) later in the future if
we discover some performance issues related to locking the whole server in
order to walk the whole list of clients, possibly issuing some 'ForEach'
callback.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
src/libvirt_remote.syms | 1 +
src/rpc/virnetserver.c | 29 +++++++++++++++++++++++++++++
src/rpc/virnetserver.h | 3 +++
3 files changed, 33 insertions(+)
diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index c049874..ea92043 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -101,6 +101,7 @@ virNetServerAddClient;
virNetServerAddProgram;
virNetServerAddService;
virNetServerClose;
+virNetServerGetClients;
virNetServerGetName;
virNetServerHasClients;
virNetServerNew;
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 8216da6..fcc79f4 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -943,3 +943,32 @@ virNetServerSetThreadPoolParameters(virNetServerPtr srv,
virObjectUnlock(srv);
return ret;
}
+
+int
+virNetServerGetClients(virNetServerPtr srv,
+ virNetServerClientPtr **clts)
+{
+ int ret = -1;
+ size_t i;
+ size_t nclients = 0;
+ virNetServerClientPtr *list = NULL;
+
+ virObjectLock(srv);
+
+ for (i = 0; i < srv->nclients; i++) {
+ virNetServerClientPtr client = virObjectRef(srv->clients[i]);
+ if (VIR_APPEND_ELEMENT(list, nclients, client) < 0) {
+ virObjectUnref(client);
+ goto cleanup;
+ }
+ }
+
+ *clts = list;
+ list = NULL;
+ ret = nclients;
+
+ cleanup:
+ virObjectListFreeCount(list, nclients);
+ virObjectUnlock(srv);
+ return ret;
+}
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index 2ae89ce..f5bb200 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -105,4 +105,7 @@ int virNetServerSetThreadPoolParameters(virNetServerPtr srv,
unsigned long long virNetServerNextClientID(virNetServerPtr srv);
+int virNetServerGetClients(virNetServerPtr srv,
+ virNetServerClientPtr **clients);
+
#endif /* __VIR_NET_SERVER_H__ */
--
2.4.11