[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/5] block/io: fix bdrv_is_allocated_above
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 4/5] block/io: fix bdrv_is_allocated_above |
Date: |
Tue, 19 May 2020 22:55:00 +0300 |
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 has
unallocated area at that place).
Reusing bdrv_common_block_status_above fixes the issue and unifies code
path.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/io.c | 43 +++++--------------------------------------
1 file changed, 5 insertions(+), 38 deletions(-)
diff --git a/block/io.c b/block/io.c
index df44e89b7d..61f0930626 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2610,52 +2610,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 = backing_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);
}
typedef struct BdrvVmstateCo {
--
2.21.0
[PATCH v2 2/5] block/io: bdrv_common_block_status_above: support include_base, Vladimir Sementsov-Ogievskiy, 2020/05/19
[PATCH v2 3/5] block/io: bdrv_common_block_status_above: support bs == base, Vladimir Sementsov-Ogievskiy, 2020/05/19
[PATCH v2 4/5] block/io: fix bdrv_is_allocated_above,
Vladimir Sementsov-Ogievskiy <=
[PATCH v2 5/5] iotests: add commit top->base cases to 274, Vladimir Sementsov-Ogievskiy, 2020/05/19
Re: [PATCH v2 0/5] fix & merge block_status_above and is_allocated_above, Eric Blake, 2020/05/19