From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1ZF0-0003Q6-Gt for qemu-devel@nongnu.org; Tue, 23 Jul 2013 05:50:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1ZEx-0007Iv-Cy for qemu-devel@nongnu.org; Tue, 23 Jul 2013 05:50:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1ZEw-0007Iq-TZ for qemu-devel@nongnu.org; Tue, 23 Jul 2013 05:50:43 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6N9og71001408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Jul 2013 05:50:42 -0400 Date: Tue, 23 Jul 2013 11:50:40 +0200 From: Stefan Hajnoczi Message-ID: <20130723095040.GE20256@stefanha-thinkpad.redhat.com> References: <1374054136-28741-1-git-send-email-famz@redhat.com> <1374054136-28741-7-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1374054136-28741-7-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 06/11] xen_disk: simplify blk_disconnect with refcnt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, hbrock@redhat.com, qemu-devel@nongnu.org, rjones@redhat.com, imain@redhat.com, pbonzini@redhat.com On Wed, Jul 17, 2013 at 05:42:11PM +0800, Fam Zheng wrote: > We call bdrv_attach_dev when initializing whether or not bs is created > locally, so call bdrv_detach_dev and let the refcnt handle the > lifecycle. > > Signed-off-by: Fam Zheng > --- > hw/block/xen_disk.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c > index 247f32f..ae17acc 100644 > --- a/hw/block/xen_disk.c > +++ b/hw/block/xen_disk.c > @@ -910,12 +910,7 @@ static void blk_disconnect(struct XenDevice *xendev) > struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); > > if (blkdev->bs) { > - if (!blkdev->dinfo) { > - /* close/delete only if we created it ourself */ > - bdrv_close(blkdev->bs); > - bdrv_detach_dev(blkdev->bs, blkdev); > - bdrv_delete(blkdev->bs); > - } > + bdrv_detach_dev(blkdev->bs, blkdev); > blkdev->bs = NULL; > } > xen_be_unbind_evtchn(&blkdev->xendev); This reminds me that bdrv_detach_dev() needs a comment documenting that it decrements the refcount; bs may be deleted when the function returns and must not be accessed anymore.