1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Hanna Reitz <hreitz@redhat.com>
3 Date: Tue, 18 Jan 2022 17:59:59 +0100
4 Subject: [PATCH] block/io: Update BSC only if want_zero is true
6 We update the block-status cache whenever we get new information from a
7 bdrv_co_block_status() call to the block driver. However, if we have
8 passed want_zero=false to that call, it may flag areas containing zeroes
9 as data, and so we would update the block-status cache with wrong
12 Therefore, we should not update the cache with want_zero=false.
14 Reported-by: Nir Soffer <nsoffer@redhat.com>
15 Fixes: 0bc329fbb00 ("block: block-status cache for data regions")
16 Reviewed-by: Nir Soffer <nsoffer@redhat.com>
17 Cc: qemu-stable@nongnu.org
18 Signed-off-by: Hanna Reitz <hreitz@redhat.com>
19 Message-Id: <20220118170000.49423-2-hreitz@redhat.com>
20 Reviewed-by: Eric Blake <eblake@redhat.com>
21 Signed-off-by: Eric Blake <eblake@redhat.com>
24 1 file changed, 5 insertions(+), 1 deletion(-)
26 diff --git a/block/io.c b/block/io.c
27 index bb0a254def..4e4cb556c5 100644
30 @@ -2497,8 +2497,12 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
31 * non-protocol nodes, and then it is never used. However, filling
32 * the cache requires an RCU update, so double check here to avoid
33 * such an update if possible.
35 + * Check want_zero, because we only want to update the cache when we
36 + * have accurate information about what is zero and what is data.
38 - if (ret == (BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID) &&
40 + ret == (BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID) &&
41 QLIST_EMPTY(&bs->children))