Skip to content

Commit a2adbbf

Browse files
Vladimir Sementsov-OgievskiyXanClic
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Signed-off-by: Max Reitz <[email protected]>
1 parent cdf9ebf commit a2adbbf

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

block/io.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
24062406

24072407
if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) {
24082408
ret |= BDRV_BLOCK_ALLOCATED;
2409-
} else if (want_zero) {
2409+
} else if (want_zero && bs->drv->supports_backing) {
24102410
if (bs->backing) {
24112411
BlockDriverState *bs2 = bs->backing->bs;
24122412
int64_t size2 = bdrv_getlength(bs2);
@@ -2415,12 +2415,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
24152415
ret |= BDRV_BLOCK_ZERO;
24162416
}
24172417
} 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;
24242419
}
24252420
}
24262421

block/qcow2.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4987,7 +4987,6 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
49874987
static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
49884988
{
49894989
BDRVQcow2State *s = bs->opaque;
4990-
bdi->unallocated_blocks_are_zero = true;
49914990
bdi->cluster_size = s->cluster_size;
49924991
bdi->vm_state_offset = qcow2_vm_state_offset(s);
49934992
return 0;

block/qed.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,6 @@ static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
15141514
memset(bdi, 0, sizeof(*bdi));
15151515
bdi->cluster_size = s->header.cluster_size;
15161516
bdi->is_dirty = s->header.features & QED_F_NEED_CHECK;
1517-
bdi->unallocated_blocks_are_zero = true;
15181517
return 0;
15191518
}
15201519

include/block/block.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ typedef struct BlockDriverInfo {
2121
/* offset at which the VM state can be saved (0 if not possible) */
2222
int64_t vm_state_offset;
2323
bool is_dirty;
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;
2924
/*
3025
* True if this block driver only supports compressed writes
3126
*/

include/block/block_int.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ struct BlockDriver {
123123
*/
124124
bool bdrv_needs_filename;
125125

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+
*/
127137
bool supports_backing;
128138

129139
/* For handling image reopen for split or non-split files */

0 commit comments

Comments
 (0)