[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 10/21] Change virNetDaemonGetServerNames to virNetDaemonGetServers



On Thu, Mar 10, 2016 at 05:53:59AM +0100, Martin Kletzander wrote:
> 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>
> ---
>  daemon/admin_server.c   | 18 +-----------------
>  src/libvirt_remote.syms |  1 +
>  src/rpc/virnetdaemon.c  | 43 +++++++++++++++++++++++++++++--------------
>  src/rpc/virnetdaemon.h  |  2 +-
>  4 files changed, 32 insertions(+), 32 deletions(-)

>  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)
> +    if (virHashForEach(dmn->servers, collectServers, &data) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("Cannot get all servers from daemon"));
>          goto cleanup;
> -
> -    for (i = 0; items[i].key; i++) {
> -        if (VIR_APPEND_ELEMENT(*servers, nservers, items[i].key) < 0)
> -            goto cleanup;
>      }
> 
> -    ret = nservers;
> +    ret = data.nservers;
> 
>   cleanup:
>      if (ret < 0)
> -        VIR_FREE(*servers);
> -    VIR_FREE(items);
> +        virObjectListFree(*servers);

This should be virObjectListFreeCount, since the array is no longer
allocated upfront.

ACK with that fixed.

Jan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]