qcow2: Catch more unaligned write_zero into zero cluster

is_zero_cluster() and is_zero_cluster_top_locked() are used only
by qcow2_co_write_zeroes().  The former is too broad (we don't
care if the sectors we are about to overwrite are non-zero, only
that all other sectors in the cluster are zero), so it needs to
be called up to twice but with smaller limits - rename it along
with adding the neeeded parameter.  The latter can be inlined for
more compact code.

The testsuite change shows that we now have a sparser top file
when an unaligned write_zeroes overwrites the only portion of
the backing file with data.

Based on a patch proposal by Denis V. Lunev.

CC: Denis V. Lunev <den@openvz.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Eric Blake 2016-05-25 21:48:49 -06:00 committed by Kevin Wolf
parent 31ad4fdf91
commit ebb718a5c7
2 changed files with 27 additions and 28 deletions

View file

@ -102,13 +102,13 @@ wrote 2048/2048 bytes at offset 29696
read 4096/4096 bytes at offset 28672
4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
[{ "start": 0, "length": 4096, "depth": 1, "zero": true, "data": false},
{ "start": 4096, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
{ "start": 4096, "length": 4096, "depth": 0, "zero": true, "data": false},
{ "start": 8192, "length": 4096, "depth": 1, "zero": true, "data": false},
{ "start": 12288, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
{ "start": 12288, "length": 4096, "depth": 0, "zero": true, "data": false},
{ "start": 16384, "length": 4096, "depth": 1, "zero": true, "data": false},
{ "start": 20480, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672},
{ "start": 20480, "length": 4096, "depth": 0, "zero": true, "data": false},
{ "start": 24576, "length": 4096, "depth": 1, "zero": true, "data": false},
{ "start": 28672, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 32768},
{ "start": 28672, "length": 4096, "depth": 0, "zero": true, "data": false},
{ "start": 32768, "length": 134184960, "depth": 1, "zero": true, "data": false}]
== spanning two clusters, non-zero before request ==