From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrXRu-0003xb-0t for qemu-devel@nongnu.org; Fri, 13 Dec 2013 13:27:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrXRo-0006G4-1L for qemu-devel@nongnu.org; Fri, 13 Dec 2013 13:26:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrXRn-0006Fy-P2 for qemu-devel@nongnu.org; Fri, 13 Dec 2013 13:26:47 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBDIQkgD019623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Dec 2013 13:26:46 -0500 Date: Fri, 13 Dec 2013 19:26:43 +0100 From: Kevin Wolf Message-ID: <20131213182643.GN3916@dhcp-200-207.str.redhat.com> References: <1385444708-19439-1-git-send-email-famz@redhat.com> <1385444708-19439-5-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1385444708-19439-5-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v6 4/6] commit: support commit active layer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: pbonzini@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@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 > --- > 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