From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2iDH-0006Z9-5a for qemu-devel@nongnu.org; Tue, 17 May 2016 12:51:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2iDF-0007GG-3l for qemu-devel@nongnu.org; Tue, 17 May 2016 12:51:17 -0400 From: Kevin Wolf Date: Tue, 17 May 2016 18:51:01 +0200 Message-Id: <1463503863-19009-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1463503863-19009-1-git-send-email-kwolf@redhat.com> References: <1463503863-19009-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] qcow2: fix condition in is_zero_cluster List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com, den@openvz.org, qemu-devel@nongnu.org From: "Denis V. Lunev" 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 Signed-off-by: Kevin Wolf --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 62febfc..a6012dc 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) -- 1.8.3.1