On 02/21/2014 03:11 PM, Kevin Wolf wrote:
> Instead of making the backing file contents visible again after a discard
> request, set the zero flag if possible (i.e. on version >= 3).
> 
> Signed-off-by: Kevin Wolf <kw...@redhat.com>
> Reviewed-by: Eric Blake <ebl...@redhat.com>
> ---
>  block/qcow2-cluster.c  | 22 ++++++++++++++++++++--
>  tests/qemu-iotests/046 | 18 ++++++++++++++----
>  2 files changed, 34 insertions(+), 6 deletions(-)
> 
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index c57f39d..36c1bed 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -1367,13 +1367,31 @@ static int discard_single_l2(BlockDriverState *bs, 
> uint64_t offset,
>          uint64_t old_offset;
>  
>          old_offset = be64_to_cpu(l2_table[l2_index + i]);
> -        if ((old_offset & L2E_OFFSET_MASK) == 0) {
> +
> +        /*
> +         * Make sure that a discarded area reads back as zeroes for v3 images
> +         * (we cannot do it for v2 without actually writing a zero-filled
> +         * buffer). We can skip the operation if the cluster is already 
> marked
> +         * as zero, or if it's unallocated and we don't have a backing file.
> +         *

Possible idea for a followup:

Is it possible with v2 images to write a single sector/cluster with all
0s, and to make all other writes of all-0 data bump the reference count
of the magic known-zero cluster, so that we are at least conserving disk
space by heavily reusing the known cluster?

Then again, we may be reaching the point where no one cares about v2
images as much.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to