qcow2: Reuse preallocated zero clusters
authorMax Reitz <mreitz@redhat.com>
Wed, 3 May 2017 23:11:18 +0000 (01:11 +0200)
committerKevin Wolf <kwolf@redhat.com>
Thu, 11 May 2017 10:08:24 +0000 (12:08 +0200)
commit564a6b693828ac38f3f562eed9e8b1dc62f45253
tree466aa3bfb92a455ccb0648dea25659b3563e22df
parent92413c16be8eee53a3b60739f2a28a1463651f47
qcow2: Reuse preallocated zero clusters

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 <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/qcow2-cluster.c
block/qcow2.h