From: Stefan Hajnoczi <stefanha@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] qcow2: Undo leaked allocations in co_writev
Date: Fri, 11 Oct 2013 11:15:46 +0200 [thread overview]
Message-ID: <20131011091546.GC28383@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <20131010122625.GG3046@dhcp-200-207.str.redhat.com>
On Thu, Oct 10, 2013 at 02:26:25PM +0200, Kevin Wolf wrote:
> Am 10.10.2013 um 10:52 hat Max Reitz geschrieben:
> > If the write request spans more than one L2 table,
> > qcow2_alloc_cluster_offset cannot handle the required allocations
> > atomically. This results in leaks if it allocated new clusters in any
> > but the last L2 table touched and an error occurs in qcow2_co_writev
> > before having established the L2 link. These non-atomic allocations
> > were, however, indeed successful and are therefore given to the caller
> > in the L2Meta list.
> >
> > If an error occurs in qcow2_co_writev and the L2Meta list is unwound,
> > all its remaining entries are clusters whose L2 links were not yet
> > established. Thus, all allocations in that list should be undone.
> >
> > Signed-off-by: Max Reitz <mreitz@redhat.com>
> > ---
> > block/qcow2.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/block/qcow2.c b/block/qcow2.c
> > index b2489fb..6bedd5d 100644
> > --- a/block/qcow2.c
> > +++ b/block/qcow2.c
> > @@ -1017,6 +1017,13 @@ fail:
> > while (l2meta != NULL) {
> > QCowL2Meta *next;
> >
> > + /* Undo all leaked allocations */
> > + if (l2meta->nb_clusters != 0) {
> > + qcow2_free_clusters(bs, l2meta->alloc_offset,
> > + l2meta->nb_clusters << s->cluster_bits,
> > + QCOW2_DISCARD_ALWAYS);
> > + }
> > +
> > if (l2meta->nb_clusters != 0) {
> > QLIST_REMOVE(l2meta, next_in_flight);
> > }
>
> This feels a bit risky.
>
> I think currently it does work, because qcow2_alloc_cluster_link_l2()
> can only return an error when it didn't update the L2 entry in the cache
> yet, but adding any error condition between that point and the L2Meta
> unwinding would result in corruption. I'm unsure, but perhaps a cluster
> leak is the lesser evil. Did you consider this? Do other people have an
> opinion on it?
I agree it's easy to make things worse by trying to free clusters in an
error path. I find these types of changes a lot of effort (to write and
review properly) for relatively little gain.
Stefan
next prev parent reply other threads:[~2013-10-11 9:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-10 8:52 [Qemu-devel] [PATCH 0/2] qcow2: Undo leaked allocations in co_writev Max Reitz
2013-10-10 8:52 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
2013-10-10 12:26 ` Kevin Wolf
2013-10-10 12:54 ` Max Reitz
2013-10-10 13:57 ` Kevin Wolf
2013-10-10 14:01 ` Max Reitz
2013-10-11 9:15 ` Stefan Hajnoczi [this message]
2013-10-10 8:52 ` [Qemu-devel] [PATCH 2/2] qemu-iotests: Extend test 026 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=20131011091546.GC28383@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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).