From: Kevin Wolf <kwolf@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Max Reitz <mreitz@redhat.com>, Eric Blake <eblake@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for-2.12 v2] qcow2: Reset free_cluster_index when allocating a new refcount block
Date: Wed, 21 Mar 2018 18:52:47 +0100 [thread overview]
Message-ID: <20180321175247.GI3898@localhost.localdomain> (raw)
In-Reply-To: <20180321133852.3560-1-berto@igalia.com>
Am 21.03.2018 um 14:38 hat Alberto Garcia geschrieben:
> When we try to allocate new clusters we first look for available ones
> starting from s->free_cluster_index and once we find them we increase
> their reference counts. Before we get to call update_refcount() to do
> this last step s->free_cluster_index is already pointing to the next
> cluster after the ones we are trying to allocate.
>
> During update_refcount() it may happen however that we also need to
> allocate a new refcount block in order to store the refcounts of these
> new clusters (and to complicate things further that may also require
> us to grow the refcount table). After all this we don't know if the
> clusters that we originally tried to allocate are still available, so
> we return -EAGAIN to ask the caller to restart the search for free
> clusters.
>
> This is what can happen in a common scenario:
>
> 1) We want to allocate a new cluster and we see that cluster N is
> free.
>
> 2) We try to increase N's refcount but all refcount blocks are full,
> so we allocate a new one at N+1 (where s->free_cluster_index was
> pointing at).
>
> 3) Once we're done we return -EAGAIN to look again for a free
> cluster, but now s->free_cluster_index points at N+2, so that's
> the one we allocate. Cluster N remains unallocated and we have a
> hole in the qcow2 file.
>
> This can be reproduced easily:
>
> qemu-img create -f qcow2 -o cluster_size=512 hd.qcow2 1M
> qemu-io -c 'write 0 124k' hd.qcow2
>
> After this the image has 132608 bytes (256 clusters), and the refcount
> block is full. If we write 512 more bytes it should allocate two new
> clusters: the data cluster itself and a new refcount block.
>
> qemu-io -c 'write 124k 512' hd.qcow2
>
> However the image has now three new clusters (259 in total), and the
> first one of them is empty (and unallocated):
>
> dd if=hd.qcow2 bs=512c skip=256 count=1 | hexdump -C
>
> If we write larger amounts of data in the last step instead of the 512
> bytes used in this example we can create larger holes in the qcow2
> file.
>
> What this patch does is reset s->free_cluster_index to its previous
> value when alloc_refcount_block() returns -EAGAIN. This way the caller
> will try to allocate again the original clusters if they are still
> free.
>
> The output of iotest 026 also needs to be updated because now that
> images have no holes some tests fail at a different point and the
> number of leaked clusters is different.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks, applied to the block branch.
Kevin
prev parent reply other threads:[~2018-03-21 17:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-21 13:38 [Qemu-devel] [PATCH for-2.12 v2] qcow2: Reset free_cluster_index when allocating a new refcount block Alberto Garcia
2018-03-21 13:52 ` Kevin Wolf
2018-03-21 14:10 ` Alberto Garcia
2018-03-21 15:07 ` Kevin Wolf
2018-03-21 15:32 ` Alberto Garcia
2018-03-21 15:40 ` Kevin Wolf
2018-03-21 17:52 ` Kevin Wolf [this message]
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=20180321175247.GI3898@localhost.localdomain \
--to=kwolf@redhat.com \
--cc=berto@igalia.com \
--cc=eblake@redhat.com \
--cc=mreitz@redhat.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 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.