drop unallocated_blocks_are_zero
v3 cover drop unallocated_blocks_are_zero
This is first step to block-status refactoring, and solves most simple problem mentioned in my investigation of block-status described in the thread "backing chain & block status & filters":
https://lists.gnu.org/archive/html/qemu-devel/2020-04/msg04706.html
The whole series is reviewed, let's proceed with it please!
v3: rebase on master
02: grammar fix in commit msg, add Eric's r-b
03,04,09: add Eric's r-b
10: add my r-b
Eric Blake (1):
qed: Simplify backing reads
Vladimir Sementsov-Ogievskiy (9):
qemu-img: convert: don't use unallocated_blocks_are_zero
block: inline bdrv_unallocated_blocks_are_zero() block/vdi: return ZERO block-status when appropriate block/vpc: return ZERO block-status when appropriate block/crypto: drop unallocated_blocks_are_zero block/iscsi: drop unallocated_blocks_are_zero block/file-posix: drop unallocated_blocks_are_zero block/vhdx: drop unallocated_blocks_are_zero
block: drop unallocated_blocks_are_zero
block/qed.h | 1 - include/block/block.h | 6 ---- include/block/block_int.h | 12 +++++++- block.c | 15 --------- block/crypto.c | 1 - block/file-posix.c | 3 -- block/io.c | 8 ++--- block/iscsi.c | 1 - block/qcow2.c | 1 - block/qed.c | 65 ++++----------------------------------- block/vdi.c | 3 +- block/vhdx.c | 3 -- block/vpc.c | 3 +- qemu-img.c | 4 +-- 14 files changed, 24 insertions(+), 102 deletions(-)
Signature · 1 line
2.18.0
PATCH v3 1/10 qemu-img: convert: don't use unallocated_blocks_are_zero
qemu-img convert wants to distinguish ZERO which comes from short backing files. unallocated_blocks_are_zero field of bdi is unrelated:
space after EOF is always considered to be zero anyway. So, just make post_backing_zero true in case of short backing file.
--- qemu-img.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
qemu-img.c +1 -3
@@ -1660,7 +1660,6 @@ typedef struct ImgConvertState {BlockBackend *target;bool has_zero_init;bool compressed; -bool unallocated_blocks_are_zero;bool target_is_new;bool target_has_backing;int64_t target_backing_sectors;/* negative if unknown */
@@ -1705,7 +1704,7 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)if (s->target_backing_sectors >=0 ) {if (sector_num >= s->target_backing_sectors) { - post_backing_zero = s->unallocated_blocks_are_zero; + post_backing_zero = true; }else if (sector_num + n > s->target_backing_sectors) {/* Split requests around target_backing_sectors (because * starting from there, zeros are handled differently) */
@@ -2610,7 +2609,6 @@ static int img_convert(int argc, char **argv) }else { s.compressed = s.compressed || bdi.needs_compressed_writes; s.cluster_sectors = bdi.cluster_size /BDRV_SECTOR_SIZE ; - s.unallocated_blocks_are_zero = bdi.unallocated_blocks_are_zero; } ret =convert_do_copy (&s);
Signature · 1 line
2.18.0
PATCH v3 2/10 block: inline bdrv_unallocated_blocks_are_zero()
In reply to Vladimir Sementsov-OgievskiyThe function has only one user: bdrv_co_block_status(). Inline it to simplify reviewing of the following patches, which will finally drop unallocated_blocks_are_zero field too.
--- include/block/block.h | 1 - block.c | 15 --------------- block/io.c | 11 ++++++++--- 3 files changed, 8 insertions(+), 19 deletions(-)
include/block/block.h +0 -1
@@ -488,7 +488,6 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes);int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);int bdrv_has_zero_init_1 (BlockDriverState *bs);int bdrv_has_zero_init (BlockDriverState *bs); -bool bdrv_unallocated_blocks_are_zero (BlockDriverState *bs);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map,
block.c +0 -15
@@ -5408,21 +5408,6 @@ int bdrv_has_zero_init(BlockDriverState *bs)return 0 ; } -bool bdrv_unallocated_blocks_are_zero (BlockDriverState *bs) -{ -BlockDriverInfo bdi; - -if (bs->backing) { -return false; - } - -if (bdrv_get_info (bs, &bdi) ==0 ) { -return bdi.unallocated_blocks_are_zero; - } - -return false; -} -bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs) {if (!(bs->open_flags &BDRV_O_UNMAP )) {
block/io.c +8 -3
@@ -2387,15 +2387,20 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,if (ret & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) { ret |=BDRV_BLOCK_ALLOCATED ; }else if (want_zero) { -if (bdrv_unallocated_blocks_are_zero (bs)) { - ret |=BDRV_BLOCK_ZERO ; - }else if (bs->backing) { +if (bs->backing) {BlockDriverState *bs2 = bs->backing->bs;int64_t size2 =bdrv_getlength (bs2);if (size2 >=0 && offset >= size2) { ret |=BDRV_BLOCK_ZERO ; } + }else { +BlockDriverInfo bdi; +int ret2 =bdrv_get_info (bs, &bdi); + +if (ret2 ==0 && bdi.unallocated_blocks_are_zero) { + ret |=BDRV_BLOCK_ZERO ; + } } }
Signature · 1 line
2.18.0
PATCH v3 3/10 block/vdi: return ZERO block-status when appropriate
In reply to Vladimir Sementsov-OgievskiyIn case of !VDI_IS_ALLOCATED[], we do zero out the corresponding chunk of qiov. So, this should be reported as ZERO.
Note that this changes visible output of "qemu-img map --output=json" and "qemu-io -c map" commands. For qemu-img map, the change is obvious:
we just mark as zero what is really zero. For qemu-io it's less
obvious: what was unallocated now is allocated.
There is an inconsistency in understanding of unallocated regions in
Qemu: backing-supporting format-drivers return 0 block-status to report go-to-backing logic for this area. Some protocol-drivers (iscsi) return 0 to report fs-unallocated-non-zero status (i.e., don't occupy space on disk, read result is undefined).
BDRV_BLOCK_ALLOCATED is defined as something more close to go-to-backing logic. Still it is calculated as ZERO | DATA, so 0 from iscsi is treated as unallocated. It doesn't influence backing-chain behavior, as iscsi can't have backing file. But it does influence "qemu-io -c map".
We should solve this inconsistency at some future point. Now, let's just make backing-not-supporting format drivers (vdi at this patch and vpc with the following) to behave more like backing-supporting drivers and not report 0 block-status. More over, returning ZERO status is absolutely valid thing, and again, corresponds to how the other format-drivers (backing-supporting) work.
After block-status update, it never reports 0, so setting unallocated_blocks_are_zero doesn't make sense (as the only user of it is bdrv_co_block_status and it checks unallocated_blocks_are_zero only for unallocated areas). Drop it.
--- block/vdi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/vdi.c +1 -2
@@ -334,7 +334,6 @@ static int vdi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)logout ("\n" ); bdi->cluster_size = s->block_size; bdi->vm_state_offset =0 ; - bdi->unallocated_blocks_are_zero = true;return 0 ; }
@@ -536,7 +535,7 @@ static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, *pnum =MIN (s->block_size - index_in_block, bytes); result =VDI_IS_ALLOCATED (bmap_entry);if (!result) { -return 0 ; +return BDRV_BLOCK_ZERO ; } *map = s->header.offset_data + (uint64_t)bmap_entry * s->block_size +
Signature · 1 line
2.18.0
PATCH v3 4/10 block/vpc: return ZERO block-status when appropriate
In reply to Vladimir Sementsov-OgievskiyIn case when get_image_offset() returns -1, we do zero out the corresponding chunk of qiov. So, this should be reported as ZERO.
Note that this changes visible output of "qemu-img map --output=json" and "qemu-io -c map" commands. For qemu-img map, the change is obvious:
we just mark as zero what is really zero. For qemu-io it's less
obvious: what was unallocated now is allocated.
There is an inconsistency in understanding of unallocated regions in
Qemu: backing-supporting format-drivers return 0 block-status to report go-to-backing logic for this area. Some protocol-drivers (iscsi) return 0 to report fs-unallocated-non-zero status (i.e., don't occupy space on disk, read result is undefined).
BDRV_BLOCK_ALLOCATED is defined as something more close to go-to-backing logic. Still it is calculated as ZERO | DATA, so 0 from iscsi is treated as unallocated. It doesn't influence backing-chain behavior, as iscsi can't have backing file. But it does influence "qemu-io -c map".
We should solve this inconsistency at some future point. Now, let's just make backing-not-supporting format drivers (vdi in the previous patch and vpc now) to behave more like backing-supporting drivers and not report 0 block-status. More over, returning ZERO status is absolutely valid thing, and again, corresponds to how the other format-drivers (backing-supporting) work.
After block-status update, it never reports 0, so setting unallocated_blocks_are_zero doesn't make sense (as the only user of it is bdrv_co_block_status and it checks unallocated_blocks_are_zero only for unallocated areas). Drop it.
--- block/vpc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/vpc.c +1 -2
@@ -606,7 +606,6 @@ static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) bdi->cluster_size = s->block_size; } - bdi->unallocated_blocks_are_zero = true;return 0 ; }
@@ -745,7 +744,7 @@ static int coroutine_fn vpc_co_block_status(BlockDriverState *bs, image_offset =get_image_offset (bs, offset, false,NULL ); allocated = (image_offset !=-1 ); *pnum =0 ; - ret =0 ; + ret =BDRV_BLOCK_ZERO ; do { /* All sectors in a block are contiguous (without using the bitmap) */
Signature · 1 line
2.18.0
Re: [PATCH v3 04/10] block/vpc: return ZERO block-status when appropriate
Quoted 32 lines · Vladimir Sementsov-Ogievskiy
In case when
get_image_offset()returns -1, we do zero out the corresponding chunk of qiov. So, this should be reported as ZERO.Note that this changes visible output of "qemu-img map --output=json" and "qemu-io -c map" commands. For qemu-img map, the change is obvious:
we just mark as zero what is really zero. For qemu-io it's less
obvious: what was unallocated now is allocated.There is an inconsistency in understanding of unallocated regions in
Qemu: backing-supporting format-drivers return 0 block-status to report go-to-backing logic for this area. Some protocol-drivers (iscsi) return 0 to report fs-unallocated-non-zero status (i.e., don't occupy space on disk, read result is undefined).
BDRV_BLOCK_ALLOCATEDis defined as something more close to go-to-backing logic. Still it is calculated as ZERO | DATA, so 0 from iscsi is treated as unallocated. It doesn't influence backing-chain behavior, as iscsi can't have backing file. But it does influence "qemu-io -c map".We should solve this inconsistency at some future point. Now, let's just make backing-not-supporting format drivers (vdi in the previous patch and vpc now) to behave more like backing-supporting drivers and not report 0 block-status. More over, returning ZERO status is absolutely valid thing, and again, corresponds to how the other format-drivers (backing-supporting) work.
After block-status update, it never reports 0, so setting
unallocated_blocks_are_zerodoesn't make sense (as the only user of it isbdrv_co_block_statusand it checksunallocated_blocks_are_zeroonly for unallocated areas). Drop it.
Quoted 5 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Eric Blake <[email protected]>--- block/vpc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
This breaks iotest 146, I’m afraid. Now everything is reported as allocated, which is of course what we kind of want, but I suppose it renders the test a bit useless.
It seems to me like the best thing to do would be to replace the “qemu-io -o $opts -c map” calls by
“qemu-img map --output=json --image-opts $opts”, so that we get “zero: true” instead of “not allocated” in the output.
A bit of a problem with that approach are the “allocated” entries, because those are split into 2 MB chunks, so the output gets long. But, well.
I’ve attached a diff to that effect. Would you be OK with squashing that in?
Max
tests/qemu-iotests/146 +45 -15
@@ -51,19 +51,25 @@ echo === Testing VPC Autodetect === echo _use_sample_img virtualpc-dynamic.vhd.bz2 -${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing VPC with current_size force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing VPC with chs force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map _cleanup_test_img
@@ -72,19 +78,25 @@ echo === Testing Hyper-V Autodetect === echo _use_sample_img hyperv2012r2-dynamic.vhd.bz2 -${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing Hyper-V with current_size force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing Hyper-V with chs force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map _cleanup_test_img
@@ -93,19 +105,25 @@ echo === Testing d2v Autodetect === echo _use_sample_img d2v-zerofilled.vhd.bz2 -${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing d2v with current_size force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing d2v with chs force === echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map _cleanup_test_img
@@ -121,19 +139,25 @@ echo echo === Read created image, default opts ==== echo -${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Read created image, force_size_calc=chs ==== echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Read created image, force_size_calc=current_size ==== echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Testing Image create, force_size ===
@@ -145,19 +169,25 @@ echo echo === Read created image, default opts ==== echo -${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Read created image, force_size_calc=chs ==== echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo echo === Read created image, force_size_calc=current_size ==== echo -${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map' +$QEMU_IMG map --output=json --image-opts \ + "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \ + | _filter_qemu_img_map echo "*** done" rm -f $seq.full
tests/qemu-iotests/146.out +390 -15
457 lines not on this page · raw message
Re: [PATCH v3 04/10] block/vpc: return ZERO block-status when appropriate
Quoted 48 lines · Max Reitz
Quoted 32 lines · Vladimir Sementsov-Ogievskiy
In case when
get_image_offset()returns -1, we do zero out the corresponding chunk of qiov. So, this should be reported as ZERO.Note that this changes visible output of "qemu-img map --output=json" and "qemu-io -c map" commands. For qemu-img map, the change is obvious:
we just mark as zero what is really zero. For qemu-io it's less
obvious: what was unallocated now is allocated.There is an inconsistency in understanding of unallocated regions in
Qemu: backing-supporting format-drivers return 0 block-status to report go-to-backing logic for this area. Some protocol-drivers (iscsi) return 0 to report fs-unallocated-non-zero status (i.e., don't occupy space on disk, read result is undefined).
BDRV_BLOCK_ALLOCATEDis defined as something more close to go-to-backing logic. Still it is calculated as ZERO | DATA, so 0 from iscsi is treated as unallocated. It doesn't influence backing-chain behavior, as iscsi can't have backing file. But it does influence "qemu-io -c map".We should solve this inconsistency at some future point. Now, let's just make backing-not-supporting format drivers (vdi in the previous patch and vpc now) to behave more like backing-supporting drivers and not report 0 block-status. More over, returning ZERO status is absolutely valid thing, and again, corresponds to how the other format-drivers (backing-supporting) work.
After block-status update, it never reports 0, so setting
unallocated_blocks_are_zerodoesn't make sense (as the only user of it isbdrv_co_block_statusand it checksunallocated_blocks_are_zeroonly for unallocated areas). Drop it.Quoted 5 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Eric Blake <[email protected]>--- block/vpc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)This breaks iotest 146, I’m afraid. Now everything is reported as allocated, which is of course what we kind of want, but I suppose it renders the test a bit useless.
It seems to me like the best thing to do would be to replace the “qemu-io -o $opts -c map” calls by
“qemu-img map --output=json --image-opts $opts”, so that we get “zero: true” instead of “not allocated” in the output.
Quoted 6 lines
A bit of a problem with that approach are the “allocated” entries, because those are split into 2 MB chunks, so the output gets long. But, well.
I’ve attached a diff to that effect. Would you be OK with squashing that in?
Yes, this looks reasonable, thanks a lot!
Signature · 2 lines
Best regards, Vladimir
PATCH v3 5/10 block/crypto: drop unallocated_blocks_are_zero
In reply to Vladimir Sementsov-OgievskiyIt's false by default, no needs to set it. We are going to drop this variable at all, so drop it now here, it doesn't hurt.
--- block/crypto.c | 1 - 1 file changed, 1 deletion(-)
block/crypto.c +0 -1
@@ -710,7 +710,6 @@ static int block_crypto_get_info_luks(BlockDriverState *bs,return ret; } - bdi->unallocated_blocks_are_zero = false; bdi->cluster_size = subbdi.cluster_size;return 0 ;
Signature · 1 line
2.18.0
PATCH v3 6/10 block/iscsi: drop unallocated_blocks_are_zero
In reply to Vladimir Sementsov-OgievskiyWe set bdi->unallocated_blocks_are_zero = iscsilun->lbprz, but iscsi_co_block_status doesn't return 0 in case of iscsilun->lbprz, it returns ZERO when appropriate. So actually unallocated_blocks_are_zero is useless (it doesn't affect the only user of the field:bdrv_co_block_status()). Drop it now.
--- block/iscsi.c | 1 - 1 file changed, 1 deletion(-)
block/iscsi.c +0 -1
@@ -2163,7 +2163,6 @@ static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,static int iscsi_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) {IscsiLun *iscsilun = bs->opaque; - bdi->unallocated_blocks_are_zero = iscsilun->lbprz; bdi->cluster_size = iscsilun->cluster_size;return 0 ; }
Signature · 1 line
2.18.0
PATCH v3 7/10 block/file-posix: drop unallocated_blocks_are_zero
In reply to Vladimir Sementsov-Ogievskiyraw_co_block_status() in block/file-posix.c never returns 0, so unallocated_blocks_are_zero is useless (it doesn't affect the only user of the field: bdrv_co_block_status()). Drop it.
--- block/file-posix.c | 3 --- 1 file changed, 3 deletions(-)
block/file-posix.c +0 -3
@@ -2878,9 +2878,6 @@ static int coroutine_fn raw_co_pwrite_zeroes(static int raw_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) { -BDRVRawState *s = bs->opaque; - - bdi->unallocated_blocks_are_zero = s->discard_zeroes;return 0 ; }
Signature · 1 line
2.18.0
PATCH v3 8/10 block/vhdx: drop unallocated_blocks_are_zero
In reply to Vladimir Sementsov-Ogievskiyvhdx doesn't have .bdrv_co_block_status handler, so DATA|ALLOCATED is always assumed for it in bdrv_co_block_status(). unallocated_blocks_are_zero is useless (it doesn't affect the only user of the field: bdrv_co_block_status()), drop it.
--- block/vhdx.c | 3 --- 1 file changed, 3 deletions(-)
block/vhdx.c +0 -3
@@ -1164,9 +1164,6 @@ static int vhdx_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) bdi->cluster_size = s->block_size; - bdi->unallocated_blocks_are_zero = - (s->params.data_bits &VHDX_PARAMS_HAS_PARENT ) ==0 ; -return 0 ; }
Signature · 1 line
2.18.0
PATCH v3 9/10 block: drop unallocated_blocks_are_zero
In reply to Vladimir Sementsov-OgievskiyCurrently 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
--- include/block/block.h | 5 ----- include/block/block_int.h | 12 +++++++++++- block/io.c | 9 ++------- block/qcow2.c | 1 - block/qed.c | 1 - 5 files changed, 13 insertions(+), 15 deletions(-)
include/block/block.h +0 -5
@@ -21,11 +21,6 @@ typedef struct BlockDriverInfo {/* offset at which the VM state can be saved (0 if not possible) */ int64_t vm_state_offset;bool is_dirty; -/* -* True if unallocated blocks read back as zeroes. This is equivalent -* to the LBPRZ flag in the SCSI logical block provisioning page. -*/ -bool unallocated_blocks_are_zero;/* * True if this block driver only supports compressed writes */
include/block/block_int.h +11 -1
@@ -123,7 +123,17 @@ struct BlockDriver {*/ bool bdrv_needs_filename; -/* Set if a driver can support backing files */ +/* +* Set if a driver can support backing files. This also implies the +* following semantics: +* +* - Return status 0 of .bdrv_co_block_status means that corresponding +* blocks are not allocated in this layer of backing-chain +* - For such (unallocated) blocks, read will: +* - fill buffer with zeros if there is no backing file +* - read from the backing file otherwise, where the block layer +* takes care of reading zeros beyond EOF if backing file is short +*/ bool supports_backing;/* For handling image reopen for split or non-split files */
block/io.c +2 -7
@@ -2386,7 +2386,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,if (ret & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) { ret |=BDRV_BLOCK_ALLOCATED ; - }else if (want_zero) { + }else if (want_zero && bs->drv->supports_backing) {if (bs->backing) {BlockDriverState *bs2 = bs->backing->bs;int64_t size2 =bdrv_getlength (bs2);
@@ -2395,12 +2395,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, ret |=BDRV_BLOCK_ZERO ; } }else { -BlockDriverInfo bdi; -int ret2 =bdrv_get_info (bs, &bdi); - -if (ret2 ==0 && bdi.unallocated_blocks_are_zero) { - ret |=BDRV_BLOCK_ZERO ; - } + ret |=BDRV_BLOCK_ZERO ; } }
block/qcow2.c +0 -1
@@ -4973,7 +4973,6 @@ err:static int qcow2_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) {BDRVQcow2State *s = bs->opaque; - bdi->unallocated_blocks_are_zero = true; bdi->cluster_size = s->cluster_size; bdi->vm_state_offset =qcow2_vm_state_offset (s);return 0 ;
block/qed.c +0 -1
@@ -1514,7 +1514,6 @@ static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)memset (bdi,0 ,sizeof (*bdi)); bdi->cluster_size = s->header.cluster_size; bdi->is_dirty = s->header.features &QED_F_NEED_CHECK ; - bdi->unallocated_blocks_are_zero = true;return 0 ; }
Signature · 1 line
2.18.0
PATCH v3 10/10 qed: Simplify backing reads
In reply to Vladimir Sementsov-OgievskiyFrom: Eric Blake <[email protected]>
The other four drivers that support backing files (qcow, qcow2, parallels, vmdk) all rely on the block layer to populate zeroes when reading beyond EOF of a short backing file. We can simplify the qed code by doing likewise.
--- block/qed.h | 1 - block/qed.c | 64 +++++------------------------------------------------ 2 files changed, 6 insertions(+), 59 deletions(-)
block/qed.h +0 -1
@@ -140,7 +140,6 @@ typedef struct QEDAIOCB {/* Current cluster scatter-gather list */ QEMUIOVector cur_qiov; -QEMUIOVector *backing_qiov;uint64_t cur_pos;/* position on block device, in bytes */ uint64_t cur_cluster;/* cluster offset in image file */ unsigned int cur_nclusters;/* number of clusters being accessed */
block/qed.c +6 -58
102 lines not on this page · raw message
Signature · 1 line
2.18.0
Max Reitz
AppliedQuoted 11 lines · Vladimir Sementsov-Ogievskiy
This is first step to block-status refactoring, and solves most simple problem mentioned in my investigation of block-status described in the thread "backing chain & block status & filters":
https://lists.gnu.org/archive/html/qemu-devel/2020-04/msg04706.htmlThe whole series is reviewed, let's proceed with it please!
v3: rebase on master
02: grammar fix in commit msg, add Eric's r-b
03,04,09: add Eric's r-b
10: add my r-b
Thanks, applied to my block branch:
Quoted 8 lines · Max Reitz
Quoted 7 lines · Vladimir Sementsov-Ogievskiy
This is first step to block-status refactoring, and solves most simple problem mentioned in my investigation of block-status described in the thread "backing chain & block status & filters":
https://lists.gnu.org/archive/html/qemu-devel/2020-04/msg04706.htmlThe whole series is reviewed, let's proceed with it please!
Quoted 9 lines
Quoted 4 lines
v3: rebase on master
02: grammar fix in commit msg, add Eric's r-b
03,04,09: add Eric's r-b
10: add my r-bThanks, applied to my block branch:
Thanks!
Signature · 2 lines
Best regards, Vladimir