From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9mGV-0001S0-BC for qemu-devel@nongnu.org; Mon, 29 Jun 2015 23:31:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9mGT-0008IS-EG for qemu-devel@nongnu.org; Mon, 29 Jun 2015 23:31:19 -0400 From: Wen Congyang Date: Tue, 30 Jun 2015 11:34:29 +0800 Message-ID: <1435635285-5804-2-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1435635285-5804-1-git-send-email-wency@cn.fujitsu.com> References: <1435635285-5804-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-BLOCK v7 01/17] Add new block driver interface to add/delete a BDS's child List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini Cc: Kevin Wolf , qemu block , Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Stefan Hajnoczi , Yang Hongyang , zhanghailiang In some cases, we want to take a quorum child offline, and take another child online. Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- block.c | 39 +++++++++++++++++++++++++++++++++++++++ include/block/block.h | 4 ++++ include/block/block_int.h | 5 +++++ 3 files changed, 48 insertions(+) diff --git a/block.c b/block.c index 81233be..617e431 100644 --- a/block.c +++ b/block.c @@ -4207,3 +4207,42 @@ BlockAcctStats *bdrv_get_stats(BlockDriverState *bs) { return &bs->stats; } + +/* + * Hot add/remove a BDS's child. So the user can take a child offline when + * it is broken and take a new child online + */ +void bdrv_add_child(BlockDriverState *bs, QDict *options, Error **errp) +{ + + if (!bs->drv || !bs->drv->bdrv_add_child) { + error_setg(errp, "this feature or command is not currently supported"); + return; + } + + bs->drv->bdrv_add_child(bs, options, errp); +} + +void bdrv_del_child(BlockDriverState *bs, BlockDriverState *child_bs, + Error **errp) +{ + BdrvChild *child; + + if (!bs->drv || !bs->drv->bdrv_del_child) { + error_setg(errp, "this feature or command is not currently supported"); + return; + } + + QLIST_FOREACH(child, &bs->children, next) { + if (child->bs == child_bs) { + break; + } + } + + if (!child) { + error_setg(errp, "Invalid child"); + return; + } + + bs->drv->bdrv_del_child(bs, child_bs, errp); +} diff --git a/include/block/block.h b/include/block/block.h index 07bb724..c43160d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -605,4 +605,8 @@ void bdrv_flush_io_queue(BlockDriverState *bs); BlockAcctStats *bdrv_get_stats(BlockDriverState *bs); +void bdrv_add_child(BlockDriverState *bs, QDict *options, Error **errp); +void bdrv_del_child(BlockDriverState *bs, BlockDriverState *child, + Error **errp); + #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index b0476fc..d7af9e3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -288,6 +288,11 @@ struct BlockDriver { */ int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo); + void (*bdrv_add_child)(BlockDriverState *bs, QDict *options, + Error **errp); + void (*bdrv_del_child)(BlockDriverState *bs, BlockDriverState *child, + Error **errp); + QLIST_ENTRY(BlockDriver) list; }; -- 2.4.3