Skip to content

Commit

Permalink
qemu-img: map: report compressed data blocks
Browse files Browse the repository at this point in the history
Right now "qemu-img map" reports compressed blocks as containing data
but having no host offset.  This is not very informative.  Instead,
let's add another boolean field named "compressed" in case JSON output
mode is specified.  This is achieved by utilizing new allocation status
flag BDRV_BLOCK_COMPRESSED for bdrv_block_status().

Also update the expected qemu-iotests outputs to contain the new field.

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Message-ID: <20230907210226.953821-3-andrey.drobyshev@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Andrey Drobyshev via authored and kevmw committed Sep 15, 2023
1 parent f16f654 commit b769769
Show file tree
Hide file tree
Showing 16 changed files with 744 additions and 738 deletions.
6 changes: 4 additions & 2 deletions qapi/block-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@
#
# @zero: whether the virtual blocks read as zeroes
#
# @compressed: true if the data is stored compressed (since 8.2)
#
# @depth: number of layers (0 = top image, 1 = top image's backing
# file, ..., n - 1 = bottom image (where n is the number of images
# in the chain)) before reaching one for which the range is
Expand All @@ -426,8 +428,8 @@
##
{ 'struct': 'MapEntry',
'data': {'start': 'int', 'length': 'int', 'data': 'bool',
'zero': 'bool', 'depth': 'int', 'present': 'bool',
'*offset': 'int', '*filename': 'str' } }
'zero': 'bool', 'compressed': 'bool', 'depth': 'int',
'present': 'bool', '*offset': 'int', '*filename': 'str' } }

##
# @BlockdevCacheInfo:
Expand Down
8 changes: 6 additions & 2 deletions qemu-img.c
Original file line number Diff line number Diff line change
Expand Up @@ -3108,10 +3108,12 @@ static int dump_map_entry(OutputFormat output_format, MapEntry *e,
case OFORMAT_JSON:
printf("{ \"start\": %"PRId64", \"length\": %"PRId64","
" \"depth\": %"PRId64", \"present\": %s, \"zero\": %s,"
" \"data\": %s", e->start, e->length, e->depth,
" \"data\": %s, \"compressed\": %s",
e->start, e->length, e->depth,
e->present ? "true" : "false",
e->zero ? "true" : "false",
e->data ? "true" : "false");
e->data ? "true" : "false",
e->compressed ? "true" : "false");
if (e->has_offset) {
printf(", \"offset\": %"PRId64"", e->offset);
}
Expand Down Expand Up @@ -3172,6 +3174,7 @@ static int get_block_status(BlockDriverState *bs, int64_t offset,
.length = bytes,
.data = !!(ret & BDRV_BLOCK_DATA),
.zero = !!(ret & BDRV_BLOCK_ZERO),
.compressed = !!(ret & BDRV_BLOCK_COMPRESSED),
.offset = map,
.has_offset = has_offset,
.depth = depth,
Expand All @@ -3189,6 +3192,7 @@ static inline bool entry_mergeable(const MapEntry *curr, const MapEntry *next)
}
if (curr->zero != next->zero ||
curr->data != next->data ||
curr->compressed != next->compressed ||
curr->depth != next->depth ||
curr->present != next->present ||
!curr->filename != !next->filename ||
Expand Down
84 changes: 42 additions & 42 deletions tests/qemu-iotests/122.out
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ read 65536/65536 bytes at offset 4194304
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 65536/65536 bytes at offset 8388608
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 65536, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 4194304, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 4259840, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 8388608, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 8454144, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 65536, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 4194304, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 4259840, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 8388608, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 8454144, "length": 4128768, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]
read 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 65536/65536 bytes at offset 4194304
Expand All @@ -94,12 +94,12 @@ wrote 1024/1024 bytes at offset 1046528
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 1024/1024 bytes at offset 0
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 65536, "length": 65536, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 131072, "length": 196608, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 327680, "length": 655360, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 983040, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 1048576, "length": 1046528, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 65536, "length": 65536, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 131072, "length": 196608, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 327680, "length": 655360, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 983040, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 1048576, "length": 1046528, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]
read 16384/16384 bytes at offset 0
16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 16384/16384 bytes at offset 16384
Expand Down Expand Up @@ -130,14 +130,14 @@ read 3145728/3145728 bytes at offset 0
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 63963136/63963136 bytes at offset 3145728
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}]

convert -c -S 0:
read 3145728/3145728 bytes at offset 0
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 63963136/63963136 bytes at offset 3145728
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true}]
Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
wrote 33554432/33554432 bytes at offset 0
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Expand All @@ -152,7 +152,7 @@ read 30408704/30408704 bytes at offset 3145728
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 33554432/33554432 bytes at offset 33554432
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}]

convert -c -S 0 with source backing file:
read 3145728/3145728 bytes at offset 0
Expand All @@ -161,7 +161,7 @@ read 30408704/30408704 bytes at offset 3145728
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 33554432/33554432 bytes at offset 33554432
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true}]

convert -S 0 -B ...
read 3145728/3145728 bytes at offset 0
Expand All @@ -170,7 +170,7 @@ read 30408704/30408704 bytes at offset 3145728
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 33554432/33554432 bytes at offset 33554432
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}]

convert -c -S 0 -B ...
read 3145728/3145728 bytes at offset 0
Expand All @@ -179,7 +179,7 @@ read 30408704/30408704 bytes at offset 3145728
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 33554432/33554432 bytes at offset 33554432
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true}]

=== Non-zero -S ===

Expand All @@ -196,32 +196,32 @@ wrote 1024/1024 bytes at offset 66560
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

convert -S 4k
[{ "start": 0, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET},
{ "start": 4096, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 8192, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET},
{ "start": 12288, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 16384, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET},
{ "start": 20480, "length": 67088384, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
{ "start": 4096, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 8192, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
{ "start": 12288, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 16384, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
{ "start": 20480, "length": 67088384, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]

convert -c -S 4k
[{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 1024, "length": 7168, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 8192, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 9216, "length": 8192, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 17408, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 18432, "length": 67090432, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 1024, "length": 7168, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 8192, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 9216, "length": 8192, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 17408, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 18432, "length": 67090432, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]

convert -S 8k
[{ "start": 0, "length": 24576, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET},
{ "start": 24576, "length": 67084288, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 24576, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET},
{ "start": 24576, "length": 67084288, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]

convert -c -S 8k
[{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 1024, "length": 7168, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 8192, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 9216, "length": 8192, "depth": 0, "present": false, "zero": true, "data": false},
{ "start": 17408, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},
{ "start": 18432, "length": 67090432, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 1024, "length": 7168, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 8192, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 9216, "length": 8192, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false},
{ "start": 17408, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "compressed": true},
{ "start": 18432, "length": 67090432, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]

=== -n to a non-zero image ===

Expand All @@ -235,18 +235,18 @@ Images are identical.

Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": true, "data": false}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false}]
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
[{ "start": 0, "length": 67108864, "depth": 0, "present": false, "zero": true, "data": false}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": false, "zero": true, "data": false, "compressed": false}]

=== -n to an empty image with a backing file ===

Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864
Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": true, "data": false}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false}]
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "offset": 327680}]
[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": 327680}]

=== -n -B to an image without a backing file ===

Expand Down

0 comments on commit b769769

Please sign in to comment.