From: Eric Blake <eblake@redhat.com>
To: Max Reitz <mreitz@redhat.com>, Ivan Ren <renyime@gmail.com>,
qemu-devel@nongnu.org
Cc: kwolf@redhat.com, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-img: return allocated size for block device with qcow2 format
Date: Wed, 2 May 2018 10:01:23 -0500 [thread overview]
Message-ID: <69c3123f-4ef2-7bdc-6042-1271fc8689e6@redhat.com> (raw)
In-Reply-To: <44cdffb1-e5f5-d324-8880-1ee2e07c3954@redhat.com>
On 05/02/2018 09:37 AM, Max Reitz wrote:
> On 2018-05-02 15:34, Ivan Ren wrote:
>> qemu-img info with a block device which has a qcow2 format always
>> return 0 for disk size, and this can not reflect the qcow2 size
>> and the used space of the block device. This patch return the
>> allocated size of qcow2 as the disk size.
>
> I'm not quite sure whether you really need this information for block
> devices (I tend to agree with Eric that wr_highest_cluster is the more
> important information there), but I can imagine it just being nice to have.
Hmm, so in an extreme case, if you create an internal snapshot, then the
guest makes edits, then you remove the internal snapshot, we have a
wr_highest_offset that has advanced (because the guest changes had to
allocate new clusters due to COW of refcount=2 clusters); but the
deleted snapshot now means we have a lot of unused clusters earlier in
the image (deleting the snapshot took refcount=2 clusters back to 1, and
any COW'd clusters edited after the internal snapshot means the snapshot
version is now back to refcount=0, whether or not we also try to punch a
hole in the protocol layer for those freed clusters). Thus, reporting
the highest written cluster is a larger number than the number of
clusters that are actually in use, and both numbers might be useful to
know (how big do I have to size my block device, and how utilized is my
block device), especially if we add code for online compaction or
defragmentation of a qcow2 image so that we can move higher offsets into
holes left earlier in the image.
If you don't use internal snapshots, the only way to get holes of
unallocated clusters earlier in the image is if the guest uses TRIM
operations, and I'm not sure if that's easier or harder to trigger, nor
which approach (internal snapshots vs. guest TRIM operations) is likely
to leave more holes of unallocated clusters.
>
> The whole implementation reminds me a lot of qcow2's check function,
> which basically just recalculates the refcounts. So I'm wondering
> whether you could just count how many clusters with non-0 refcount there
> are and thus simplify the implementation dramatically.
We also recently added 'qemu-img measure', which DOES report how many
clusters are in use. Is any of that reusable here?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-05-02 15:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 13:34 [Qemu-devel] [PATCH] qemu-img: return allocated size for block device with qcow2 format Ivan Ren
2018-05-02 14:02 ` Eric Blake
2018-05-03 13:06 ` 叶残风
2018-05-04 14:35 ` Max Reitz
2018-05-04 15:57 ` Ivan Ren
2018-05-02 14:37 ` Max Reitz
2018-05-02 15:01 ` Eric Blake [this message]
2018-05-02 15:13 ` Max Reitz
2018-05-02 15:19 ` Eric Blake
2018-05-02 15:33 ` Max Reitz
2018-05-03 13:08 ` 叶残风
2018-05-04 14:27 ` Max Reitz
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=69c3123f-4ef2-7bdc-6042-1271fc8689e6@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=renyime@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.