All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Kevin Wolf <kwolf@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: Mon, 16 Dec 2013 14:25:07 +0800	[thread overview]
Message-ID: <52AE9CC3.20600@redhat.com> (raw)
In-Reply-To: <20131213182643.GN3916@dhcp-200-207.str.redhat.com>

On 2013年12月14日 02:26, Kevin Wolf wrote:
> 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);

Dropping "p" here (points to sn1 in your example) recursively results in ...

>
> 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
>

... sn2(1) left alone. It is also reference by s->target and is 
bdrv_unref'ed right before block_job_completed(). So...

>
> Drop the commit job's reference:
>
>                               +------ NBD server
>                               v
> sn2 (1) <-- sn1 (1)     base (3) <-- guest
>                               ^
>                               +------ something else
>

you mean sn2 (1) <-- sn1 (1) is leaked but I double checked it is not. 
(Did you overlooked the bdrv_unref(p)?)

Fam

  reply	other threads:[~2013-12-16  6:25 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
2013-12-16  6:25     ` Fam Zheng [this message]
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=52AE9CC3.20600@redhat.com \
    --to=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@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.