From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-block@nongnu.org, "Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v2 6/6] block: convert to use qapi_stringify_ImageInfoSpecific
Date: Fri, 9 Sep 2016 18:42:01 +0100 [thread overview]
Message-ID: <1473442921-2968-7-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1473442921-2968-1-git-send-email-berrange@redhat.com>
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.
Converting this to use the TextOutputVisitor allows the QAPI
type to be directly pretty-printed without any conversion,
thus preserving struct field ordering in the output.
The output format structure to the old code, only the ordering
of fields is changed.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
block/qapi.c | 100 ++++-------------------------------------------------------
1 file changed, 6 insertions(+), 94 deletions(-)
diff --git a/block/qapi.c b/block/qapi.c
index 0f59d9c..ff98ac8 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -29,7 +29,7 @@
#include "block/write-threshold.h"
#include "qmp-commands.h"
#include "qapi-visit.h"
-#include "qapi/qmp-output-visitor.h"
+#include "qapi/text-output-visitor.h"
#include "qapi/qmp/types.h"
#include "sysemu/block-backend.h"
#include "qemu/cutils.h"
@@ -572,105 +572,17 @@ 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)
{
- QObject *obj, *data;
- Visitor *v = qmp_output_visitor_new(&obj);
+ Visitor *v = text_output_visitor_new(4, 2);
+ char *str;
visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort);
- visit_complete(v, &obj);
- assert(qobject_type(obj) == QTYPE_QDICT);
- data = qdict_get(qobject_to_qdict(obj), "data");
- dump_qobject(func_fprintf, f, 1, data);
+ visit_complete(v, &str);
+ func_fprintf(f, "%s", str);
+ g_free(str);
visit_free(v);
}
--
2.7.4
next prev parent reply other threads:[~2016-09-09 17:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-09 17:41 [Qemu-devel] [PATCH v2 0/6] Stable output of blockdev format specific info Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 1/6] cutils: add helpers for formatting sized values Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 2/6] qapi: convert StringOutputVisitor to use qemu_szutostr Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 3/6] qapi: assert that visitor impls have required callbacks Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 4/6] qapi: add a text output visitor for pretty printing types Daniel P. Berrange
2016-09-09 17:42 ` [Qemu-devel] [PATCH v2 5/6] block: convert to use the qemu_szutostr functions Daniel P. Berrange
2016-09-09 17:42 ` Daniel P. Berrange [this message]
2016-09-13 13:44 ` [Qemu-devel] [PATCH v2 0/6] Stable output of blockdev format specific info Markus Armbruster
2016-09-13 13:52 ` Daniel P. Berrange
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=1473442921-2968-7-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=pbonzini@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.