On 2017-07-07 16:30, Pavel Butsykin wrote: > This patch add shrinking of the image file for qcow2. As a result, this allows > us to reduce the virtual image size and free up space on the disk without > copying the image. Image can be fragmented and shrink is done by punching > holes > in the image file. > > Signed-off-by: Pavel Butsykin <[email protected]> > --- > block/qcow2-cluster.c | 40 +++++++++++++++++++ > block/qcow2-refcount.c | 103 > +++++++++++++++++++++++++++++++++++++++++++++++++ > block/qcow2.c | 42 +++++++++++++++----- > block/qcow2.h | 14 +++++++ > qapi/block-core.json | 3 +- > 5 files changed, 191 insertions(+), 11 deletions(-)
[...]
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 0141c9cbe7..443fca6a98 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
[...]
> @@ -2945,3 +2946,105 @@ done:
[...]
> + ret = qcow2_cache_get(bs, s->refcount_block_cache, refblock_offs,
> + &refblock);
> + if (ret < 0) {
> + goto out;
> + }
> +
> + if (s->get_refcount(refblock, block_index) != 1) {
> + qcow2_cache_put(bs, s->refcount_block_cache, &refblock);
> + ret = -EINVAL;
Optional: You could mark the image corrupt here.
Anyway:
Reviewed-by: Max Reitz <[email protected]>
> + goto out;
> + }
> + s->set_refcount(refblock, block_index, 0);
signature.asc
Description: OpenPGP digital signature
