bitmaps patches for 2020-05-26
The following changes since commit a20ab81d22300cca80325c284f21eefee99aa740:
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-05-28' into staging (2020-05-28 16:18:06 +0100)
are available in the Git repository at:
https://repo.or.cz/qemu/ericb.git tags/pull-bitmaps-2020-05-26-v3
for you to fetch changes up to cf2d1203dcfc2bf964453d83a2302231ce77f2dc:
iotests: Add test 291 to for qemu-img bitmap coverage (2020-05-28 13:16:30 -0500)
v3: port sed expression to BSD sed
v2: fix iotest 190 to not be as sensitive to different sparseness of qcow2 file on various filesystems, such as FreeBSD (sending only the changed patch)
----------------------------------------------------------------
bitmaps patches for 2020-05-26
- fix non-blockdev migration of bitmaps when mirror job is in use
- add bitmap sizing to 'qemu-img measure'
- add 'qemu-img convert --bitmaps'
----------------------------------------------------------------
Eric Blake (5):
iotests: Fix test 178
qcow2: Expose bitmaps' size during measure
qemu-img: Factor out code for merging bitmaps
qemu-img: Add convert --bitmaps option
iotests: Add test 291 to for qemu-img bitmap coverage
Vladimir Sementsov-Ogievskiy (6):
migration: refactor init_dirty_bitmap_migration block/dirty-bitmap: add bdrv_has_named_bitmaps helper
migration: fix bitmaps pre-blockdev migration with mirror job
iotests: 194: test also migration of dirty bitmap
migration: add_bitmaps_to_list: check disk name once
migration: forbid bitmap migration by generated node-name
docs/tools/qemu-img.rst | 13 +++- qapi/block-core.json | 16 +++-- block/qcow2.h | 2 + include/block/dirty-bitmap.h | 1 + block/crypto.c | 2 +- block/dirty-bitmap.c | 13 ++++ block/qcow2-bitmap.c | 36 ++++++++++ block/qcow2.c | 14 +++- block/raw-format.c | 2 +- migration/block-dirty-bitmap.c | 142 ++++++++++++++++++++++++++++----------- qemu-img.c | 107 ++++++++++++++++++++++++----- qemu-img-cmds.hx | 4 +- tests/qemu-iotests/178.out.qcow2 | 18 ++++- tests/qemu-iotests/178.out.raw | 2 +- tests/qemu-iotests/190 | 47 ++++++++++++- tests/qemu-iotests/190.out | 27 +++++++- tests/qemu-iotests/194 | 14 ++-- tests/qemu-iotests/194.out | 6 ++ tests/qemu-iotests/291 | 112 ++++++++++++++++++++++++++++++ tests/qemu-iotests/291.out | 80 ++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 21 files changed, 582 insertions(+), 77 deletions(-) create mode 100755 tests/qemu-iotests/291 create mode 100644 tests/qemu-iotests/291.out
Signature · 1 line
2.26.2
[PULL v3 08/11] qcow2: Expose bitmaps' size during measure
It's useful to know how much space can be occupied by qcow2 persistent bitmaps, even though such metadata is unrelated to the guest-visible data. Report this value as an additional QMP field, present when measuring an existing image and output format that both support bitmaps. Update iotest 178 and 190 to updated output, as well as new coverage in 190 demonstrating non-zero values made possible with the recently-added qemu-img bitmap command (see 3b51ab4b).
The new 'bitmaps size:' field is displayed automatically as part of 'qemu-img measure' any time it is present in QMP (that is, any time both the source image being measured and destination format support bitmaps, even if the measurement is 0 because there are no bitmaps present). If the field is absent, it means that no bitmaps can be copied (source, destination, or both lack bitmaps, including when measuring based on size rather than on a source image). This behavior is compatible with an upcoming patch adding 'qemu-img convert --bitmaps': that command will fail in the same situations where this patch omits the field.
The addition of a new field demonstrates why we should always zero-initialize qapi C structs; while the qcow2 driver still fully populates all fields, the raw and crypto drivers had to be tweaked to avoid uninitialized data.
Consideration was also given towards having a 'qemu-img measure --bitmaps' which errors out when bitmaps are not possible, and otherwise sums the bitmaps into the existing allocation totals rather than displaying as a separate field, as a potential convenience factor. But this was ultimately decided to be more complexity than necessary when the QMP interface was sufficient enough with bitmaps remaining a separate field.
See also: https://bugzilla.redhat.com/1779904
Message-Id: <[email protected]>
--- docs/tools/qemu-img.rst | 7 +++++ qapi/block-core.json | 16 +++++++---- block/qcow2.h | 2 ++ block/crypto.c | 2 +- block/qcow2-bitmap.c | 36 ++++++++++++++++++++++++ block/qcow2.c | 14 ++++++++-- block/raw-format.c | 2 +- qemu-img.c | 3 ++ tests/qemu-iotests/178.out.qcow2 | 16 +++++++++++ tests/qemu-iotests/190 | 47 ++++++++++++++++++++++++++++++-- tests/qemu-iotests/190.out | 27 +++++++++++++++++- 11 files changed, 159 insertions(+), 13 deletions(-)
docs/tools/qemu-img.rst +7 -0
@@ -616,6 +616,7 @@ Command description: required size: 524288 fully allocated size: 1074069504 + bitmaps size: 0 The ``required size`` is the file size of the new image. It may be smaller than the virtual disk size if the image format supports compact representation.
@@ -625,6 +626,12 @@ Command description: occupy with the exception of internal snapshots, dirty bitmaps, vmstate data, and other advanced image format features. + The ``bitmaps size`` is the additional size required in order to + copy bitmaps from a source image in addition to the guest-visible + data; the line is omitted if either source or destination lacks + bitmap support, or 0 if bitmaps are supported but there is nothing + to copy. + .. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME List, apply, create or delete snapshots in image *FILENAME*.
qapi/block-core.json +11 -5
@@ -636,18 +636,24 @@ # efficiently so file size may be smaller than virtual disk size. # # The values are upper bounds that are guaranteed to fit the new image file. -# Subsequent modification, such as internal snapshot or bitmap creation, may -# require additional space and is not covered here. +# Subsequent modification, such as internal snapshot or further bitmap +# creation, may require additional space and is not covered here. # -# @required: Size required for a new image file, in bytes. +# @required: Size required for a new image file, in bytes, when copying just +# allocated guest-visible contents. # # @fully-allocated: Image file size, in bytes, once data has been written -# to all sectors. +# to all sectors, when copying just guest-visible contents. +# +# @bitmaps: Additional size required if all the top-level bitmap metadata +# in the source image were to be copied to the destination, +# present only when source and destination both support +# persistent bitmaps. (since 5.1) # # Since: 2.10 ## { 'struct': 'BlockMeasureInfo', - 'data': {'required': 'int', 'fully-allocated': 'int'} } + 'data': {'required': 'int', 'fully-allocated': 'int', '*bitmaps': 'int'} } ## # @query-block:
block/qcow2.h +2 -0
@@ -783,6 +783,8 @@ int qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs,const char *name, Error **errp);bool qcow2_supports_persistent_dirty_bitmap (BlockDriverState *bs); +uint64_t qcow2_get_persistent_dirty_bitmap_size (BlockDriverState *bs, +uint32_t cluster_size); ssize_t coroutine_fn qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
block/crypto.c +1 -1
@@ -552,7 +552,7 @@ static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts,* Unallocated blocks are still encrypted so allocation status makes no * difference to the file size. */ - info =g_new (BlockMeasureInfo,1 ); + info =g_new0 (BlockMeasureInfo,1 ); info->fully_allocated = luks_payload_size + size; info->required = luks_payload_size + size;return info;
block/qcow2-bitmap.c +36 -0
@@ -1755,3 +1755,39 @@ bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs)return s->qcow_version >=3 ; } + +/* +* Compute the space required for bitmaps in @bs. +* +* The computation is based as if copying to a new image with the +* given @cluster_size, which may differ from the cluster size in @bs. +*/ +uint64_t qcow2_get_persistent_dirty_bitmap_size (BlockDriverState *bs, +uint32_t cluster_size) +{ +uint64_t bitmaps_size =0 ; +BdrvDirtyBitmap *bm; +size_t bitmap_dir_size =0 ; + + FOR_EACH_DIRTY_BITMAP(bs, bm) { +if (bdrv_dirty_bitmap_get_persistence (bm)) { +const char *name =bdrv_dirty_bitmap_name (bm); +uint32_t granularity =bdrv_dirty_bitmap_granularity (bm); +uint64_t bmbytes = +get_bitmap_bytes_needed (bdrv_dirty_bitmap_size (bm), + granularity); +uint64_t bmclusters =DIV_ROUND_UP (bmbytes, cluster_size); + +/* Assume the entire bitmap is allocated */ + bitmaps_size += bmclusters * cluster_size; +/* Also reserve space for the bitmap table entries */ + bitmaps_size +=ROUND_UP (bmclusters *sizeof (uint64_t ), + cluster_size); +/* And space for contribution to bitmap directory size */ + bitmap_dir_size +=calc_dir_entry_size (strlen (name),0 ); + } + } + bitmaps_size +=ROUND_UP (bitmap_dir_size, cluster_size); + +return bitmaps_size; +}
block/qcow2.c +11 -3
@@ -4953,16 +4953,24 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs, required = virtual_size; } - info =g_new (BlockMeasureInfo,1 ); + info =g_new0 (BlockMeasureInfo,1 ); info->fully_allocated =qcow2_calc_prealloc_size (virtual_size, cluster_size,ctz32 (refcount_bits)) + luks_payload_size; -/* Remove data clusters that are not required. This overestimates the +/* +* Remove data clusters that are not required. This overestimates the * required size because metadata needed for the fully allocated file is -* still counted. +* still counted. Show bitmaps only if both source and destination +* would support them. */ info->required = info->fully_allocated - virtual_size + required; + info->has_bitmaps = version >=3 && in_bs && +bdrv_supports_persistent_dirty_bitmap (in_bs); +if (info->has_bitmaps) { + info->bitmaps =qcow2_get_persistent_dirty_bitmap_size (in_bs, + cluster_size); + }return info; err:
block/raw-format.c +1 -1
@@ -359,7 +359,7 @@ static BlockMeasureInfo *raw_measure(QemuOpts *opts, BlockDriverState *in_bs, BDRV_SECTOR_SIZE); } - info =g_new (BlockMeasureInfo,1 ); + info =g_new0 (BlockMeasureInfo,1 ); info->required = required;/* Unallocated sectors count towards the file size in raw images */
qemu-img.c +3 -0
@@ -5302,6 +5302,9 @@ static int img_measure(int argc, char **argv)if (output_format ==OFORMAT_HUMAN ) {printf ("required size: %" PRIu64"\n" , info->required);printf ("fully allocated size: %" PRIu64"\n" , info->fully_allocated); +if (info->has_bitmaps) { +printf ("bitmaps size: %" PRIu64"\n" , info->bitmaps); + } }else {dump_json_block_measure_info (info); }
tests/qemu-iotests/178.out.qcow2 +16 -0
@@ -37,6 +37,7 @@ qemu-img: The image size is too large (try using a larger cluster size) Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 required size: 196608 fully allocated size: 196608 +bitmaps size: 0 converted image file size in bytes: 196608
@@ -45,6 +46,7 @@ converted image file size in bytes: 196608 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 required size: 393216 fully allocated size: 1074135040 +bitmaps size: 0 wrote 512/512 bytes at offset 512 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 65536/65536 bytes at offset 65536
@@ -53,6 +55,7 @@ wrote 64512/64512 bytes at offset 134217728 63 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) required size: 589824 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 524288
@@ -60,6 +63,7 @@ converted image file size in bytes: 524288 required size: 524288 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 458752
@@ -67,16 +71,19 @@ converted image file size in bytes: 458752 required size: 1074135040 fully allocated size: 1074135040 +bitmaps size: 0 == qcow2 input image and LUKS encryption == required size: 2686976 fully allocated size: 1076232192 +bitmaps size: 0 == qcow2 input image and preallocation (human) == required size: 1074135040 fully allocated size: 1074135040 +bitmaps size: 0 converted image file size in bytes: 1074135040
@@ -87,6 +94,7 @@ wrote 8388608/8388608 bytes at offset 0 8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) required size: 8716288 fully allocated size: 8716288 +bitmaps size: 0 converted image file size in bytes: 8716288
@@ -173,6 +181,7 @@ qemu-img: The image size is too large (try using a larger cluster size) Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 { + "bitmaps": 0, "required": 196608, "fully-allocated": 196608 }
@@ -183,6 +192,7 @@ converted image file size in bytes: 196608 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 { + "bitmaps": 0, "required": 393216, "fully-allocated": 1074135040 }
@@ -193,6 +203,7 @@ wrote 65536/65536 bytes at offset 65536 wrote 64512/64512 bytes at offset 134217728 63 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) { + "bitmaps": 0, "required": 589824, "fully-allocated": 1074135040 }
@@ -202,6 +213,7 @@ converted image file size in bytes: 524288 == qcow2 input image with internal snapshot (json) == { + "bitmaps": 0, "required": 524288, "fully-allocated": 1074135040 }
@@ -211,6 +223,7 @@ converted image file size in bytes: 458752 == qcow2 input image and a backing file (json) == { + "bitmaps": 0, "required": 1074135040, "fully-allocated": 1074135040 }
@@ -218,6 +231,7 @@ converted image file size in bytes: 458752 == qcow2 input image and LUKS encryption == { + "bitmaps": 0, "required": 2686976, "fully-allocated": 1076232192 }
@@ -225,6 +239,7 @@ converted image file size in bytes: 458752 == qcow2 input image and preallocation (json) == { + "bitmaps": 0, "required": 1074135040, "fully-allocated": 1074135040 }
@@ -237,6 +252,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=8388608 wrote 8388608/8388608 bytes at offset 0 8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) { + "bitmaps": 0, "required": 8716288, "fully-allocated": 8716288 }
tests/qemu-iotests/190 +45 -2
65 lines not on this page · raw message
tests/qemu-iotests/190.out +26 -1
@@ -1,11 +1,36 @@ QA output created by 190 -== Huge file == +== Huge file without bitmaps == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2199023255552 required size: 2199023255552 fully allocated size: 2199023255552 required size: 335806464 fully allocated size: 2199359062016 +bitmaps size: 0 required size: 18874368 fully allocated size: 2199042129920 +bitmaps size: 0 + +== Huge file with bitmaps == + +required size: 327680 +fully allocated size: 10813440 +required size: 2199023255552 +fully allocated size: 2199023255552 +required size: SIZE +fully allocated size: 17170432 +required size: 335806464 +fully allocated size: 2199359062016 + +expected bitmap 537198592 +required size: 335806464 +fully allocated size: 2199359062016 +bitmaps size: 537198592 + +expected bitmap 545259520 +{ + "bitmaps": 545259520, + "required": 18874368, + "fully-allocated": 2199042129920 +} *** done
Signature · 1 line
2.26.2
Hi!
Strange thing with your pull requests: I receive only small part of them.. I thought it's my problem of receiving part, but now I've checked that in mailing list archive there are same only two emails: 00/11 and 08/11 https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08061.html
Quoted 65 lines · Eric Blake
The following changes since commit
a20ab81d22300cca80325c284f21eefee99aa740:Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-05-28' into staging (2020-05-28 16:18:06 +0100)are available in the Git repository at:
https://repo.or.cz/qemu/ericb.git tags/pull-bitmaps-2020-05-26-v3for you to fetch changes up to
cf2d1203dcfc2bf964453d83a2302231ce77f2dc:iotests: Add test 291 to for qemu-img bitmap coverage (2020-05-28 13:16:30 -0500)v3: port sed expression to BSD sed
v2: fix iotest 190 to not be as sensitive to different sparseness of qcow2 file on various filesystems, such as FreeBSD (sending only the changed patch)----------------------------------------------------------------
bitmaps patches for 2020-05-26- fix non-blockdev migration of bitmaps when mirror job is in use
- add bitmap sizing to 'qemu-img measure'
- add 'qemu-img convert --bitmaps'----------------------------------------------------------------
Eric Blake (5):
iotests: Fix test 178
qcow2: Expose bitmaps' size during measure
qemu-img: Factor out code for merging bitmaps
qemu-img: Add convert --bitmaps option
iotests: Add test 291 to for qemu-img bitmap coverageVladimir Sementsov-Ogievskiy (6):
migration: refactorinit_dirty_bitmap_migrationblock/dirty-bitmap: addbdrv_has_named_bitmapshelper
migration: fix bitmaps pre-blockdev migration with mirror job
iotests: 194: test also migration of dirty bitmap
migration:add_bitmaps_to_list: check disk name once
migration: forbid bitmap migration by generated node-namedocs/tools/qemu-img.rst | 13 +++- qapi/block-core.json | 16 +++-- block/qcow2.h | 2 + include/block/dirty-bitmap.h | 1 + block/crypto.c | 2 +- block/dirty-bitmap.c | 13 ++++ block/qcow2-bitmap.c | 36 ++++++++++ block/qcow2.c | 14 +++- block/raw-format.c | 2 +- migration/block-dirty-bitmap.c | 142 ++++++++++++++++++++++++++++----------- qemu-img.c | 107 ++++++++++++++++++++++++----- qemu-img-cmds.hx | 4 +- tests/qemu-iotests/178.out.qcow2 | 18 ++++- tests/qemu-iotests/178.out.raw | 2 +- tests/qemu-iotests/190 | 47 ++++++++++++- tests/qemu-iotests/190.out | 27 +++++++- tests/qemu-iotests/194 | 14 ++-- tests/qemu-iotests/194.out | 6 ++ tests/qemu-iotests/291 | 112 ++++++++++++++++++++++++++++++ tests/qemu-iotests/291.out | 80 ++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 21 files changed, 582 insertions(+), 77 deletions(-)create mode 100755 tests/qemu-iotests/291
create mode 100644 tests/qemu-iotests/291.out
Signature · 2 lines
Best regards, Vladimir
Quoted 4 lines · Vladimir Sementsov-Ogievskiy
Hi!
Strange thing with your pull requests: I receive only small part of them.. I thought it's my problem of receiving part, but now I've checked that in mailing list archive there are same only two emails: 00/11 and 08/11 https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08061.html
The convention when resending a pullreq which has had to be respun with a minor fixup is to send only the coverletter and any significantly changed patches, on the basis that there's no need to spam the list with the whole set of emails again. You can see that for v1 the whole set was sent:
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07419.html
thanks
-- PMM
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Hi!
Strange thing with your pull requests: I receive only small part of them.. I thought it's my problem of receiving part, but now I've checked that in mailing list archive there are same only two emails: 00/11 and 08/11 https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08061.html
It was intentional for both v2 and v3:
Quoted 8 lines
Quoted 5 lines · Eric Blake
v3: port sed expression to BSD sed
v2: fix iotest 190 to not be as sensitive to different sparseness of qcow2 file on various filesystems, such as FreeBSD (sending only the changed patch)
and I even tried to mention what I was doing, although I also see how it could have been easy to miss that buried in the middle of the cover letter.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Peter Maydell
AppliedQuoted 18 lines · Eric Blake
The following changes since commit
a20ab81d22300cca80325c284f21eefee99aa740:Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-05-28' into staging (2020-05-28 16:18:06 +0100)
are available in the Git repository at:
https://repo.or.cz/qemu/ericb.git tags/pull-bitmaps-2020-05-26-v3
for you to fetch changes up to
cf2d1203dcfc2bf964453d83a2302231ce77f2dc:iotests: Add test 291 to for qemu-img bitmap coverage (2020-05-28 13:16:30 -0500)
v3: port sed expression to BSD sed
v2: fix iotest 190 to not be as sensitive to different sparseness of qcow2 file on various filesystems, such as FreeBSD (sending only the changed patch)
Quoted 7 lines
----------------------------------------------------------------
bitmaps patches for 2020-05-26- fix non-blockdev migration of bitmaps when mirror job is in use
- add bitmap sizing to 'qemu-img measure'
- add 'qemu-img convert --bitmaps'
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.
-- PMM