All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, Kevin Wolf <kwolf@redhat.com>,
	Max Reitz <mreitz@redhat.com>,
	"open list:Block layer core" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PATCH v6 15/15] qemu-img: Use new JSON output formatter
Date: Mon, 10 Oct 2016 08:23:57 -0500	[thread overview]
Message-ID: <1476105837-9861-16-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1476105837-9861-1-git-send-email-eblake@redhat.com>

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 <eblake@redhat.com>

---
v6: rebase
[no v5 due to series split]
v4: rebase to earlier changes
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                 | 43 +++++++++++++++++--------------------------
 tests/qemu-iotests/043.out | 22 +++++++++++-----------
 2 files changed, 28 insertions(+), 37 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 626781d..97a5401 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -25,9 +25,9 @@
 #include "qemu-version.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/qjson.h"
+#include "qapi/qmp/types.h"
 #include "qemu/cutils.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
@@ -498,17 +498,14 @@ fail:

 static void dump_json_image_check(ImageCheck *check, bool quiet)
 {
-    QString *str;
-    QObject *obj;
-    Visitor *v = qmp_output_visitor_new(&obj);
+    char *str;
+    Visitor *v = json_output_visitor_new(true, &str);

     visit_type_ImageCheck(v, NULL, &check, &error_abort);
-    visit_complete(v, &obj);
-    str = qobject_to_json(obj, true);
-    qprintf(quiet, "%s\n", qstring_get_str(str));
-    qobject_decref(obj);
+    visit_complete(v, &str);
+    qprintf(quiet, "%s\n", str);
+    g_free(str);
     visit_free(v);
-    QDECREF(str);
 }

 static void dump_human_image_check(ImageCheck *check, bool quiet)
@@ -2190,32 +2187,26 @@ static void dump_snapshots(BlockDriverState *bs)

 static void dump_json_image_info_list(ImageInfoList *list)
 {
-    QString *str;
-    QObject *obj;
-    Visitor *v = qmp_output_visitor_new(&obj);
+    char *str;
+    Visitor *v = json_output_visitor_new(true, &str);

     visit_type_ImageInfoList(v, NULL, &list, &error_abort);
-    visit_complete(v, &obj);
-    str = qobject_to_json(obj, true);
-    printf("%s\n", qstring_get_str(str));
-    qobject_decref(obj);
+    visit_complete(v, &str);
+    printf("%s\n", str);
     visit_free(v);
-    QDECREF(str);
+    g_free(str);
 }

 static void dump_json_image_info(ImageInfo *info)
 {
-    QString *str;
-    QObject *obj;
-    Visitor *v = qmp_output_visitor_new(&obj);
+    char *str;
+    Visitor *v = json_output_visitor_new(true, &str);

     visit_type_ImageInfo(v, NULL, &info, &error_abort);
-    visit_complete(v, &obj);
-    str = qobject_to_json(obj, true);
-    printf("%s\n", qstring_get_str(str));
-    qobject_decref(obj);
+    visit_complete(v, &str);
+    printf("%s\n", str);
     visit_free(v);
-    QDECREF(str);
+    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
-- 
2.7.4

  parent reply	other threads:[~2016-10-10 13:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 13:23 [Qemu-devel] [PATCH v6 00/15] Add qapi-to-JSON visitor Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 01/15] qapi: Visitor documentation tweak Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 02/15] qapi: Assert finite use of 'number' Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 03/15] qapi: Factor out JSON string escaping Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 04/15] qapi: Factor out JSON number formatting Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 05/15] qapi: Add qstring_append_printf() Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 06/15] qapi: Use qstring_append_chr() where appropriate Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 07/15] qstring: Add qstring_consume_str() Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 08/15] qstring: Add qstring_wrap_str() Eric Blake
2016-10-11 11:08   ` Marc-André Lureau
2016-10-11 15:04     ` Eric Blake
2016-10-11 15:05       ` Eric Blake
2016-10-11 15:25         ` Marc-André Lureau
2016-10-11 15:24   ` [Qemu-devel] [PATCH v6 08.5/15] fixup! " Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 09/15] qobject: Consolidate qobject_to_json() calls Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 10/15] tests: Test qobject_to_json() pretty formatting Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 11/15] qapi: Add JSON output visitor Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 12/15] qapi: Support pretty printing in " Eric Blake
2016-10-11 11:20   ` Marc-André Lureau
2016-10-11 15:09     ` Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 13/15] qobject: Implement qobject_to_json() atop JSON visitor Eric Blake
2016-10-10 13:23 ` [Qemu-devel] [PATCH v6 14/15] qapi: Add 'any' support to JSON output Eric Blake
2016-10-10 13:23 ` Eric Blake [this message]
2016-10-11 12:14 ` [Qemu-devel] [PATCH v6 00/15] Add qapi-to-JSON visitor Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476105837-9861-16-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.