All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: pbonzini@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org,
	stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 4/6] commit: support commit active layer
Date: Fri, 13 Dec 2013 19:26:43 +0100	[thread overview]
Message-ID: <20131213182643.GN3916@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <1385444708-19439-5-git-send-email-famz@redhat.com>

Am 26.11.2013 um 06:45 hat Fam Zheng geschrieben:
> If active is top, it will be mirrored to base, (with block/mirror.c
> code), then the image is switched when user completes the block job.
> 
> QMP documentation is updated.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/mirror.c   | 11 +++++++++++
>  blockdev.c       |  9 +++++++--
>  qapi-schema.json |  5 +++--
>  3 files changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index 9be741a..86ffac8 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -478,6 +478,13 @@ immediate_exit:
>              bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
>          }
>          bdrv_swap(s->target, s->common.bs);
> +        if (s->common.driver->job_type == BLOCK_JOB_TYPE_COMMIT) {
> +            /* drop the bs loop chain formed by the swap: break the loop then
> +             * trigger the unref from the top one */
> +            BlockDriverState *p = s->base->backing_hd;
> +            s->base->backing_hd = NULL;
> +            bdrv_unref(p);

I'm not sure about the refcounts...

Let's assume we have the following backing file chain, refcount in
brackets:

                             +------ NBD server
                             v
base (1) <-- sn1 (1) <-- sn2 (3) <-- guest
                             ^
                             +------ something else ;-)

> +        }
>      }
>      bdrv_unref(s->target);
>      block_job_completed(&s->common, ret);
> @@ -619,6 +626,10 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
>                           BlockDriverCompletionFunc *cb,
>                           void *opaque, Error **errp)
>  {
> +    if (bdrv_reopen(base, bs->open_flags, errp)) {
> +        return;
> +    }
> +    bdrv_ref(base);

So when we start, the refcount changes as follows:

  +--- commit job            +------ NBD server
  v                          v
base (2) <-- sn1 (1) <-- sn2 (3) <-- guest
                             ^
                             +------ something else


Once all the data is copied over, we get o the code above, and first do
a bdrv_swap, which results in the following:

  +--- commit job            +------ NBD server
  v                          v
sn2 (2) <-- sn1 (1)     base (3) <-- guest
  |            ^             ^
  +------------+             +------ something else


Break the loop (but no refcount update!):

  +--- commit job            +------ NBD server
  v                          v
sn2 (2) <-- sn1 (1)     base (3) <-- guest
                             ^
                             +------ something else


Drop the commit job's reference:

                             +------ NBD server
                             v
sn2 (1) <-- sn1 (1)     base (3) <-- guest
                             ^
                             +------ something else


Okay, so writing this down made me actually understand what's wrong with
the refcount logic. You can't set s->base->backing_hd = NULL without
updating the reference count of the backing file.

Easy enough to fix. :-)

Kevin

  reply	other threads:[~2013-12-13 18:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-26  5:45 [Qemu-devel] [PATCH v6 0/6] block: allow commit active as top Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 1/6] mirror: don't close target Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 2/6] mirror: move base to MirrorBlockJob Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 3/6] block: add commit_active_start() Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 4/6] commit: support commit active layer Fam Zheng
2013-12-13 18:26   ` Kevin Wolf [this message]
2013-12-16  6:25     ` Fam Zheng
2013-12-14  3:10   ` Eric Blake
2013-12-16  6:28     ` Fam Zheng
2013-12-16  6:32       ` Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 5/6] qemu-iotests: update test cases for commit active Fam Zheng
2013-11-26  5:45 ` [Qemu-devel] [PATCH v6 6/6] commit: remove unused check Fam Zheng
2013-12-11  2:49 ` [Qemu-devel] [PATCH v6 0/6] block: allow commit active as top Fam Zheng
2013-12-13 18:28 ` Kevin Wolf

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=20131213182643.GN3916@dhcp-200-207.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=pbonzini@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 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.