From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Wqz-0000ZS-Pz for qemu-devel@nongnu.org; Thu, 25 Jul 2013 21:30:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2Wql-0000AV-R3 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 21:29:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Wql-0000AB-H6 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 21:29:43 -0400 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 r6Q1Tga6014374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Jul 2013 21:29:42 -0400 Date: Thu, 25 Jul 2013 21:29:39 -0400 From: Jeff Cody Message-ID: <20130726012939.GA5445@localhost.localdomain> References: <1374742906-4489-1-git-send-email-famz@redhat.com> <1374742906-4489-9-git-send-email-famz@redhat.com> <20130725130141.GC19682@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130725130141.GC19682@localhost.localdomain> Subject: Re: [Qemu-devel] [PATCH 8/8] nbd: use BlockDriverState refcnt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Thu, Jul 25, 2013 at 09:01:41AM -0400, Jeff Cody wrote: > On Thu, Jul 25, 2013 at 05:01:46PM +0800, Fam Zheng wrote: > > Previously, nbd calls drive_get_ref() on the drive of bs. A BDS doesn't > > always have associated dinfo, which nbd doesn't care either. We already > > have BDS ref count, so use it to make it safe for a BDS w/o blockdev. > > > > Signed-off-by: Fam Zheng > > --- > > blockdev-nbd.c | 10 +--------- > > nbd.c | 5 +++++ > > 2 files changed, 6 insertions(+), 9 deletions(-) > > > > diff --git a/blockdev-nbd.c b/blockdev-nbd.c > > index 95f10c8..922cf56 100644 > > --- a/blockdev-nbd.c > > +++ b/blockdev-nbd.c > > @@ -69,12 +69,6 @@ static void nbd_close_notifier(Notifier *n, void *data) > > g_free(cn); > > } > > > > -static void nbd_server_put_ref(NBDExport *exp) > > -{ > > - BlockDriverState *bs = nbd_export_get_blockdev(exp); > > - drive_put_ref(drive_get_by_blockdev(bs)); > > -} > > - > > void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, > > Error **errp) > > { > > @@ -105,11 +99,9 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, > > writable = false; > > } > > > > - exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, > > - nbd_server_put_ref); > > + exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL); > > > > nbd_export_set_name(exp, device); > > - drive_get_ref(drive_get_by_blockdev(bs)); > > > > n = g_malloc0(sizeof(NBDCloseNotifier)); > > n->n.notify = nbd_close_notifier; > > diff --git a/nbd.c b/nbd.c > > index 2606403..f258cdd 100644 > > --- a/nbd.c > > +++ b/nbd.c > > @@ -881,6 +881,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, > > exp->nbdflags = nbdflags; > > exp->size = size == -1 ? bdrv_getlength(bs) : size; > > exp->close = close; > > + bdrv_ref(bs); > > return exp; > > } > > > > @@ -927,6 +928,10 @@ void nbd_export_close(NBDExport *exp) > > } > > nbd_export_set_name(exp, NULL); > > nbd_export_put(exp); > > + if (exp->bs) { > > + bdrv_unref(exp->bs); > > + exp->bs = NULL; > > + } > > Same thing here - if the refcnt is ever > 1, then this leaks exp->bs. > Nevermind - since bs continues to exist elsewhere (and would presumably be unrefed there), then this would not leak exp->bs. > > } > > > > void nbd_export_get(NBDExport *exp) > > -- > > 1.8.3.2 > > > >