From patchwork Thu Jul 25 09:01:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 261631 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 6C3BB2C00C5 for ; Thu, 25 Jul 2013 19:05:37 +1000 (EST) Received: from localhost ([::1]:34604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2HUI-0001w7-RM for incoming@patchwork.ozlabs.org; Thu, 25 Jul 2013 05:05:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2HRI-0007HE-Mv for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:02:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2HRF-0000n0-RY for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:02:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2HRF-0000mt-J7 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:02:21 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6P92Lc4017166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Jul 2013 05:02:21 -0400 Received: from T430s.redhat.com ([10.66.6.13]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6P925fT018668; Thu, 25 Jul 2013 05:02:19 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2013 17:01:43 +0800 Message-Id: <1374742906-4489-6-git-send-email-famz@redhat.com> In-Reply-To: <1374742906-4489-1-git-send-email-famz@redhat.com> References: <1374742906-4489-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 5/8] block: use BlockDriverState refcnt for device attach/detach 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 Signed-off-by: Fam Zheng --- block.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index dfa4be0..ce4d94b 100644 --- a/block.c +++ b/block.c @@ -1620,11 +1620,13 @@ int bdrv_attach_dev(BlockDriverState *bs, void *dev) return -EBUSY; } bs->dev = dev; + bdrv_ref(bs); bdrv_iostatus_reset(bs); return 0; } -/* TODO qdevified devices don't use this, remove when devices are qdevified */ +/* Attach a bs to dev, and increase its refcnt. + * TODO qdevified devices don't use this, remove when devices are qdevified */ void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev) { if (bdrv_attach_dev(bs, dev) < 0) { @@ -1632,10 +1634,13 @@ void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev) } } +/* Detach bs from device. This decreases its refcnt, and may consequently + * deletes it make bs an invalid pointer */ void bdrv_detach_dev(BlockDriverState *bs, void *dev) /* TODO change to DeviceState *dev when all users are qdevified */ { assert(bs->dev == dev); + bdrv_unref(bs); bs->dev = NULL; bs->dev_ops = NULL; bs->dev_opaque = NULL;