From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7Cdh-0001pB-Eq for qemu-devel@nongnu.org; Thu, 10 Dec 2015 20:36:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7Cdg-0000hh-2S for qemu-devel@nongnu.org; Thu, 10 Dec 2015 20:36:53 -0500 Date: Fri, 11 Dec 2015 09:36:41 +0800 From: Fam Zheng Message-ID: <20151211013641.GA10985@ad.usersys.redhat.com> References: <1449791621-16185-1-git-send-email-eblake@redhat.com> <1449791621-16185-12-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1449791621-16185-12-git-send-email-eblake@redhat.com> Subject: Re: [Qemu-devel] [PATCH 11/11] RFC: qemu-img: Use new JSON output formatter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , qemu-devel@nongnu.org, "open list:Block layer core" On Thu, 12/10 16:53, Eric Blake wrote: > Now that we can pretty-print straight to JSON from a visitor, > we can eliminate the temporary conversion into QObject inside > qemu-img. > > RFC because at least qemu-iotests 043 has changed output, not > included in this version of the patch. Conflicts with Fam's > qemu-img edits, so one of the two of us will get to rebase on > the other: > https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg01756.html I touched qemu-img map's output, this patch updates info and check, so the context conflict should be okay, but it would be better to get this patch in before mine so I can update my patch to make use of the new formatter, without code churn. Thanks! Fam > > Signed-off-by: Eric Blake > Cc: Fam Zheng > --- > qemu-img.c | 70 ++++++++++++++++++++++++++------------------------------------ > 1 file changed, 29 insertions(+), 41 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index cb961e6..08dca98 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -22,9 +22,9 @@ > * THE SOFTWARE. > */ > #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/qstring.h" > #include "qemu-common.h" > #include "qemu/option.h" > #include "qemu/error-report.h" > @@ -375,19 +375,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), > - &check, NULL, &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), > + &check, NULL, &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) > @@ -1926,36 +1922,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), > - &list, NULL, &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), > + &list, NULL, &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), > - &info, NULL, &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), > + &info, NULL, &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) > -- > 2.4.3 >