|
|
218e99 |
From 85b14be2b92e75320728a450635c80053d8cd374 Mon Sep 17 00:00:00 2001
|
|
|
218e99 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
218e99 |
Date: Wed, 6 Nov 2013 16:53:36 +0100
|
|
|
218e99 |
Subject: [PATCH 79/87] block/qapi: Human-readable ImageInfoSpecific dump
|
|
|
218e99 |
|
|
|
218e99 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
218e99 |
Message-id: <1383756824-6921-14-git-send-email-mreitz@redhat.com>
|
|
|
218e99 |
Patchwork-id: 55568
|
|
|
218e99 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 13/21] block/qapi: Human-readable ImageInfoSpecific dump
|
|
|
218e99 |
Bugzilla: 980771
|
|
|
218e99 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
218e99 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
218e99 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
218e99 |
|
|
|
218e99 |
BZ: 980771
|
|
|
218e99 |
|
|
|
218e99 |
Add a function for generically dumping the ImageInfoSpecific information
|
|
|
218e99 |
in a human-readable format to block/qapi.c.
|
|
|
218e99 |
|
|
|
218e99 |
Use this function in bdrv_image_info_dump and qemu-io-cmds.c:info_f to
|
|
|
218e99 |
allow qemu-img info resp. qemu-io -c info to print that format specific
|
|
|
218e99 |
information.
|
|
|
218e99 |
|
|
|
218e99 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
218e99 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
218e99 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
218e99 |
(cherry picked from commit a8d8ecb77fc16da49ea2c1edae267dc9d0c01dfd)
|
|
|
218e99 |
|
|
|
218e99 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
218e99 |
|
|
|
218e99 |
Conflicts:
|
|
|
218e99 |
qemu-io.c
|
|
|
218e99 |
qemu-io-cmds.c
|
|
|
218e99 |
|
|
|
218e99 |
Conflicts because 797ac58cb2093ab9192d8998a1fef85d87cc8661 has not been
|
|
|
218e99 |
backported, which splits qemu-io-cmds.c from qemu-io.c.
|
|
|
218e99 |
---
|
|
|
218e99 |
block/qapi.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
218e99 |
include/block/qapi.h | 2 +
|
|
|
218e99 |
qemu-io.c | 9 ++++
|
|
|
218e99 |
3 files changed, 132 insertions(+)
|
|
|
218e99 |
|
|
|
218e99 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
218e99 |
---
|
|
|
218e99 |
block/qapi.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
218e99 |
include/block/qapi.h | 2 +
|
|
|
218e99 |
qemu-io.c | 9 ++++
|
|
|
218e99 |
3 files changed, 132 insertions(+), 0 deletions(-)
|
|
|
218e99 |
|
|
|
218e99 |
diff --git a/block/qapi.c b/block/qapi.c
|
|
|
218e99 |
index 896cd37..87423fb 100644
|
|
|
218e99 |
--- a/block/qapi.c
|
|
|
218e99 |
+++ b/block/qapi.c
|
|
|
218e99 |
@@ -25,6 +25,9 @@
|
|
|
218e99 |
#include "block/qapi.h"
|
|
|
218e99 |
#include "block/block_int.h"
|
|
|
218e99 |
#include "qmp-commands.h"
|
|
|
218e99 |
+#include "qapi-visit.h"
|
|
|
218e99 |
+#include "qapi/qmp-output-visitor.h"
|
|
|
218e99 |
+#include "qapi/qmp/types.h"
|
|
|
218e99 |
|
|
|
218e99 |
/*
|
|
|
218e99 |
* Returns 0 on success, with *p_list either set to describe snapshot
|
|
|
218e99 |
@@ -400,6 +403,119 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
}
|
|
|
218e99 |
}
|
|
|
218e99 |
|
|
|
218e99 |
+static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
|
|
|
218e99 |
+ QDict *dict);
|
|
|
218e99 |
+static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
|
|
|
218e99 |
+ QList *list);
|
|
|
218e99 |
+
|
|
|
218e99 |
+static void dump_qobject(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
+ int comp_indent, QObject *obj)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ switch (qobject_type(obj)) {
|
|
|
218e99 |
+ case QTYPE_QINT: {
|
|
|
218e99 |
+ QInt *value = qobject_to_qint(obj);
|
|
|
218e99 |
+ func_fprintf(f, "%" PRId64, qint_get_int(value));
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QSTRING: {
|
|
|
218e99 |
+ QString *value = qobject_to_qstring(obj);
|
|
|
218e99 |
+ func_fprintf(f, "%s", qstring_get_str(value));
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QDICT: {
|
|
|
218e99 |
+ QDict *value = qobject_to_qdict(obj);
|
|
|
218e99 |
+ dump_qdict(func_fprintf, f, comp_indent, value);
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QLIST: {
|
|
|
218e99 |
+ QList *value = qobject_to_qlist(obj);
|
|
|
218e99 |
+ dump_qlist(func_fprintf, f, comp_indent, value);
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QFLOAT: {
|
|
|
218e99 |
+ QFloat *value = qobject_to_qfloat(obj);
|
|
|
218e99 |
+ func_fprintf(f, "%g", qfloat_get_double(value));
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QBOOL: {
|
|
|
218e99 |
+ QBool *value = qobject_to_qbool(obj);
|
|
|
218e99 |
+ func_fprintf(f, "%s", qbool_get_int(value) ? "true" : "false");
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_QERROR: {
|
|
|
218e99 |
+ QString *value = qerror_human((QError *)obj);
|
|
|
218e99 |
+ func_fprintf(f, "%s", qstring_get_str(value));
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ case QTYPE_NONE:
|
|
|
218e99 |
+ break;
|
|
|
218e99 |
+ case QTYPE_MAX:
|
|
|
218e99 |
+ default:
|
|
|
218e99 |
+ abort();
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+}
|
|
|
218e99 |
+
|
|
|
218e99 |
+static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
|
|
|
218e99 |
+ QList *list)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ const QListEntry *entry;
|
|
|
218e99 |
+ int i = 0;
|
|
|
218e99 |
+
|
|
|
218e99 |
+ for (entry = qlist_first(list); entry; entry = qlist_next(entry), i++) {
|
|
|
218e99 |
+ qtype_code type = qobject_type(entry->value);
|
|
|
218e99 |
+ bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
|
|
|
218e99 |
+ const char *format = composite ? "%*s[%i]:\n" : "%*s[%i]: ";
|
|
|
218e99 |
+
|
|
|
218e99 |
+ func_fprintf(f, format, indentation * 4, "", i);
|
|
|
218e99 |
+ dump_qobject(func_fprintf, f, indentation + 1, entry->value);
|
|
|
218e99 |
+ if (!composite) {
|
|
|
218e99 |
+ func_fprintf(f, "\n");
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+}
|
|
|
218e99 |
+
|
|
|
218e99 |
+static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
|
|
|
218e99 |
+ QDict *dict)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ const QDictEntry *entry;
|
|
|
218e99 |
+
|
|
|
218e99 |
+ for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) {
|
|
|
218e99 |
+ qtype_code type = qobject_type(entry->value);
|
|
|
218e99 |
+ bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
|
|
|
218e99 |
+ const char *format = composite ? "%*s%s:\n" : "%*s%s: ";
|
|
|
218e99 |
+ char key[strlen(entry->key) + 1];
|
|
|
218e99 |
+ int i;
|
|
|
218e99 |
+
|
|
|
218e99 |
+ /* replace dashes with spaces in key (variable) names */
|
|
|
218e99 |
+ for (i = 0; entry->key[i]; i++) {
|
|
|
218e99 |
+ key[i] = entry->key[i] == '-' ? ' ' : entry->key[i];
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ key[i] = 0;
|
|
|
218e99 |
+
|
|
|
218e99 |
+ func_fprintf(f, format, indentation * 4, "", key);
|
|
|
218e99 |
+ dump_qobject(func_fprintf, f, indentation + 1, entry->value);
|
|
|
218e99 |
+ if (!composite) {
|
|
|
218e99 |
+ func_fprintf(f, "\n");
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+}
|
|
|
218e99 |
+
|
|
|
218e99 |
+void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
+ ImageInfoSpecific *info_spec)
|
|
|
218e99 |
+{
|
|
|
218e99 |
+ Error *local_err = NULL;
|
|
|
218e99 |
+ QmpOutputVisitor *ov = qmp_output_visitor_new();
|
|
|
218e99 |
+ QObject *obj, *data;
|
|
|
218e99 |
+
|
|
|
218e99 |
+ visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), &info_spec, NULL,
|
|
|
218e99 |
+ &local_err);
|
|
|
218e99 |
+ obj = qmp_output_get_qobject(ov);
|
|
|
218e99 |
+ assert(qobject_type(obj) == QTYPE_QDICT);
|
|
|
218e99 |
+ data = qdict_get(qobject_to_qdict(obj), "data");
|
|
|
218e99 |
+ dump_qobject(func_fprintf, f, 1, data);
|
|
|
218e99 |
+ qmp_output_visitor_cleanup(ov);
|
|
|
218e99 |
+}
|
|
|
218e99 |
+
|
|
|
218e99 |
void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
ImageInfo *info)
|
|
|
218e99 |
{
|
|
|
218e99 |
@@ -470,4 +586,9 @@ void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
func_fprintf(f, "\n");
|
|
|
218e99 |
}
|
|
|
218e99 |
}
|
|
|
218e99 |
+
|
|
|
218e99 |
+ if (info->has_format_specific) {
|
|
|
218e99 |
+ func_fprintf(f, "Format specific information:\n");
|
|
|
218e99 |
+ bdrv_image_info_specific_dump(func_fprintf, f, info->format_specific);
|
|
|
218e99 |
+ }
|
|
|
218e99 |
}
|
|
|
218e99 |
diff --git a/include/block/qapi.h b/include/block/qapi.h
|
|
|
218e99 |
index 0496cc9..9518ee4 100644
|
|
|
218e99 |
--- a/include/block/qapi.h
|
|
|
218e99 |
+++ b/include/block/qapi.h
|
|
|
218e99 |
@@ -42,6 +42,8 @@ BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
|
|
218e99 |
|
|
|
218e99 |
void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
QEMUSnapshotInfo *sn);
|
|
|
218e99 |
+void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
+ ImageInfoSpecific *info_spec);
|
|
|
218e99 |
void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
|
|
218e99 |
ImageInfo *info);
|
|
|
218e99 |
#endif
|
|
|
218e99 |
diff --git a/qemu-io.c b/qemu-io.c
|
|
|
218e99 |
index 116bb1b..df21022 100644
|
|
|
218e99 |
--- a/qemu-io.c
|
|
|
218e99 |
+++ b/qemu-io.c
|
|
|
218e99 |
@@ -17,6 +17,7 @@
|
|
|
218e99 |
#include "qemu-common.h"
|
|
|
218e99 |
#include "qemu/main-loop.h"
|
|
|
218e99 |
#include "block/block_int.h"
|
|
|
218e99 |
+#include "block/qapi.h"
|
|
|
218e99 |
#include "cmd.h"
|
|
|
218e99 |
#include "trace/control.h"
|
|
|
218e99 |
|
|
|
218e99 |
@@ -1462,6 +1463,7 @@ static const cmdinfo_t length_cmd = {
|
|
|
218e99 |
static int info_f(int argc, char **argv)
|
|
|
218e99 |
{
|
|
|
218e99 |
BlockDriverInfo bdi;
|
|
|
218e99 |
+ ImageInfoSpecific *spec_info;
|
|
|
218e99 |
char s1[64], s2[64];
|
|
|
218e99 |
int ret;
|
|
|
218e99 |
|
|
|
218e99 |
@@ -1483,6 +1485,13 @@ static int info_f(int argc, char **argv)
|
|
|
218e99 |
printf("cluster size: %s\n", s1);
|
|
|
218e99 |
printf("vm state offset: %s\n", s2);
|
|
|
218e99 |
|
|
|
218e99 |
+ spec_info = bdrv_get_specific_info(bs);
|
|
|
218e99 |
+ if (spec_info) {
|
|
|
218e99 |
+ printf("Format specific information:\n");
|
|
|
218e99 |
+ bdrv_image_info_specific_dump(fprintf, stdout, spec_info);
|
|
|
218e99 |
+ qapi_free_ImageInfoSpecific(spec_info);
|
|
|
218e99 |
+ }
|
|
|
218e99 |
+
|
|
|
218e99 |
return 0;
|
|
|
218e99 |
}
|
|
|
218e99 |
|
|
|
218e99 |
--
|
|
|
218e99 |
1.7.1
|
|
|
218e99 |
|