Re: [PATCH] tools: virsh: Add virshCellnoCompleter.

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

 



On 05/25/2018 09:12 AM, Roland Schulz wrote:
> Signed-off-by: Roland Schulz <schullzroll@xxxxxxxxx>
> ---
>  tools/virsh-completer.c | 59 +++++++++++++++++++++++++++++++++++++++++
>  tools/virsh-completer.h |  3 +++
>  tools/virsh-host.c      |  3 +++
>  3 files changed, 65 insertions(+)
> 
> diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
> index 5713a887e..ce152226f 100644
> --- a/tools/virsh-completer.c
> +++ b/tools/virsh-completer.c
> @@ -756,3 +756,62 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
>      virStringListFree(ret);
>      return NULL;
>  }
> +
> +
> +char **
> +virshCellnoCompleter(vshControl *ctl,
> +                     const vshCmd *cmd ATTRIBUTE_UNUSED,
> +                     unsigned int flags)
> +{
> +    xmlXPathContextPtr ctxt = NULL;
> +    virshControlPtr priv = ctl->privData;
> +    unsigned int ncells = 0;
> +    xmlNodePtr *cells = NULL;
> +    xmlDocPtr doc = NULL;
> +    size_t i = 0;
> +    char *cap_xml = NULL;
> +    char *cellid = NULL;
> +    char **ret = NULL;
> +
> +    virCheckFlags(0, NULL);
> +
> +    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
> +        goto error;
> +
> +    if (!(cap_xml = virConnectGetCapabilities(priv->conn)))
> +        goto error;
> +
> +    if (!(doc = virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)))
> +        goto error;
> +
> +    ncells = virXPathNodeSet("/capabilities/host/topology/cells/cell", ctxt, &cells);
> +    if (ncells <= 0)
> +        goto error;
> +
> +    if (VIR_ALLOC_N(ret, ncells + 1))
> +        goto error;
> +
> +    for (i = 0; i < ncells; i++) {
> +        VIR_FREE(cellid);
> +        cellid = virXMLPropString(cells[i], "id");
> +        if (VIR_STRDUP(ret[i], cellid) < 0)

The virXMLPropString() already returns a dynamically allocated string
(that's why you call VIR_FREE(cellid)). There's not much value added in
duplicating the string again. What you can do is assign the returned
value to ret[i] directly:

for (i = 0; i < ncells; i++) {
  if (!(ret[i] = virXMLPropString(cells[i], "id")))
    goto error;
}

This way @cellid variable is needless.

> +            goto error;
> +    }
> +
> + cleanup:
> +    xmlXPathFreeContext(ctxt);
> +    VIR_FREE(cells);
> +    xmlFreeDoc(doc);
> +    VIR_FREE(cap_xml);
> +    VIR_FREE(cellid);
> +
> +    return ret;
> +
> + error:
> +    if (ret) {
> +        for (i = 0; i < ncells; i++)
> +            VIR_FREE(ret[i]);
> +    }
> +    VIR_FREE(ret);
> +    goto cleanup;
> +}

I'm fixing that, ACKing and pushing.

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux