mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +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)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char **srv_names = NULL;
|
|
||||||
virNetServerPtr *srvs = NULL;
|
virNetServerPtr *srvs = NULL;
|
||||||
size_t i;
|
|
||||||
ssize_t nsrvs = 0;
|
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if ((nsrvs = virNetDaemonGetServerNames(dmn, &srv_names)) < 0)
|
if ((ret = virNetDaemonGetServers(dmn, &srvs)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (servers) {
|
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;
|
*servers = srvs;
|
||||||
srvs = NULL;
|
srvs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = nsrvs;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(srv_names);
|
|
||||||
virObjectListFree(srvs);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ virNetDaemonAddSignalHandler;
|
|||||||
virNetDaemonAutoShutdown;
|
virNetDaemonAutoShutdown;
|
||||||
virNetDaemonClose;
|
virNetDaemonClose;
|
||||||
virNetDaemonGetServer;
|
virNetDaemonGetServer;
|
||||||
|
virNetDaemonGetServers;
|
||||||
virNetDaemonHasClients;
|
virNetDaemonHasClients;
|
||||||
virNetDaemonIsPrivileged;
|
virNetDaemonIsPrivileged;
|
||||||
virNetDaemonNew;
|
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
|
* Returns number of names allocated in *servers, on error sets
|
||||||
* *servers to NULL and returns -1. List of *servers must be free()d,
|
* *servers to NULL and returns -1. List of *servers must be free()d,
|
||||||
* but not the items in it (similarly to virHashGetItems).
|
* but not the items in it (similarly to virHashGetItems).
|
||||||
*/
|
*/
|
||||||
ssize_t
|
ssize_t
|
||||||
virNetDaemonGetServerNames(virNetDaemonPtr dmn,
|
virNetDaemonGetServers(virNetDaemonPtr dmn,
|
||||||
const char ***servers)
|
virNetServerPtr **servers)
|
||||||
{
|
{
|
||||||
virHashKeyValuePairPtr items = NULL;
|
struct collectData data = { servers, 0 };
|
||||||
size_t nservers = 0;
|
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
*servers = NULL;
|
*servers = NULL;
|
||||||
|
|
||||||
virObjectLock(dmn);
|
virObjectLock(dmn);
|
||||||
|
|
||||||
items = virHashGetItems(dmn->servers, NULL);
|
if (virHashForEach(dmn->servers, collectServers, &data) < 0) {
|
||||||
if (!items)
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
goto cleanup;
|
_("Cannot get all servers from daemon"));
|
||||||
|
|
||||||
for (i = 0; items[i].key; i++) {
|
|
||||||
if (VIR_APPEND_ELEMENT(*servers, nservers, items[i].key) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = nservers;
|
ret = data.nservers;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
VIR_FREE(*servers);
|
virObjectListFreeCount(*servers, data.nservers);
|
||||||
VIR_FREE(items);
|
|
||||||
virObjectUnlock(dmn);
|
virObjectUnlock(dmn);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,6 @@ bool virNetDaemonHasClients(virNetDaemonPtr dmn);
|
|||||||
|
|
||||||
virNetServerPtr virNetDaemonGetServer(virNetDaemonPtr dmn,
|
virNetServerPtr virNetDaemonGetServer(virNetDaemonPtr dmn,
|
||||||
const char *serverName);
|
const char *serverName);
|
||||||
ssize_t virNetDaemonGetServerNames(virNetDaemonPtr dmn, const char ***servers);
|
ssize_t virNetDaemonGetServers(virNetDaemonPtr dmn, virNetServerPtr **servers);
|
||||||
|
|
||||||
#endif /* __VIR_NET_DAEMON_H__ */
|
#endif /* __VIR_NET_DAEMON_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user