qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v4 3/4] qcow2: add shrink image support


From: Max Reitz
Subject: Re: [Qemu-block] [PATCH v4 3/4] qcow2: add shrink image support
Date: Tue, 11 Jul 2017 19:22:31 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 2017-07-11 14:40, 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 <address@hidden>
> Reviewed-by: Max Reitz <address@hidden>
> ---
>  block/qcow2-cluster.c  |  40 ++++++++++++++++++
>  block/qcow2-refcount.c | 110 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  block/qcow2.c          |  42 ++++++++++++++-----
>  block/qcow2.h          |  14 +++++++
>  qapi/block-core.json   |   3 +-
>  5 files changed, 198 insertions(+), 11 deletions(-)

[...]

> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 0141c9cbe7..e52d1698b5 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c

[...]

> +    for (i = 0; i < s->refcount_table_size; i++) {
> +        if (s->refcount_table[i] && !reftable_tmp[i]) {
> +            uint64_t discard_offs = s->refcount_table[i] & REFT_OFFSET_MASK;
> +            uint64_t refblock_offs = get_refblock_offset(s, discard_offs);
> +            uint64_t cluster_index = discard_offs >> s->cluster_bits;
> +            uint32_t block_index = cluster_index & (s->refcount_block_size - 
> 1);
> +            void *refblock;
> +
> +            assert(discard_offs != 0);
> +
> +            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_signal_corruption(bs, true, -1, -1, "Invalid refcount:"
> +                                        " refblock offset %#" PRIx64
> +                                        ", reftable index %d"
> +                                        ", block offset %#" PRIx64
> +                                        ", refcount %#" PRIx64,
> +                                        refblock_offs, i, discard_offs,
> +                                        s->get_refcount(refblock, 
> block_index));

Nice, thanks!

Max

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]