mirror: Reduce I/O when destination is detect-zeroes:unmap

If we are going to punch holes in the mirror destination even for the
portions where the source image is unallocated, it is nicer to treat
the entire image as dirty and punch as we go, rather than pre-zeroing
the entire image just to re-do I/O to the allocated portions of the
image.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-ID: <20250513220142.535200-2-eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Eric Blake 2025-05-13 17:00:45 -05:00
parent c0ddcb2cbc
commit aff46b4bf5

View File

@ -920,11 +920,16 @@ static int coroutine_fn GRAPH_UNLOCKED mirror_dirty_init(MirrorBlockJob *s)
* zeroing happened externally (ret > 0) or if we have a fast
* way to pre-zero the image (the dirty bitmap will be
* populated later by the non-zero portions, the same as for
* TOP mode). If pre-zeroing is not fast, then our only
* recourse is to mark the entire image dirty. The act of
* pre-zeroing will populate the zero bitmap.
* TOP mode). If pre-zeroing is not fast, or we need to visit
* the entire image in order to punch holes even in the
* non-allocated regions of the source, then just mark the
* entire image dirty and leave the zero bitmap clear at this
* point in time. Otherwise, it can be faster to pre-zero the
* image now, even if we re-write the allocated portions of
* the disk later, and the pre-zero pass will populate the
* zero bitmap.
*/
if (!bdrv_can_write_zeroes_with_unmap(target_bs)) {
if (!bdrv_can_write_zeroes_with_unmap(target_bs) || punch_holes) {
bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length);
return 0;
}