qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block: drop unallocated_blocks_are_zero

Currently this field only set by qed and qcow2. But in fact, all
backing-supporting formats (parallels, qcow, qcow2, qed, vmdk) share
these semantics: on unallocated blocks, if there is no backing file they
just memset the buffer with zeroes.

So, document this behavior for .supports_backing and drop
.unallocated_blocks_are_zero

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200528094405.145708-10-vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Vladimir Sementsov-Ogievskiy and committed by
Max Reitz
a2adbbf6 cdf9ebf1

+13 -15
+2 -7
block/io.c
··· 2406 2406 2407 2407 if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) { 2408 2408 ret |= BDRV_BLOCK_ALLOCATED; 2409 - } else if (want_zero) { 2409 + } else if (want_zero && bs->drv->supports_backing) { 2410 2410 if (bs->backing) { 2411 2411 BlockDriverState *bs2 = bs->backing->bs; 2412 2412 int64_t size2 = bdrv_getlength(bs2); ··· 2415 2415 ret |= BDRV_BLOCK_ZERO; 2416 2416 } 2417 2417 } else { 2418 - BlockDriverInfo bdi; 2419 - int ret2 = bdrv_get_info(bs, &bdi); 2420 - 2421 - if (ret2 == 0 && bdi.unallocated_blocks_are_zero) { 2422 - ret |= BDRV_BLOCK_ZERO; 2423 - } 2418 + ret |= BDRV_BLOCK_ZERO; 2424 2419 } 2425 2420 } 2426 2421
-1
block/qcow2.c
··· 4987 4987 static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) 4988 4988 { 4989 4989 BDRVQcow2State *s = bs->opaque; 4990 - bdi->unallocated_blocks_are_zero = true; 4991 4990 bdi->cluster_size = s->cluster_size; 4992 4991 bdi->vm_state_offset = qcow2_vm_state_offset(s); 4993 4992 return 0;
-1
block/qed.c
··· 1514 1514 memset(bdi, 0, sizeof(*bdi)); 1515 1515 bdi->cluster_size = s->header.cluster_size; 1516 1516 bdi->is_dirty = s->header.features & QED_F_NEED_CHECK; 1517 - bdi->unallocated_blocks_are_zero = true; 1518 1517 return 0; 1519 1518 } 1520 1519
-5
include/block/block.h
··· 22 22 int64_t vm_state_offset; 23 23 bool is_dirty; 24 24 /* 25 - * True if unallocated blocks read back as zeroes. This is equivalent 26 - * to the LBPRZ flag in the SCSI logical block provisioning page. 27 - */ 28 - bool unallocated_blocks_are_zero; 29 - /* 30 25 * True if this block driver only supports compressed writes 31 26 */ 32 27 bool needs_compressed_writes;
+11 -1
include/block/block_int.h
··· 123 123 */ 124 124 bool bdrv_needs_filename; 125 125 126 - /* Set if a driver can support backing files */ 126 + /* 127 + * Set if a driver can support backing files. This also implies the 128 + * following semantics: 129 + * 130 + * - Return status 0 of .bdrv_co_block_status means that corresponding 131 + * blocks are not allocated in this layer of backing-chain 132 + * - For such (unallocated) blocks, read will: 133 + * - fill buffer with zeros if there is no backing file 134 + * - read from the backing file otherwise, where the block layer 135 + * takes care of reading zeros beyond EOF if backing file is short 136 + */ 127 137 bool supports_backing; 128 138 129 139 /* For handling image reopen for split or non-split files */