block/qapi: Add indentation to bdrv_node_info_dump()
In order to let qemu-img info present a block graph, add a parameter to bdrv_node_info_dump() and bdrv_image_info_specific_dump() so that the information of nodes below the root level can be given an indentation. Signed-off-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20220620162704.80987-9-hreitz@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
6cab33997b
commit
76c9e9750d
@ -725,7 +725,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
|||||||
monitor_printf(mon, "\nImages:\n");
|
monitor_printf(mon, "\nImages:\n");
|
||||||
image_info = inserted->image;
|
image_info = inserted->image;
|
||||||
while (1) {
|
while (1) {
|
||||||
bdrv_node_info_dump(qapi_ImageInfo_base(image_info));
|
bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0);
|
||||||
if (image_info->backing_image) {
|
if (image_info->backing_image) {
|
||||||
image_info = image_info->backing_image;
|
image_info = image_info->backing_image;
|
||||||
} else {
|
} else {
|
||||||
|
47
block/qapi.c
47
block/qapi.c
@ -898,7 +898,8 @@ static bool qobject_is_empty_dump(const QObject *obj)
|
|||||||
* prepending an optional prefix if the dump is not empty.
|
* prepending an optional prefix if the dump is not empty.
|
||||||
*/
|
*/
|
||||||
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
|
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
|
||||||
const char *prefix)
|
const char *prefix,
|
||||||
|
int indentation)
|
||||||
{
|
{
|
||||||
QObject *obj, *data;
|
QObject *obj, *data;
|
||||||
Visitor *v = qobject_output_visitor_new(&obj);
|
Visitor *v = qobject_output_visitor_new(&obj);
|
||||||
@ -908,48 +909,51 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
|
|||||||
data = qdict_get(qobject_to(QDict, obj), "data");
|
data = qdict_get(qobject_to(QDict, obj), "data");
|
||||||
if (!qobject_is_empty_dump(data)) {
|
if (!qobject_is_empty_dump(data)) {
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
qemu_printf("%s", prefix);
|
qemu_printf("%*s%s", indentation * 4, "", prefix);
|
||||||
}
|
}
|
||||||
dump_qobject(1, data);
|
dump_qobject(indentation + 1, data);
|
||||||
}
|
}
|
||||||
qobject_unref(obj);
|
qobject_unref(obj);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_node_info_dump(BlockNodeInfo *info)
|
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation)
|
||||||
{
|
{
|
||||||
char *size_buf, *dsize_buf;
|
char *size_buf, *dsize_buf;
|
||||||
|
g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, "");
|
||||||
|
|
||||||
if (!info->has_actual_size) {
|
if (!info->has_actual_size) {
|
||||||
dsize_buf = g_strdup("unavailable");
|
dsize_buf = g_strdup("unavailable");
|
||||||
} else {
|
} else {
|
||||||
dsize_buf = size_to_str(info->actual_size);
|
dsize_buf = size_to_str(info->actual_size);
|
||||||
}
|
}
|
||||||
size_buf = size_to_str(info->virtual_size);
|
size_buf = size_to_str(info->virtual_size);
|
||||||
qemu_printf("image: %s\n"
|
qemu_printf("%simage: %s\n"
|
||||||
"file format: %s\n"
|
"%sfile format: %s\n"
|
||||||
"virtual size: %s (%" PRId64 " bytes)\n"
|
"%svirtual size: %s (%" PRId64 " bytes)\n"
|
||||||
"disk size: %s\n",
|
"%sdisk size: %s\n",
|
||||||
info->filename, info->format, size_buf,
|
ind_s, info->filename,
|
||||||
info->virtual_size,
|
ind_s, info->format,
|
||||||
dsize_buf);
|
ind_s, size_buf, info->virtual_size,
|
||||||
|
ind_s, dsize_buf);
|
||||||
g_free(size_buf);
|
g_free(size_buf);
|
||||||
g_free(dsize_buf);
|
g_free(dsize_buf);
|
||||||
|
|
||||||
if (info->has_encrypted && info->encrypted) {
|
if (info->has_encrypted && info->encrypted) {
|
||||||
qemu_printf("encrypted: yes\n");
|
qemu_printf("%sencrypted: yes\n", ind_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_cluster_size) {
|
if (info->has_cluster_size) {
|
||||||
qemu_printf("cluster_size: %" PRId64 "\n",
|
qemu_printf("%scluster_size: %" PRId64 "\n",
|
||||||
info->cluster_size);
|
ind_s, info->cluster_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_dirty_flag && info->dirty_flag) {
|
if (info->has_dirty_flag && info->dirty_flag) {
|
||||||
qemu_printf("cleanly shut down: no\n");
|
qemu_printf("%scleanly shut down: no\n", ind_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->backing_filename) {
|
if (info->backing_filename) {
|
||||||
qemu_printf("backing file: %s", info->backing_filename);
|
qemu_printf("%sbacking file: %s", ind_s, info->backing_filename);
|
||||||
if (!info->full_backing_filename) {
|
if (!info->full_backing_filename) {
|
||||||
qemu_printf(" (cannot determine actual path)");
|
qemu_printf(" (cannot determine actual path)");
|
||||||
} else if (strcmp(info->backing_filename,
|
} else if (strcmp(info->backing_filename,
|
||||||
@ -958,15 +962,16 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
|
|||||||
}
|
}
|
||||||
qemu_printf("\n");
|
qemu_printf("\n");
|
||||||
if (info->backing_filename_format) {
|
if (info->backing_filename_format) {
|
||||||
qemu_printf("backing file format: %s\n",
|
qemu_printf("%sbacking file format: %s\n",
|
||||||
info->backing_filename_format);
|
ind_s, info->backing_filename_format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_snapshots) {
|
if (info->has_snapshots) {
|
||||||
SnapshotInfoList *elem;
|
SnapshotInfoList *elem;
|
||||||
|
|
||||||
qemu_printf("Snapshot list:\n");
|
qemu_printf("%sSnapshot list:\n", ind_s);
|
||||||
|
qemu_printf("%s", ind_s);
|
||||||
bdrv_snapshot_dump(NULL);
|
bdrv_snapshot_dump(NULL);
|
||||||
qemu_printf("\n");
|
qemu_printf("\n");
|
||||||
|
|
||||||
@ -986,6 +991,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
|
|||||||
|
|
||||||
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
|
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
|
||||||
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
|
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
|
||||||
|
qemu_printf("%s", ind_s);
|
||||||
bdrv_snapshot_dump(&sn);
|
bdrv_snapshot_dump(&sn);
|
||||||
qemu_printf("\n");
|
qemu_printf("\n");
|
||||||
}
|
}
|
||||||
@ -993,6 +999,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
|
|||||||
|
|
||||||
if (info->format_specific) {
|
if (info->format_specific) {
|
||||||
bdrv_image_info_specific_dump(info->format_specific,
|
bdrv_image_info_specific_dump(info->format_specific,
|
||||||
"Format specific information:\n");
|
"Format specific information:\n",
|
||||||
|
indentation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs,
|
|||||||
|
|
||||||
void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
|
void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
|
||||||
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
|
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
|
||||||
const char *prefix);
|
const char *prefix,
|
||||||
void bdrv_node_info_dump(BlockNodeInfo *info);
|
int indentation);
|
||||||
|
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2860,7 +2860,7 @@ static void dump_human_image_info_list(BlockNodeInfoList *list)
|
|||||||
}
|
}
|
||||||
delim = true;
|
delim = true;
|
||||||
|
|
||||||
bdrv_node_info_dump(elem->value);
|
bdrv_node_info_dump(elem->value, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1789,7 +1789,8 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (spec_info) {
|
if (spec_info) {
|
||||||
bdrv_image_info_specific_dump(spec_info,
|
bdrv_image_info_specific_dump(spec_info,
|
||||||
"Format specific information:\n");
|
"Format specific information:\n",
|
||||||
|
0);
|
||||||
qapi_free_ImageInfoSpecific(spec_info);
|
qapi_free_ImageInfoSpecific(spec_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user