From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYlDt-0006RQ-Pv for qemu-devel@nongnu.org; Sun, 06 Sep 2015 21:27:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZYlDs-0007wb-Ti for qemu-devel@nongnu.org; Sun, 06 Sep 2015 21:27:53 -0400 References: <1441183880-26993-1-git-send-email-wency@cn.fujitsu.com> <1441183880-26993-2-git-send-email-wency@cn.fujitsu.com> <55E717C7.5050303@redhat.com> From: Wen Congyang Message-ID: <55ECE7F1.9010007@cn.fujitsu.com> Date: Mon, 7 Sep 2015 09:27:13 +0800 MIME-Version: 1.0 In-Reply-To: <55E717C7.5050303@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 01/16] introduce a new API to enable/disable attach device model List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Yang Hongyang On 09/02/2015 11:37 PM, Eric Blake wrote: > On 09/02/2015 02:51 AM, Wen Congyang wrote: >> Signed-off-by: Wen Congyang >> --- >> block/block-backend.c | 24 ++++++++++++++++++++++++ >> include/sysemu/block-backend.h | 2 ++ >> 2 files changed, 26 insertions(+) >> >> diff --git a/block/block-backend.c b/block/block-backend.c >> index aee8a12..72d8b2c 100644 >> --- a/block/block-backend.c >> +++ b/block/block-backend.c >> @@ -344,6 +344,30 @@ void *blk_get_attached_dev(BlockBackend *blk) >> } >> >> /* >> + * Disable to attach a device mode to @blk. > > s/to attach/attaching/ > s/mode/model/ > > But I'm not even sure this patch makes sense. I'd rather see Max's work > go in that allows for a BB without a BDS as representing a drive without > media, because then it is clear - either a BB has an associated BDS (and > cannot attach another one), or it does not (and attaching is fine). Hmm, I think the API's name cause a misunderstanding. These APIs are used to check if the BB is used by some block device. It is very useful if we allow references for backing files. If the backing file referes an existing BDS that with BB, the block device can't use this BB at the same time. Thanks Wen Congyang > >> + * Return 0 on success, -EBUSY when a device model is attached already. >> + */ >> +int blk_disable_attach_dev(BlockBackend *blk) >> +{ >> + if (blk->dev) { >> + return blk->dev == (void *)-1 ? 0 : -EBUSY; >> + } >> + >> + blk->dev = (void *)-1; >> + return 0; >> +} >> + >> +/* >> + * Enable to attach a device mode to @blk. >> + */ >> +void blk_enable_attach_dev(BlockBackend *blk) >> +{ >> + if (blk->dev == (void *)-1) { > > At the very least, if we allow a special sentinel to represent a BB > without a BDS (other than NULL, the way Max's series does it), it should > at least be wrapped by a macro, rather than using '(void *)-1' at > multiple call sites. >