From: Denis V. Lunev Date: Tue, 17 May 2016 09:15:42 +0000 (+0300) Subject: qcow2: fix condition in is_zero_cluster X-Git-Tag: v2.7.1~333^2~4 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=f575f145f4fa97fdbb9bbb4df62dfeada3f15dc4;p=mirror_qemu.git qcow2: fix condition in is_zero_cluster We should check for (res & BDRV_BLOCK_ZERO) only. The situation when we will have !(res & BDRV_BLOCK_DATA) and will not have BDRV_BLOCK_ZERO is not possible for images with bdi.unallocated_blocks_are_zero == true. For those images where it's false, however, it can happen and we must not consider the data zeroed then or we would corrupt the image. Signed-off-by: Denis V. Lunev CC: Kevin Wolf Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- diff --git a/block/qcow2.c b/block/qcow2.c index 62febfc386..a6012dc793 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) || !(res & BDRV_BLOCK_DATA)); + return res >= 0 && (res & BDRV_BLOCK_ZERO); } static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start)