From: Max Reitz <mreitz@redhat.com>
To: Pavel Butsykin <pbutsykin@virtuozzo.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, eblake@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 2/2] qcow2: truncate the tail of the image file after shrinking the image
Date: Thu, 21 Sep 2017 17:28:19 +0200 [thread overview]
Message-ID: <d64c9cdd-098b-bb41-cf80-de51c569288b@redhat.com> (raw)
In-Reply-To: <20170920135833.20472-3-pbutsykin@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]
On 2017-09-20 15:58, Pavel Butsykin wrote:
> Now after shrinking the image, at the end of the image file, there might be a
> tail that probably will never be used. So we can find the last used cluster and
> cut the tail.
>
> Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
> ---
> block/qcow2-refcount.c | 21 +++++++++++++++++++++
> block/qcow2.c | 19 +++++++++++++++++++
> block/qcow2.h | 1 +
> 3 files changed, 41 insertions(+)
>
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 88d5a3f1ad..5e221a166c 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -3181,3 +3181,24 @@ out:
> g_free(reftable_tmp);
> return ret;
> }
> +
> +int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size)
> +{
> + BDRVQcow2State *s = bs->opaque;
> + int64_t i, last_cluster, nb_clusters = size_to_clusters(s, size);
> + uint64_t refcount;
> +
> + for (i = 0, last_cluster = 0; i < nb_clusters; i++) {
> + int ret = qcow2_get_refcount(bs, i, &refcount);
> + if (ret < 0) {
> + fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",
> + i, strerror(-ret));
> + continue;
> + }
> +
> + if (refcount > 0) {
> + last_cluster = i;
> + }
> + }
> + return last_cluster;
> +}
Wouldn't it make more sense to start from the end of the image?
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
next prev parent reply other threads:[~2017-09-21 15:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 13:58 [Qemu-devel] [PATCH 0/2] Truncate the tail of the image file in qcow2 shrinking Pavel Butsykin
2017-09-20 13:58 ` [Qemu-devel] [PATCH 1/2] qcow2: fix return error code in qcow2_truncate() Pavel Butsykin
2017-09-20 14:27 ` Eric Blake
2017-09-20 20:17 ` [Qemu-devel] [Qemu-block] " John Snow
2017-09-21 15:28 ` [Qemu-devel] " Max Reitz
2017-09-20 13:58 ` [Qemu-devel] [PATCH 2/2] qcow2: truncate the tail of the image file after shrinking the image Pavel Butsykin
2017-09-20 21:38 ` [Qemu-devel] [Qemu-block] " John Snow
2017-09-21 9:49 ` Pavel Butsykin
2017-09-21 16:48 ` John Snow
2017-09-21 18:23 ` Eric Blake
2017-09-21 15:28 ` Max Reitz [this message]
2017-09-21 16:16 ` [Qemu-devel] " Pavel Butsykin
2017-09-21 16:20 ` Max Reitz
2017-09-21 15:30 ` Max Reitz
2017-09-21 15:52 ` Pavel Butsykin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d64c9cdd-098b-bb41-cf80-de51c569288b@redhat.com \
--to=mreitz@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbutsykin@virtuozzo.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).