On 05/03/2017 06:11 PM, Max Reitz wrote: > Instead of just freeing preallocated zero clusters and completely > allocating them from scratch, reuse them. > > We cannot do this in handle_copied(), however, since this is a COW > operation. Therefore, we have to add the new logic to handle_alloc() and > simply return the existing offset if it exists. The only catch is that > we have to convince qcow2_alloc_cluster_link_l2() not to free the old > clusters (because we have reused them). > > Reported-by: Eric Blake <ebl...@redhat.com> > Signed-off-by: Max Reitz <mre...@redhat.com> > --- > block/qcow2.h | 3 ++ > block/qcow2-cluster.c | 80 > +++++++++++++++++++++++++++++++++++---------------- > 2 files changed, 59 insertions(+), 24 deletions(-) >
> > - assert(qcow2_get_cluster_type(first_entry) == QCOW2_CLUSTER_NORMAL); > + /* must be allocated */ > + first_cluster_type = qcow2_get_cluster_type(first_entry); > + assert(first_cluster_type == QCOW2_CLUSTER_NORMAL || > + (first_cluster_type == QCOW2_CLUSTER_ZERO && > + (first_entry & L2E_OFFSET_MASK) != 0)); I wonder if we should have separate QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOCATED, so we don't have to keep checking first_entry & L2E_OFFSET_MASK. But I think that can be a separate followup if we want it. Reviewed-by: Eric Blake <ebl...@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature