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