Re: [PATCH 4/9] util: json: Don't remove the 'file' subobject when deflattening

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

 




On 06/27/2017 08:46 AM, Peter Krempa wrote:
> Currently the function would deflatten the object by dropping the 'file'
> prefix from the attributes. This does not really scale well or adhere to
> the documentation.
> 
> Until we refactor the worker to properly deflatten everything we at
> least simulate it by adding the "file" wrapper object back.
> ---
>  src/util/virjson.c        | 19 +++++++++++++------
>  src/util/virstoragefile.c |  8 +++++++-
>  2 files changed, 20 insertions(+), 7 deletions(-)
> 
> diff --git a/src/util/virjson.c b/src/util/virjson.c
> index 8ab542432..a8e28cd1b 100644
> --- a/src/util/virjson.c
> +++ b/src/util/virjson.c
> @@ -2012,17 +2012,24 @@ virJSONValueObjectDeflattenWorker(const char *key,
>  virJSONValuePtr
>  virJSONValueObjectDeflatten(virJSONValuePtr json)
>  {
> -    virJSONValuePtr ret;
> +    virJSONValuePtr deflattened;
> +    virJSONValuePtr ret = NULL;
> 
> -    if (!(ret = virJSONValueNewObject()))
> +    if (!(deflattened = virJSONValueNewObject()))
>          return NULL;
> 
>      if (virJSONValueObjectForeachKeyValue(json,
>                                            virJSONValueObjectDeflattenWorker,
> -                                          ret) < 0) {
> -        virJSONValueFree(ret);
> -        return NULL;
> -    }
> +                                          deflattened) < 0)
> +        goto cleanup;
> +
> +    if (virJSONValueObjectCreate(&ret, "a:file", deflattened, NULL) < 0)
> +        goto cleanup;
> +
> +    deflattened = NULL;
> +
> + cleanup:
> +    virJSONValueFree(deflattened);
> 
>      return ret;
>  }
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 52c5301ff..d24502fbf 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -3260,7 +3260,13 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
>          if (!(fixedroot = virJSONValueObjectDeflatten(json)))
>              goto cleanup;
> 
> -        file = fixedroot;
> +        if (!(file = virJSONValueObjectGetObject(fixedroot, "file"))) {
> +            str = virJSONValueToString(json, false);
> +            virReportError(VIR_ERR_INVALID_ARG,
> +                _("JSON backing volume defintion '%s' lacks 'file' object"),
> +                str);

Not aligned properly under VIR_ERR_INVALID_ARG

Similar to driver below, this should be NULLSTR(str);

Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx>

John

> +            goto cleanup;
> +        }
>      }
> 
>      if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
> 

--
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