aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-10-11 22:46:57 -0500
committerKevin Wolf <kwolf@redhat.com>2017-10-26 14:45:57 +0200
commit298a1665a2800f7264e483c2dd1f551574243a2f (patch)
tree74d8d30bf06f312a0d343e883854eb1af83dce5d /block/qcow2.c
parent760c4d43ae43f5d4b5eec450a53f056c3c91fab1 (diff)
downloadqemu-298a1665a2800f7264e483c2dd1f551574243a2f.zip
qemu-298a1665a2800f7264e483c2dd1f551574243a2f.tar.gz
qemu-298a1665a2800f7264e483c2dd1f551574243a2f.tar.bz2
block: Allow NULL file for bdrv_get_block_status()
Not all callers care about which BDS owns the mapping for a given range of the file. This patch merely simplifies the callers by consolidating the logic in the common call point, while guaranteeing a non-NULL file to all the driver callbacks, for no semantic change. The only caller that does not care about pnum is bdrv_is_allocated, as invoked by vvfat; we can likewise add assertions that the rest of the stack does not have to worry about a NULL pnum. Furthermore, this will also set the stage for a future cleanup: when a caller does not care about which BDS owns an offset, it would be nice to allow the driver to optimize things to not have to return BDRV_BLOCK_OFFSET_VALID in the first place. In the case of fragmented allocation (for example, it's fairly easy to create a qcow2 image where consecutive guest addresses are not at consecutive host addresses), the current contract requires bdrv_get_block_status() to clamp *pnum to the limit where host addresses are no longer consecutive, but allowing a NULL file means that *pnum could be set to the full length of known-allocated data. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index f63d183..0e4c91c 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2976,7 +2976,6 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
uint32_t count)
{
int nr;
- BlockDriverState *file;
int64_t res;
if (start + count > bs->total_sectors) {
@@ -2986,8 +2985,7 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
if (!count) {
return true;
}
- res = bdrv_get_block_status_above(bs, NULL, start, count,
- &nr, &file);
+ res = bdrv_get_block_status_above(bs, NULL, start, count, &nr, NULL);
return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == count;
}
@@ -3703,13 +3701,11 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
offset += pnum * BDRV_SECTOR_SIZE) {
int nb_sectors = MIN(ssize - offset,
BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR_SIZE;
- BlockDriverState *file;
int64_t ret;
ret = bdrv_get_block_status_above(in_bs, NULL,
offset >> BDRV_SECTOR_BITS,
- nb_sectors,
- &pnum, &file);
+ nb_sectors, &pnum, NULL);
if (ret < 0) {
error_setg_errno(&local_err, -ret,
"Unable to get block status");