From patchwork Fri Sep 6 15:38:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 273244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 38B992C036E for ; Sat, 7 Sep 2013 01:46:43 +1000 (EST) Received: from localhost ([::1]:38464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHyF7-0002sZ-3B for incoming@patchwork.ozlabs.org; Fri, 06 Sep 2013 11:46:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy8i-00058C-ND for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHy8c-0005EZ-Of for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy8c-0005EJ-I4 for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:39:58 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r86FdvnM004506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Sep 2013 11:39:57 -0400 Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r86FdtAI021569; Fri, 6 Sep 2013 11:39:56 -0400 From: Stefan Hajnoczi To: Date: Fri, 6 Sep 2013 17:38:46 +0200 Message-Id: <1378481953-23099-16-git-send-email-stefanha@redhat.com> In-Reply-To: <1378481953-23099-1-git-send-email-stefanha@redhat.com> References: <1378481953-23099-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Fam Zheng , Stefan Hajnoczi , Anthony Liguori Subject: [Qemu-devel] [PULL 15/42] xen_disk: simplify blk_disconnect with refcnt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Fam Zheng 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 Signed-off-by: Stefan Hajnoczi --- hw/block/xen_disk.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 8bfa04e..668cc06 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -824,6 +824,9 @@ static int blk_connect(struct XenDevice *xendev) /* setup via qemu cmdline -> already setup for us */ xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n"); blkdev->bs = blkdev->dinfo->bdrv; + /* blkdev->bs is not create by us, we get a reference + * so we can bdrv_unref() unconditionally */ + bdrv_ref(blkdev->bs); } bdrv_attach_dev_nofail(blkdev->bs, blkdev); blkdev->file_size = bdrv_getlength(blkdev->bs); @@ -922,12 +925,8 @@ 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_unref(blkdev->bs); - } + bdrv_detach_dev(blkdev->bs, blkdev); + bdrv_unref(blkdev->bs); blkdev->bs = NULL; } xen_be_unbind_evtchn(&blkdev->xendev);