diff options
author | Kevin Wolf | 2016-05-17 18:42:23 +0200 |
---|---|---|
committer | Kevin Wolf | 2016-05-19 16:45:31 +0200 |
commit | 5efdf53227809a0da436dd63d7ed19c99044ecbd (patch) | |
tree | 7e5922f4e1ec4cc750b83a8ab0d8614b95b0fe07 /block | |
parent | qcow2: fix condition in is_zero_cluster (diff) | |
download | qemu-5efdf53227809a0da436dd63d7ed19c99044ecbd.tar.gz qemu-5efdf53227809a0da436dd63d7ed19c99044ecbd.tar.xz qemu-5efdf53227809a0da436dd63d7ed19c99044ecbd.zip |
qcow2: Fix write_zeroes with partially allocated backing file cluster
In order to correctly check whether a given cluster is read as zero, we
don't only need to check whether bdrv_get_block_status_above() sets
BDRV_BLOCK_ZERO, but also if all sectors for the whole cluster have the
same status.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Diffstat (limited to 'block')
-rw-r--r-- | block/qcow2.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index a6012dc793..c197ff3c53 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2412,7 +2412,7 @@ static bool is_zero_cluster(BlockDriverState *bs, int64_t start) BlockDriverState *file; int64_t res = bdrv_get_block_status_above(bs, NULL, start, s->cluster_sectors, &nr, &file); - return res >= 0 && (res & BDRV_BLOCK_ZERO); + return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == s->cluster_sectors; } static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start) @@ -2423,6 +2423,7 @@ static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start) int ret; ret = qcow2_get_cluster_offset(bs, start << BDRV_SECTOR_BITS, &nr, &off); + assert(nr == s->cluster_sectors); return ret == QCOW2_CLUSTER_UNALLOCATED || ret == QCOW2_CLUSTER_ZERO; } |