From patchwork Fri Apr 29 04:23:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8977121 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 38AD8BF29F for ; Fri, 29 Apr 2016 04:35:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3DA4620219 for ; Fri, 29 Apr 2016 04:35:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0922B20166 for ; Fri, 29 Apr 2016 04:35:12 +0000 (UTC) Received: from localhost ([::1]:52301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw091-00071m-C0 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Apr 2016 00:35:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avzyB-0007TD-D6 for qemu-devel@nongnu.org; Fri, 29 Apr 2016 00:24:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avzy9-0000xB-Vr for qemu-devel@nongnu.org; Fri, 29 Apr 2016 00:23:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avzy5-0000uJ-Id; Fri, 29 Apr 2016 00:23:53 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49118C049E18; Fri, 29 Apr 2016 04:23:53 +0000 (UTC) Received: from red.redhat.com (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3T4NgfB016324; Fri, 29 Apr 2016 00:23:52 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 28 Apr 2016 22:23:35 -0600 Message-Id: <1461903820-3092-15-git-send-email-eblake@redhat.com> In-Reply-To: <1461903820-3092-1-git-send-email-eblake@redhat.com> References: <1461903820-3092-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 14/18] qemu-img: Use new JSON output formatter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , famz@redhat.com, armbru@redhat.com, "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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); + visit_type_ImageCheck(json_output_get_visitor(ov), NULL, + &check, &error_abort); + str = json_output_get_string(ov); + assert(str); + 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