mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 02:24:58 -06:00
block: Exploit BDRV_BLOCK_EOF for larger zero blocks
When we have a BDS with unallocated clusters, but asking the status of its underlying bs->file or backing layer encounters an end-of-file condition, we know that the rest of the unallocated area will read as zeroes. However, pre-patch, this required two separate calls to bdrv_get_block_status(), as the first call stops at the point where the underlying file ends. Thanks to BDRV_BLOCK_EOF, we can now widen the results of the primary status if the secondary status already includes BDRV_BLOCK_ZERO. In turn, this fixes a TODO mentioned in iotest 154, where we can now see that all sectors in a partial cluster at the end of a file read as zero when coupling the shorter backing file's status along with our knowledge that the remaining sectors came from an unallocated cluster. Also, note that the loop in bdrv_co_get_block_status_above() had an inefficent exit: in cases where the active layer sets BDRV_BLOCK_ZERO but does NOT set BDRV_BLOCK_ALLOCATED (namely, where we know we read zeroes merely because our unallocated clusters lie beyond the backing file's shorter length), we still ended up probing the backing layer even though we already had a good answer. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20170505021500.19315-3-eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
parent
fb0d8654ff
commit
c61e684e44
3 changed files with 28 additions and 15 deletions
|
@ -310,19 +310,19 @@ wrote 512/512 bytes at offset 134217728
|
|||
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 512/512 bytes at offset 134219264
|
||||
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 1024/1024 bytes at offset 134218240
|
||||
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 2048/2048 bytes at offset 134217728
|
||||
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
|
@ -336,19 +336,19 @@ wrote 512/512 bytes at offset 134217728
|
|||
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 512/512 bytes at offset 134219264
|
||||
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 1024/1024 bytes at offset 134218240
|
||||
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
2048/2048 bytes allocated at offset 128 MiB
|
||||
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
|
||||
{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
|
||||
wrote 2048/2048 bytes at offset 134217728
|
||||
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue