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 <pbutsy...@virtuozzo.com> > Reviewed-by: Max Reitz <mre...@redhat.com> > --- > 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
signature.asc
Description: OpenPGP digital signature