Skip to content

Commit 76c9e97

Browse files
XanClickevmw
authored andcommitted
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 <[email protected]> Message-Id: <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 6cab339 commit 76c9e97

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

block/monitor/block-hmp-cmds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
725725
monitor_printf(mon, "\nImages:\n");
726726
image_info = inserted->image;
727727
while (1) {
728-
bdrv_node_info_dump(qapi_ImageInfo_base(image_info));
728+
bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0);
729729
if (image_info->backing_image) {
730730
image_info = image_info->backing_image;
731731
} else {

block/qapi.c

+27-20
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,8 @@ static bool qobject_is_empty_dump(const QObject *obj)
898898
* prepending an optional prefix if the dump is not empty.
899899
*/
900900
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
901-
const char *prefix)
901+
const char *prefix,
902+
int indentation)
902903
{
903904
QObject *obj, *data;
904905
Visitor *v = qobject_output_visitor_new(&obj);
@@ -908,48 +909,51 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
908909
data = qdict_get(qobject_to(QDict, obj), "data");
909910
if (!qobject_is_empty_dump(data)) {
910911
if (prefix) {
911-
qemu_printf("%s", prefix);
912+
qemu_printf("%*s%s", indentation * 4, "", prefix);
912913
}
913-
dump_qobject(1, data);
914+
dump_qobject(indentation + 1, data);
914915
}
915916
qobject_unref(obj);
916917
visit_free(v);
917918
}
918919

919-
void bdrv_node_info_dump(BlockNodeInfo *info)
920+
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation)
920921
{
921922
char *size_buf, *dsize_buf;
923+
g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, "");
924+
922925
if (!info->has_actual_size) {
923926
dsize_buf = g_strdup("unavailable");
924927
} else {
925928
dsize_buf = size_to_str(info->actual_size);
926929
}
927930
size_buf = size_to_str(info->virtual_size);
928-
qemu_printf("image: %s\n"
929-
"file format: %s\n"
930-
"virtual size: %s (%" PRId64 " bytes)\n"
931-
"disk size: %s\n",
932-
info->filename, info->format, size_buf,
933-
info->virtual_size,
934-
dsize_buf);
931+
qemu_printf("%simage: %s\n"
932+
"%sfile format: %s\n"
933+
"%svirtual size: %s (%" PRId64 " bytes)\n"
934+
"%sdisk size: %s\n",
935+
ind_s, info->filename,
936+
ind_s, info->format,
937+
ind_s, size_buf, info->virtual_size,
938+
ind_s, dsize_buf);
935939
g_free(size_buf);
936940
g_free(dsize_buf);
937941

938942
if (info->has_encrypted && info->encrypted) {
939-
qemu_printf("encrypted: yes\n");
943+
qemu_printf("%sencrypted: yes\n", ind_s);
940944
}
941945

942946
if (info->has_cluster_size) {
943-
qemu_printf("cluster_size: %" PRId64 "\n",
944-
info->cluster_size);
947+
qemu_printf("%scluster_size: %" PRId64 "\n",
948+
ind_s, info->cluster_size);
945949
}
946950

947951
if (info->has_dirty_flag && info->dirty_flag) {
948-
qemu_printf("cleanly shut down: no\n");
952+
qemu_printf("%scleanly shut down: no\n", ind_s);
949953
}
950954

951955
if (info->backing_filename) {
952-
qemu_printf("backing file: %s", info->backing_filename);
956+
qemu_printf("%sbacking file: %s", ind_s, info->backing_filename);
953957
if (!info->full_backing_filename) {
954958
qemu_printf(" (cannot determine actual path)");
955959
} else if (strcmp(info->backing_filename,
@@ -958,15 +962,16 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
958962
}
959963
qemu_printf("\n");
960964
if (info->backing_filename_format) {
961-
qemu_printf("backing file format: %s\n",
962-
info->backing_filename_format);
965+
qemu_printf("%sbacking file format: %s\n",
966+
ind_s, info->backing_filename_format);
963967
}
964968
}
965969

966970
if (info->has_snapshots) {
967971
SnapshotInfoList *elem;
968972

969-
qemu_printf("Snapshot list:\n");
973+
qemu_printf("%sSnapshot list:\n", ind_s);
974+
qemu_printf("%s", ind_s);
970975
bdrv_snapshot_dump(NULL);
971976
qemu_printf("\n");
972977

@@ -986,13 +991,15 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
986991

987992
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
988993
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
994+
qemu_printf("%s", ind_s);
989995
bdrv_snapshot_dump(&sn);
990996
qemu_printf("\n");
991997
}
992998
}
993999

9941000
if (info->format_specific) {
9951001
bdrv_image_info_specific_dump(info->format_specific,
996-
"Format specific information:\n");
1002+
"Format specific information:\n",
1003+
indentation);
9971004
}
9981005
}

include/block/qapi.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs,
4949

5050
void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
5151
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
52-
const char *prefix);
53-
void bdrv_node_info_dump(BlockNodeInfo *info);
52+
const char *prefix,
53+
int indentation);
54+
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation);
5455
#endif

qemu-img.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2860,7 +2860,7 @@ static void dump_human_image_info_list(BlockNodeInfoList *list)
28602860
}
28612861
delim = true;
28622862

2863-
bdrv_node_info_dump(elem->value);
2863+
bdrv_node_info_dump(elem->value, 0);
28642864
}
28652865
}
28662866

qemu-io-cmds.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,8 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
17891789
}
17901790
if (spec_info) {
17911791
bdrv_image_info_specific_dump(spec_info,
1792-
"Format specific information:\n");
1792+
"Format specific information:\n",
1793+
0);
17931794
qapi_free_ImageInfoSpecific(spec_info);
17941795
}
17951796

0 commit comments

Comments
 (0)