[PATCH 0/2] block/io: Update BSC only if want_zero is true

Hanna Reitz posted 2 patches 2 years, 3 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220117162649.193501-1-hreitz@redhat.com
Maintainers: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>, Hanna Reitz <hreitz@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
There is a newer version of this series
block/io.c                                    |   6 +-
tests/qemu-iotests/tests/block-status-cache   | 130 ++++++++++++++++++
.../qemu-iotests/tests/block-status-cache.out |   5 +
3 files changed, 140 insertions(+), 1 deletion(-)
create mode 100755 tests/qemu-iotests/tests/block-status-cache
create mode 100644 tests/qemu-iotests/tests/block-status-cache.out
[PATCH 0/2] block/io: Update BSC only if want_zero is true
Posted by Hanna Reitz 2 years, 3 months ago
Hi,

As reported by Nir
(https://lists.nongnu.org/archive/html/qemu-block/2022-01/msg00292.html)
there’s a problem with the block-status cache, namely that it is updated
when want_zero is false, but we return the result later even when the
caller now passes want_zero=true.  In the worst case, the
want_zero=false call may have resulted in the cache containing an entry
describing the whole image to contain data, and then all future requests
will be served from that cache entry.

There are a couple ways this could be fixed (e.g. one cache per
want_zero mode, or storing want_zero in the cache and comparing it when
the cached data is fetched), but I think the simplest way is to only
store want_zero=true block-status results in the cache.  (This way, the
cache will not work with want_zero=false, but the want_zero=true case is
the one for which we introduced the cache in the first place.  I think
want_zero=false generally is fast enough(tm), that’s why we introduced
want_zero after all.)

Patch 1 is the fix, patch 2 a regression test.


Hanna Reitz (2):
  block/io: Update BSC only if want_zero is true
  iotests/block-status-cache: New test

 block/io.c                                    |   6 +-
 tests/qemu-iotests/tests/block-status-cache   | 130 ++++++++++++++++++
 .../qemu-iotests/tests/block-status-cache.out |   5 +
 3 files changed, 140 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/tests/block-status-cache
 create mode 100644 tests/qemu-iotests/tests/block-status-cache.out

-- 
2.33.1


Re: [PATCH 0/2] block/io: Update BSC only if want_zero is true
Posted by Hanna Reitz 2 years, 3 months ago
Forgot to CC qemu-stable.

On 17.01.22 17:26, Hanna Reitz wrote:
> Hi,
>
> As reported by Nir
> (https://lists.nongnu.org/archive/html/qemu-block/2022-01/msg00292.html)
> there’s a problem with the block-status cache, namely that it is updated
> when want_zero is false, but we return the result later even when the
> caller now passes want_zero=true.  In the worst case, the
> want_zero=false call may have resulted in the cache containing an entry
> describing the whole image to contain data, and then all future requests
> will be served from that cache entry.
>
> There are a couple ways this could be fixed (e.g. one cache per
> want_zero mode, or storing want_zero in the cache and comparing it when
> the cached data is fetched), but I think the simplest way is to only
> store want_zero=true block-status results in the cache.  (This way, the
> cache will not work with want_zero=false, but the want_zero=true case is
> the one for which we introduced the cache in the first place.  I think
> want_zero=false generally is fast enough(tm), that’s why we introduced
> want_zero after all.)
>
> Patch 1 is the fix, patch 2 a regression test.
>
>
> Hanna Reitz (2):
>    block/io: Update BSC only if want_zero is true
>    iotests/block-status-cache: New test
>
>   block/io.c                                    |   6 +-
>   tests/qemu-iotests/tests/block-status-cache   | 130 ++++++++++++++++++
>   .../qemu-iotests/tests/block-status-cache.out |   5 +
>   3 files changed, 140 insertions(+), 1 deletion(-)
>   create mode 100755 tests/qemu-iotests/tests/block-status-cache
>   create mode 100644 tests/qemu-iotests/tests/block-status-cache.out
>