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

Re: [libvirt] [PATCH 1/2] util: storage: split function for JSON backing volume parsing in two



On Mon, Feb 13, 2017 at 23:53:42 +0100, Tomáš Golembiovský wrote:
> Split virStorageSourceParseBackingJSON into two functions so that the
> core can be reused by other functions. The new function called
> virStorageSourceParseBackingJSONInternal accepts virJSONValuePtr.
> 
> Signed-off-by: Tomáš Golembiovský <tgolembi redhat com>
> ---
>  src/util/virstoragefile.c | 35 +++++++++++++++++++++++++----------
>  1 file changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 3d4bda700..3698eeeda 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -3053,29 +3053,28 @@ virStorageSourceParseBackingJSONDeflatten(virJSONValuePtr json)
>  
>  
>  static int
> -virStorageSourceParseBackingJSON(virStorageSourcePtr src,
> -                                 const char *json)
> +virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
> +                                         virJSONValuePtr json)
>  {
> -    virJSONValuePtr root = NULL;
>      virJSONValuePtr fixedroot = NULL;
>      virJSONValuePtr file;
>      const char *drvname;
>      size_t i;
>      int ret = -1;
>  
> -    if (!(root = virJSONValueFromString(json)))
> -        return -1;
> -
> -    if (!(file = virJSONValueObjectGetObject(root, "file"))) {
> -        if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(root)))
> +    if (!(file = virJSONValueObjectGetObject(json, "file"))) {
> +        if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(json)))
>              goto cleanup;
>  
>          file = fixedroot;
>      }
>  
>      if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
> +        char *str = virJSONValueToString(json, false);

We usually declare variables at the top.

>          virReportError(VIR_ERR_INVALID_ARG, _("JSON backing volume defintion "
> -                                              "'%s' lacks driver name"), json);
> +                                              "'%s' lacks driver name"),
> +            NULLSTR(str));

Broken formatting.

> +        VIR_FREE(str);
>          goto cleanup;
>      }
>  
> @@ -3091,12 +3090,28 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
>                       "driver '%s'"), drvname);
>  
>   cleanup:
> -    virJSONValueFree(root);
>      virJSONValueFree(fixedroot);
>      return ret;
>  }
>  
>  
> +static int
> +virStorageSourceParseBackingJSON(virStorageSourcePtr src,
> +                                 const char *json)
> +{
> +    virJSONValuePtr root = NULL;
> +    int ret = -1;
> +
> +    if (!(root = virJSONValueFromString(json)))
> +        return -1;
> +
> +    ret = virStorageSourceParseBackingJSONInternal(src, root);
> +
> +    virJSONValueFree(root);
> +    return ret;
> +}
> +
> +
>  virStorageSourcePtr
>  virStorageSourceNewFromBackingAbsolute(const char *path)
>  {

ACK, I'll fix the stuff pointed out prior to pushing.

Attachment: signature.asc
Description: PGP signature


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