提交 04bab54d 编写于 作者: E Erik Skultety

rpc: virnetserver: Support retrieval of a list of clients

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: NErik Skultety <eskultet@redhat.com>
上级 4bd43074
......@@ -101,6 +101,7 @@ virNetServerAddClient;
virNetServerAddProgram;
virNetServerAddService;
virNetServerClose;
virNetServerGetClients;
virNetServerGetName;
virNetServerHasClients;
virNetServerNew;
......
......@@ -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;
}
......@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册