mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 11:01:19 +00:00
Change virNetDaemonGetServerNames to virNetDaemonGetServers
For now it does not matter which ones we return as the code is similarly complex, however it will fit in with other constructs in the future, mainly when we will be able to generate dispatch helpers. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
a0dbed6160
commit
d4218ca64f
@ -42,33 +42,17 @@ adminDaemonListServers(virNetDaemonPtr dmn,
|
||||
unsigned int flags)
|
||||
{
|
||||
int ret = -1;
|
||||
const char **srv_names = NULL;
|
||||
virNetServerPtr *srvs = NULL;
|
||||
size_t i;
|
||||
ssize_t nsrvs = 0;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
if ((nsrvs = virNetDaemonGetServerNames(dmn, &srv_names)) < 0)
|
||||
if ((ret = virNetDaemonGetServers(dmn, &srvs)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (servers) {
|
||||
if (VIR_ALLOC_N(srvs, nsrvs) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < nsrvs; i++) {
|
||||
if (!(srvs[i] = virNetDaemonGetServer(dmn, srv_names[i])))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*servers = srvs;
|
||||
srvs = NULL;
|
||||
}
|
||||
|
||||
ret = nsrvs;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(srv_names);
|
||||
virObjectListFree(srvs);
|
||||
return ret;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ virNetDaemonAddSignalHandler;
|
||||
virNetDaemonAutoShutdown;
|
||||
virNetDaemonClose;
|
||||
virNetDaemonGetServer;
|
||||
virNetDaemonGetServers;
|
||||
virNetDaemonHasClients;
|
||||
virNetDaemonIsPrivileged;
|
||||
virNetDaemonNew;
|
||||
|
@ -196,39 +196,54 @@ virNetDaemonGetServer(virNetDaemonPtr dmn,
|
||||
}
|
||||
|
||||
|
||||
struct collectData {
|
||||
virNetServerPtr **servers;
|
||||
size_t nservers;
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
collectServers(void *payload,
|
||||
const void *name ATTRIBUTE_UNUSED,
|
||||
void *opaque)
|
||||
{
|
||||
virNetServerPtr srv = virObjectRef(payload);
|
||||
struct collectData *data = opaque;
|
||||
|
||||
if (!srv)
|
||||
return -1;
|
||||
|
||||
return VIR_APPEND_ELEMENT(*data->servers, data->nservers, srv);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns number of names allocated in *servers, on error sets
|
||||
* *servers to NULL and returns -1. List of *servers must be free()d,
|
||||
* but not the items in it (similarly to virHashGetItems).
|
||||
*/
|
||||
ssize_t
|
||||
virNetDaemonGetServerNames(virNetDaemonPtr dmn,
|
||||
const char ***servers)
|
||||
virNetDaemonGetServers(virNetDaemonPtr dmn,
|
||||
virNetServerPtr **servers)
|
||||
{
|
||||
virHashKeyValuePairPtr items = NULL;
|
||||
size_t nservers = 0;
|
||||
struct collectData data = { servers, 0 };
|
||||
ssize_t ret = -1;
|
||||
size_t i;
|
||||
|
||||
*servers = NULL;
|
||||
|
||||
virObjectLock(dmn);
|
||||
|
||||
items = virHashGetItems(dmn->servers, NULL);
|
||||
if (!items)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; items[i].key; i++) {
|
||||
if (VIR_APPEND_ELEMENT(*servers, nservers, items[i].key) < 0)
|
||||
if (virHashForEach(dmn->servers, collectServers, &data) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Cannot get all servers from daemon"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = nservers;
|
||||
ret = data.nservers;
|
||||
|
||||
cleanup:
|
||||
if (ret < 0)
|
||||
VIR_FREE(*servers);
|
||||
VIR_FREE(items);
|
||||
virObjectListFreeCount(*servers, data.nservers);
|
||||
virObjectUnlock(dmn);
|
||||
return ret;
|
||||
}
|
||||
|
@ -82,6 +82,6 @@ bool virNetDaemonHasClients(virNetDaemonPtr dmn);
|
||||
|
||||
virNetServerPtr virNetDaemonGetServer(virNetDaemonPtr dmn,
|
||||
const char *serverName);
|
||||
ssize_t virNetDaemonGetServerNames(virNetDaemonPtr dmn, const char ***servers);
|
||||
ssize_t virNetDaemonGetServers(virNetDaemonPtr dmn, virNetServerPtr **servers);
|
||||
|
||||
#endif /* __VIR_NET_DAEMON_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user