summaryrefslogtreecommitdiff
path: root/block/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/io.c')
-rw-r--r--block/io.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/block/io.c b/block/io.c
index 0854e0fdac..93231b0e26 100644
--- a/block/io.c
+++ b/block/io.c
@@ -718,7 +718,6 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
{
int64_t target_sectors, ret, nb_sectors, sector_num = 0;
BlockDriverState *bs = child->bs;
- BlockDriverState *file;
int n;
target_sectors = bdrv_nb_sectors(bs);
@@ -731,7 +730,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
if (nb_sectors <= 0) {
return 0;
}
- ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n, &file);
+ ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL);
if (ret < 0) {
error_report("error getting block status at sector %" PRId64 ": %s",
sector_num, strerror(-ret));
@@ -1820,8 +1819,9 @@ int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverState *bs,
* beyond the end of the disk image it will be clamped; if 'pnum' is set to
* the end of the image, then the returned value will include BDRV_BLOCK_EOF.
*
- * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, 'file'
- * points to the BDS which the sector range is allocated in.
+ * If returned value is positive, BDRV_BLOCK_OFFSET_VALID bit is set, and
+ * 'file' is non-NULL, then '*file' points to the BDS which the sector range
+ * is allocated in.
*/
static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
int64_t sector_num,
@@ -1831,20 +1831,23 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
int64_t total_sectors;
int64_t n;
int64_t ret, ret2;
+ BlockDriverState *local_file = NULL;
- *file = NULL;
+ assert(pnum);
+ *pnum = 0;
total_sectors = bdrv_nb_sectors(bs);
if (total_sectors < 0) {
- return total_sectors;
+ ret = total_sectors;
+ goto early_out;
}
if (sector_num >= total_sectors) {
- *pnum = 0;
- return BDRV_BLOCK_EOF;
+ ret = BDRV_BLOCK_EOF;
+ goto early_out;
}
if (!nb_sectors) {
- *pnum = 0;
- return 0;
+ ret = 0;
+ goto early_out;
}
n = total_sectors - sector_num;
@@ -1860,23 +1863,23 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
}
if (bs->drv->protocol_name) {
ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
- *file = bs;
+ local_file = bs;
}
- return ret;
+ goto early_out;
}
bdrv_inc_in_flight(bs);
ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum,
- file);
+ &local_file);
if (ret < 0) {
*pnum = 0;
goto out;
}
if (ret & BDRV_BLOCK_RAW) {
- assert(ret & BDRV_BLOCK_OFFSET_VALID && *file);
- ret = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
- *pnum, pnum, file);
+ assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file);
+ ret = bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_BITS,
+ *pnum, pnum, &local_file);
goto out;
}
@@ -1894,14 +1897,13 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
}
}
- if (*file && *file != bs &&
+ if (local_file && local_file != bs &&
(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
(ret & BDRV_BLOCK_OFFSET_VALID)) {
- BlockDriverState *file2;
int file_pnum;
- ret2 = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
- *pnum, &file_pnum, &file2);
+ ret2 = bdrv_co_get_block_status(local_file, ret >> BDRV_SECTOR_BITS,
+ *pnum, &file_pnum, NULL);
if (ret2 >= 0) {
/* Ignore errors. This is just providing extra information, it
* is useful but not necessary.
@@ -1927,6 +1929,10 @@ out:
if (ret >= 0 && sector_num + *pnum == total_sectors) {
ret |= BDRV_BLOCK_EOF;
}
+early_out:
+ if (file) {
+ *file = local_file;
+ }
return ret;
}
@@ -2026,7 +2032,6 @@ int64_t bdrv_get_block_status(BlockDriverState *bs,
int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
int64_t bytes, int64_t *pnum)
{
- BlockDriverState *file;
int64_t sector_num = offset >> BDRV_SECTOR_BITS;
int nb_sectors = bytes >> BDRV_SECTOR_BITS;
int64_t ret;
@@ -2035,7 +2040,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE));
assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && bytes < INT_MAX);
ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &psectors,
- &file);
+ NULL);
if (ret < 0) {
return ret;
}