Skip to content

Commit d570177

Browse files
XanClickevmw
authored andcommitted
qemu-img: Change info key names for protocol nodes
Currently, when querying a qcow2 image, qemu-img info reports something like this: image: test.qcow2 file format: qcow2 virtual size: 64 MiB (67108864 bytes) disk size: 196 KiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false extended l2: false Child node '/file': image: test.qcow2 file format: file virtual size: 192 KiB (197120 bytes) disk size: 196 KiB Format specific information: extent size hint: 1048576 Notably, the way the keys are named is specific for image files: The filename is shown under "image", the BDS driver under "file format", and the BDS length under "virtual size". This does not make much sense for nodes that are not actually supposed to be guest images, like the /file child node shown above. Give bdrv_node_info_dump() a @protocol parameter that gives a hint that the respective node is probably just used for data storage and does not necessarily present the data for a VM guest disk. This renames the keys so that with this patch, the output becomes: image: test.qcow2 [...] Child node '/file': filename: test.qcow2 protocol type: file file length: 192 KiB (197120 bytes) disk size: 196 KiB Format specific information: extent size hint: 1048576 (Perhaps we should also rename "Format specific information", but I could not come up with anything better that will not become problematic if we guess wrong with the protocol "heuristic".) This change affects iotest 302, which has protocol node information in its reference output. 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 c04d0ab commit d570177

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
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), 0);
728+
bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0, false);
729729
if (image_info->backing_image) {
730730
image_info = image_info->backing_image;
731731
} else {

block/qapi.c

+32-7
Original file line numberDiff line numberDiff line change
@@ -917,24 +917,49 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
917917
visit_free(v);
918918
}
919919

920-
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation)
920+
/**
921+
* Print the given @info object in human-readable form. Every field is indented
922+
* using the given @indentation (four spaces per indentation level).
923+
*
924+
* When using this to print a whole block graph, @protocol can be set to true to
925+
* signify that the given information is associated with a protocol node, i.e.
926+
* just data storage for an image, such that the data it presents is not really
927+
* a full VM disk. If so, several fields change name: For example, "virtual
928+
* size" is printed as "file length".
929+
* (Consider a qcow2 image, which is represented by a qcow2 node and a file
930+
* node. Printing a "virtual size" for the file node does not make sense,
931+
* because without the qcow2 node, it is not really a guest disk, so it does not
932+
* have a "virtual size". Therefore, we call it "file length" instead.)
933+
*
934+
* @protocol is ignored when @indentation is 0, because we take that to mean
935+
* that the associated node is the root node in the queried block graph, and
936+
* thus is always to be interpreted as a standalone guest disk.
937+
*/
938+
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol)
921939
{
922940
char *size_buf, *dsize_buf;
923941
g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, "");
924942

943+
if (indentation == 0) {
944+
/* Top level, consider this a normal image */
945+
protocol = false;
946+
}
947+
925948
if (!info->has_actual_size) {
926949
dsize_buf = g_strdup("unavailable");
927950
} else {
928951
dsize_buf = size_to_str(info->actual_size);
929952
}
930953
size_buf = size_to_str(info->virtual_size);
931-
qemu_printf("%simage: %s\n"
932-
"%sfile format: %s\n"
933-
"%svirtual size: %s (%" PRId64 " bytes)\n"
954+
qemu_printf("%s%s: %s\n"
955+
"%s%s: %s\n"
956+
"%s%s: %s (%" PRId64 " bytes)\n"
934957
"%sdisk size: %s\n",
935-
ind_s, info->filename,
936-
ind_s, info->format,
937-
ind_s, size_buf, info->virtual_size,
958+
ind_s, protocol ? "filename" : "image", info->filename,
959+
ind_s, protocol ? "protocol type" : "file format",
960+
info->format,
961+
ind_s, protocol ? "file length" : "virtual size",
962+
size_buf, info->virtual_size,
938963
ind_s, dsize_buf);
939964
g_free(size_buf);
940965
g_free(dsize_buf);

include/block/qapi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
5151
void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
5252
const char *prefix,
5353
int indentation);
54-
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation);
54+
void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol);
5555
#endif

qemu-img.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,8 @@ static void dump_human_image_info(BlockGraphInfo *info, int indentation,
28542854
{
28552855
BlockChildInfoList *children_list;
28562856

2857-
bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation);
2857+
bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation,
2858+
info->children == NULL);
28582859

28592860
for (children_list = info->children; children_list;
28602861
children_list = children_list->next)

tests/qemu-iotests/302.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ file format: raw
55
virtual size: 448 KiB (458752 bytes)
66
disk size: unavailable
77
Child node '/file':
8-
image: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock
9-
file format: nbd
10-
virtual size: 448 KiB (458752 bytes)
8+
filename: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock
9+
protocol type: nbd
10+
file length: 448 KiB (458752 bytes)
1111
disk size: unavailable
1212

1313
=== Converted image info ===

0 commit comments

Comments
 (0)