[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageIn
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageInfoSpecific |
Date: |
Tue, 7 Jun 2016 11:11:15 +0100 |
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 <address@hidden>
---
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
- Re: [Qemu-devel] [PATCH v1 2/6] block: export LUKS specific data to qemu-img info, (continued)
[Qemu-devel] [PATCH v1 4/6] qapi: add a text output visitor for pretty printing types, Daniel P. Berrange, 2016/06/07
[Qemu-devel] [PATCH v1 5/6] qapi: generate a qapi_stringify_TYPENAME method for all types, Daniel P. Berrange, 2016/06/07
[Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageInfoSpecific,
Daniel P. Berrange <=
Re: [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver, Eric Blake, 2016/06/07
Re: [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver, Max Reitz, 2016/06/14