From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1aC5-0003r8-9N for qemu-devel@nongnu.org; Tue, 23 Jul 2013 06:51:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1ZtO-0004IS-HN for qemu-devel@nongnu.org; Tue, 23 Jul 2013 06:33:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1ZtO-0004I9-7u for qemu-devel@nongnu.org; Tue, 23 Jul 2013 06:32:30 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6NAWSlP023279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Jul 2013 06:32:28 -0400 Date: Tue, 23 Jul 2013 18:32:25 +0800 From: Fam Zheng Message-ID: <20130723103225.GA7183@T430s.redhat.com> References: <1374054136-28741-1-git-send-email-famz@redhat.com> <1374054136-28741-2-git-send-email-famz@redhat.com> <20130723093600.GB20256@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130723093600.GB20256@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 01/11] block: replace in_use with refcnt_soft and refcnt_hard Reply-To: famz@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: kwolf@redhat.com, hbrock@redhat.com, qemu-devel@nongnu.org, rjones@redhat.com, imain@redhat.com, pbonzini@redhat.com On Tue, 07/23 11:36, Stefan Hajnoczi wrote: > On Wed, Jul 17, 2013 at 05:42:06PM +0800, Fam Zheng wrote: > > Introduce refcnt_soft (soft reference) and refcnt_hard (hard reference) > > to BlockDriverState, since in_use mechanism cannot provide proper > > management of lifecycle when a BDS is referenced in multiple places > > (e.g. pointed to by another bs's backing_hd while also used as a block > > job device, in the use case of image fleecing). > > > > The original in_use case is considered a "hard reference" in this patch, > > where the bs is busy and should not be used in other tasks that require > > a hard reference. (However the interface doesn't force this, caller > > still need to call bdrv_in_use() to check by itself.). > > > > A soft reference is implemented but not used yet. It will be used in > > following patches to manage the lifecycle together with hard reference. > > > > If bdrv_ref() is called on a BDS, it must be released by exactly the > > same numbers of bdrv_unref() with the same "soft/hard" type, and never > > call bdrv_delete() directly. If the BDS is only used locally (unnamed), > > bdrv_ref/bdrv_unref can be skipped and just use bdrv_delete(). > > It is risky to keep bdrv_delete() public. I suggest replacing > bdrv_delete() callers with bdrv_unref() and then making bdrv_delete() > static in block.c. > > This way it is impossible to make the mistake of calling bdrv_delete() > on a BDS which has refcnt > 1. > > I don't really understand this patch. There are now two separate > refcounts. They must both reach 0 for deletion to occur. I think > you plan to treat the "hard" refcount like the in_use counter (there > should only be 0 or 1 refs) but you don't enforce it. It seems cleaner > to keep in_use separate: let in_use callers take a refcount and also set > in_use. OK, I like your ideas, make bdrv_delete private is much cleaner. Will fix in next revision. I plan to make it like this: /* soft ref */ void bdrv_{ref,unref}(bs) /* hard ref */ bool bdrv_hard_{ref,unref}(bs) usage: bs = bdrv_new() ... bdrv_unref(bs) or with hard ref: bs = bdrv_new() bdrv_hard_ref(bs) ... bdrv_hard_unref(bs) bdrv_unref(bs) The second bdrv_hard_ref call to a bs returns false, caller check the return value. -- Fam