qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v3 14/18] qemu-img: Use new JSON output formatte


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v3 14/18] qemu-img: Use new JSON output formatter
Date: Mon, 02 May 2016 16:04:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Eric Blake <address@hidden> writes:

> Now that we can pretty-print straight to JSON from a visitor,
> we can eliminate the temporary conversion into QObject inside
> qemu-img.
>
> The changes to qemu-iotests 043 expected output demonstrates
> the fact that output is now done in qapi declaration order,
> rather than QDict hash order.
>
> Signed-off-by: Eric Blake <address@hidden>
>
> ---
> v3: rebase to master
> v2: Drop RFC, adjust expected output of 043; rebase to 'name' motion
>
> Overlaps with Fam's qemu-img edits, although he has expressed
> interest in getting this one in first.
> https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg01756.html
> https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg01806.html
> ---
>  qemu-img.c                 | 69 
> +++++++++++++++++++---------------------------
>  tests/qemu-iotests/043.out | 22 +++++++--------
>  2 files changed, 40 insertions(+), 51 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index e976851..7bc3610 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -24,9 +24,9 @@
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
>  #include "qapi-visit.h"
> -#include "qapi/qmp-output-visitor.h"
> +#include "qapi/json-output-visitor.h"
>  #include "qapi/qmp/qerror.h"
> -#include "qapi/qmp/qobject-json.h"
> +#include "qapi/qmp/types.h"
>  #include "qemu/cutils.h"
>  #include "qemu/config-file.h"
>  #include "qemu/option.h"
> @@ -479,19 +479,15 @@ fail:
>
>  static void dump_json_image_check(ImageCheck *check, bool quiet)
>  {
> -    Error *local_err = NULL;
> -    QString *str;
> -    QmpOutputVisitor *ov = qmp_output_visitor_new();
> -    QObject *obj;
> -    visit_type_ImageCheck(qmp_output_get_visitor(ov), NULL, &check,
> -                          &local_err);
> -    obj = qmp_output_get_qobject(ov);
> -    str = qobject_to_json_pretty(obj);
> -    assert(str != NULL);
> -    qprintf(quiet, "%s\n", qstring_get_str(str));
> -    qobject_decref(obj);
> -    qmp_output_visitor_cleanup(ov);
> -    QDECREF(str);
> +    char *str;
> +    JsonOutputVisitor *ov = json_output_visitor_new(true);

Blank line between declarations and statements, please.  More of the
same below.

> +    visit_type_ImageCheck(json_output_get_visitor(ov), NULL,
> +                          &check, &error_abort);

Silent bug fix: if visit_type_ImageCheck() fails, we now abort instead
of leaking the error object.  Separate patch or mention in the commit
message.

> +    str = json_output_get_string(ov);
> +    assert(str);

Can json_output_get_string() legitimately return null?

If no, shouldn't the assertion live there rather than here?

> +    qprintf(quiet, "%s\n", str);
> +    g_free(str);
> +    json_output_visitor_cleanup(ov);
>  }
>
>  static void dump_human_image_check(ImageCheck *check, bool quiet)
> @@ -2152,35 +2148,28 @@ static void dump_snapshots(BlockDriverState *bs)
>
>  static void dump_json_image_info_list(ImageInfoList *list)
>  {
> -    Error *local_err = NULL;
> -    QString *str;
> -    QmpOutputVisitor *ov = qmp_output_visitor_new();
> -    QObject *obj;
> -    visit_type_ImageInfoList(qmp_output_get_visitor(ov), NULL, &list,
> -                             &local_err);
> -    obj = qmp_output_get_qobject(ov);
> -    str = qobject_to_json_pretty(obj);
> -    assert(str != NULL);
> -    printf("%s\n", qstring_get_str(str));
> -    qobject_decref(obj);
> -    qmp_output_visitor_cleanup(ov);
> -    QDECREF(str);
> +    char *str;
> +    JsonOutputVisitor *ov = json_output_visitor_new(true);
> +    visit_type_ImageInfoList(json_output_get_visitor(ov), NULL,
> +                             &list, &error_abort);
> +    str = json_output_get_string(ov);
> +    assert(str);
> +    printf("%s\n", str);
> +    json_output_visitor_cleanup(ov);
> +    g_free(str);
>  }
>
>  static void dump_json_image_info(ImageInfo *info)
>  {
> -    Error *local_err = NULL;
> -    QString *str;
> -    QmpOutputVisitor *ov = qmp_output_visitor_new();
> -    QObject *obj;
> -    visit_type_ImageInfo(qmp_output_get_visitor(ov), NULL, &info, 
> &local_err);
> -    obj = qmp_output_get_qobject(ov);
> -    str = qobject_to_json_pretty(obj);
> -    assert(str != NULL);
> -    printf("%s\n", qstring_get_str(str));
> -    qobject_decref(obj);
> -    qmp_output_visitor_cleanup(ov);
> -    QDECREF(str);
> +    char *str;
> +    JsonOutputVisitor *ov = json_output_visitor_new(true);
> +    visit_type_ImageInfo(json_output_get_visitor(ov), NULL, &info,
> +                         &error_abort);
> +    str = json_output_get_string(ov);
> +    assert(str);
> +    printf("%s\n", str);
> +    json_output_visitor_cleanup(ov);
> +    g_free(str);
>  }
>
>  static void dump_human_image_info_list(ImageInfoList *list)
> diff --git a/tests/qemu-iotests/043.out b/tests/qemu-iotests/043.out
> index b37d2a3..41697a2 100644
> --- a/tests/qemu-iotests/043.out
> +++ b/tests/qemu-iotests/043.out
> @@ -40,29 +40,29 @@ cluster_size: 65536
>  == finite chain of length 3 (json) ==
>  [
>      {
> -        "virtual-size": 134217728,
>          "filename": "TEST_DIR/t.IMGFMT",
> -        "cluster-size": 65536,
>          "format": "IMGFMT",
> -        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
> +        "dirty-flag": false,
> +        "virtual-size": 134217728,
> +        "cluster-size": 65536,
>          "backing-filename": "TEST_DIR/t.IMGFMT.2.base",
> -        "dirty-flag": false
> +        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
>      },
>      {
> -        "virtual-size": 134217728,
>          "filename": "TEST_DIR/t.IMGFMT.2.base",
> -        "cluster-size": 65536,
>          "format": "IMGFMT",
> -        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
> +        "dirty-flag": false,
> +        "virtual-size": 134217728,
> +        "cluster-size": 65536,
>          "backing-filename": "TEST_DIR/t.IMGFMT.1.base",
> -        "dirty-flag": false
> +        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
>      },
>      {
> -        "virtual-size": 134217728,
>          "filename": "TEST_DIR/t.IMGFMT.1.base",
> -        "cluster-size": 65536,
>          "format": "IMGFMT",
> -        "dirty-flag": false
> +        "dirty-flag": false,
> +        "virtual-size": 134217728,
> +        "cluster-size": 65536,
>      }
>  ]
>  *** done



reply via email to

[Prev in Thread] Current Thread [Next in Thread]