From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bADz6-0008AT-Nu for qemu-devel@nongnu.org; Tue, 07 Jun 2016 06:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bADz5-00055W-IY for qemu-devel@nongnu.org; Tue, 07 Jun 2016 06:11:44 -0400 From: "Daniel P. Berrange" Date: Tue, 7 Jun 2016 11:11:15 +0100 Message-Id: <1465294275-8733-7-git-send-email-berrange@redhat.com> In-Reply-To: <1465294275-8733-1-git-send-email-berrange@redhat.com> References: <1465294275-8733-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageInfoSpecific List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Max Reitz , Markus Armbruster , Michael Roth , Eric Blake , "Daniel P. Berrange" When 'qemu-img info' prints out format specific information, it first converts the QAPI object into a JSON based QObject data structure. Unfortunately structs have to be turned into dicts, which looses all information about field ordering, so the data printed appears in a semi-random order. Convert this to use the qapi_stringify_ImageInfoSpecific() which uses a visitor to directly pretty-print the objects without the intermediate QObject conversion, and thus will maintain struct field ordering. Signed-off-by: Daniel P. Berrange --- block/qapi.c | 101 ++--------------------------------------------------------- 1 file changed, 3 insertions(+), 98 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 5594f74..769d7f3 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -29,7 +29,6 @@ #include "block/write-threshold.h" #include "qmp-commands.h" #include "qapi-visit.h" -#include "qapi/qmp-output-visitor.h" #include "qapi/qmp/types.h" #include "sysemu/block-backend.h" #include "qemu/cutils.h" @@ -599,107 +598,13 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f, } } -static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation, - QDict *dict); -static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation, - QList *list); - -static void dump_qobject(fprintf_function func_fprintf, void *f, - int comp_indent, QObject *obj) -{ - switch (qobject_type(obj)) { - case QTYPE_QINT: { - QInt *value = qobject_to_qint(obj); - func_fprintf(f, "%" PRId64, qint_get_int(value)); - break; - } - case QTYPE_QSTRING: { - QString *value = qobject_to_qstring(obj); - func_fprintf(f, "%s", qstring_get_str(value)); - break; - } - case QTYPE_QDICT: { - QDict *value = qobject_to_qdict(obj); - dump_qdict(func_fprintf, f, comp_indent, value); - break; - } - case QTYPE_QLIST: { - QList *value = qobject_to_qlist(obj); - dump_qlist(func_fprintf, f, comp_indent, value); - break; - } - case QTYPE_QFLOAT: { - QFloat *value = qobject_to_qfloat(obj); - func_fprintf(f, "%g", qfloat_get_double(value)); - break; - } - case QTYPE_QBOOL: { - QBool *value = qobject_to_qbool(obj); - func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false"); - break; - } - default: - abort(); - } -} - -static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation, - QList *list) -{ - const QListEntry *entry; - int i = 0; - - for (entry = qlist_first(list); entry; entry = qlist_next(entry), i++) { - QType type = qobject_type(entry->value); - bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST); - func_fprintf(f, "%*s[%i]:%c", indentation * 4, "", i, - composite ? '\n' : ' '); - dump_qobject(func_fprintf, f, indentation + 1, entry->value); - if (!composite) { - func_fprintf(f, "\n"); - } - } -} - -static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation, - QDict *dict) -{ - const QDictEntry *entry; - - for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) { - QType type = qobject_type(entry->value); - bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST); - char *key = g_malloc(strlen(entry->key) + 1); - int i; - - /* replace dashes with spaces in key (variable) names */ - for (i = 0; entry->key[i]; i++) { - key[i] = entry->key[i] == '-' ? ' ' : entry->key[i]; - } - key[i] = 0; - func_fprintf(f, "%*s%s:%c", indentation * 4, "", key, - composite ? '\n' : ' '); - dump_qobject(func_fprintf, f, indentation + 1, entry->value); - if (!composite) { - func_fprintf(f, "\n"); - } - g_free(key); - } -} void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f, ImageInfoSpecific *info_spec) { - QmpOutputVisitor *ov = qmp_output_visitor_new(); - QObject *obj, *data; - - visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), NULL, &info_spec, - &error_abort); - obj = qmp_output_get_qobject(ov); - assert(qobject_type(obj) == QTYPE_QDICT); - data = qdict_get(qobject_to_qdict(obj), "data"); - dump_qobject(func_fprintf, f, 1, data); - qmp_output_visitor_cleanup(ov); + char *str = qapi_stringify_ImageInfoSpecific(info_spec, 4, 2); + func_fprintf(f, "%s", str); + g_free(str); } void bdrv_image_info_dump(fprintf_function func_fprintf, void *f, -- 2.5.5