[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 29/30] block/io: fix bdrv_is_allocated_above
From: |
Stefan Hajnoczi |
Subject: |
[PULL v2 29/30] block/io: fix bdrv_is_allocated_above |
Date: |
Mon, 12 Oct 2020 19:27:59 +0100 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
bdrv_is_allocated_above wrongly handles short backing files: it reports
after-EOF space as UNALLOCATED which is wrong, as on read the data is
generated on the level of short backing file (if all overlays have
unallocated areas at that place).
Reusing bdrv_common_block_status_above fixes the issue and unifies code
path.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-id: 20200924194003.22080-5-vsementsov@virtuozzo.com
[Fix s/has/have/ as suggested by Eric Blake. Fix s/area/areas/.
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/io.c | 43 +++++--------------------------------------
1 file changed, 5 insertions(+), 38 deletions(-)
diff --git a/block/io.c b/block/io.c
index b616bc4ada..02528b3823 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2477,52 +2477,19 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState
*bs, int64_t offset,
* at 'offset + *pnum' may return the same allocation status (in other
* words, the result is not necessarily the maximum possible range);
* but 'pnum' will only be 0 when end of file is reached.
- *
*/
int bdrv_is_allocated_above(BlockDriverState *top,
BlockDriverState *base,
bool include_base, int64_t offset,
int64_t bytes, int64_t *pnum)
{
- BlockDriverState *intermediate;
- int ret;
- int64_t n = bytes;
-
- assert(base || !include_base);
-
- intermediate = top;
- while (include_base || intermediate != base) {
- int64_t pnum_inter;
- int64_t size_inter;
-
- assert(intermediate);
- ret = bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter);
- if (ret < 0) {
- return ret;
- }
- if (ret) {
- *pnum = pnum_inter;
- return 1;
- }
-
- size_inter = bdrv_getlength(intermediate);
- if (size_inter < 0) {
- return size_inter;
- }
- if (n > pnum_inter &&
- (intermediate == top || offset + pnum_inter < size_inter)) {
- n = pnum_inter;
- }
-
- if (intermediate == base) {
- break;
- }
-
- intermediate = bdrv_filter_or_cow_bs(intermediate);
+ int ret = bdrv_common_block_status_above(top, base, include_base, false,
+ offset, bytes, pnum, NULL, NULL);
+ if (ret < 0) {
+ return ret;
}
- *pnum = n;
- return 0;
+ return !!(ret & BDRV_BLOCK_ALLOCATED);
}
int coroutine_fn
--
2.26.2
- [PULL v2 19/30] util/vhost-user-server: move header to include/, (continued)
- [PULL v2 19/30] util/vhost-user-server: move header to include/, Stefan Hajnoczi, 2020/10/12
- [PULL v2 16/30] util/vhost-user-server: rework vu_client_trip() coroutine lifecycle, Stefan Hajnoczi, 2020/10/12
- [PULL v2 20/30] util/vhost-user-server: use static library in meson.build, Stefan Hajnoczi, 2020/10/12
- [PULL v2 21/30] qemu-storage-daemon: avoid compiling blockdev_ss twice, Stefan Hajnoczi, 2020/10/12
- [PULL v2 22/30] block: move block exports to libblockdev, Stefan Hajnoczi, 2020/10/12
- [PULL v2 23/30] block/export: add iothread and fixed-iothread options, Stefan Hajnoczi, 2020/10/12
- [PULL v2 24/30] block/export: add vhost-user-blk multi-queue support, Stefan Hajnoczi, 2020/10/12
- [PULL v2 25/30] tests/qtest: add multi-queue test case to vhost-user-blk-test, Stefan Hajnoczi, 2020/10/12
- [PULL v2 26/30] block/io: fix bdrv_co_block_status_above, Stefan Hajnoczi, 2020/10/12
- [PULL v2 27/30] block/io: bdrv_common_block_status_above: support include_base, Stefan Hajnoczi, 2020/10/12
- [PULL v2 29/30] block/io: fix bdrv_is_allocated_above,
Stefan Hajnoczi <=
- [PULL v2 30/30] iotests: add commit top->base cases to 274, Stefan Hajnoczi, 2020/10/12
- [PULL v2 28/30] block/io: bdrv_common_block_status_above: support bs == base, Stefan Hajnoczi, 2020/10/12
- Re: [PULL v2 00/30] Block patches, no-reply, 2020/10/12
- Re: [PULL v2 00/30] Block patches, Peter Maydell, 2020/10/12