In some cases, we want to take a quorum child offline, and take another child online.
Signed-off-by: Wen Congyang <we...@cn.fujitsu.com> Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Signed-off-by: Gonglei <arei.gong...@huawei.com> --- 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