Message ID | 1457578181-27111-2-git-send-email-xiecl.fnst@cn.fujitsu.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu 10 Mar 2016 03:49:39 AM CET, Changlong Xie wrote: > From: Wen Congyang <wency@cn.fujitsu.com> > > In some cases, we want to take a quorum child offline, and take > another child online. > > Signed-off-by: Wen Congyang <wency@cn.fujitsu.com> > Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> > Signed-off-by: Gonglei <arei.gonglei@huawei.com> > Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com> > Reviewed-by: Max Reitz <mreitz@redhat.com> > + if (!tmp) { > + error_setg(errp, "The node %s does not have child named %s", > + bdrv_get_device_or_node_name(parent_bs), > + bdrv_get_device_or_node_name(child->bs)); > + return; I think it should be "does not have a child" or "does not have any child". With that corrected, Reviewed-by: Alberto Garcia <berto@igalia.com> Berto
On 03/10/2016 10:57 PM, Alberto Garcia wrote: > On Thu 10 Mar 2016 03:49:39 AM CET, Changlong Xie wrote: >> From: Wen Congyang <wency@cn.fujitsu.com> >> >> In some cases, we want to take a quorum child offline, and take >> another child online. >> >> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com> >> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> >> Signed-off-by: Gonglei <arei.gonglei@huawei.com> >> Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com> >> Reviewed-by: Max Reitz <mreitz@redhat.com> > >> + if (!tmp) { >> + error_setg(errp, "The node %s does not have child named %s", >> + bdrv_get_device_or_node_name(parent_bs), >> + bdrv_get_device_or_node_name(child->bs)); >> + return; > > I think it should be "does not have a child" or "does not have any > child". > > With that corrected, Ok, will fix in next version. Thanks -Xie > > Reviewed-by: Alberto Garcia <berto@igalia.com> > > Berto > > > . >
diff --git a/block.c b/block.c index ba24b8e..d48f441 100644 --- a/block.c +++ b/block.c @@ -4395,3 +4395,52 @@ void bdrv_refresh_filename(BlockDriverState *bs) QDECREF(json); } } + +/* + * 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 *parent_bs, BlockDriverState *child_bs, + Error **errp) +{ + + if (!parent_bs->drv || !parent_bs->drv->bdrv_add_child) { + error_setg(errp, "The node %s does not support adding a child", + bdrv_get_device_or_node_name(parent_bs)); + return; + } + + if (!QLIST_EMPTY(&child_bs->parents)) { + error_setg(errp, "The node %s already has a parent", + child_bs->node_name); + return; + } + + parent_bs->drv->bdrv_add_child(parent_bs, child_bs, errp); +} + +void bdrv_del_child(BlockDriverState *parent_bs, BdrvChild *child, Error **errp) +{ + BdrvChild *tmp; + + if (!parent_bs->drv || !parent_bs->drv->bdrv_del_child) { + error_setg(errp, "The node %s does not support removing a child", + bdrv_get_device_or_node_name(parent_bs)); + return; + } + + QLIST_FOREACH(tmp, &parent_bs->children, next) { + if (tmp == child) { + break; + } + } + + if (!tmp) { + error_setg(errp, "The node %s does not have child named %s", + bdrv_get_device_or_node_name(parent_bs), + bdrv_get_device_or_node_name(child->bs)); + return; + } + + parent_bs->drv->bdrv_del_child(parent_bs, child, errp); +} diff --git a/include/block/block.h b/include/block/block.h index 1c4f4d8..7378e74 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -582,4 +582,8 @@ void bdrv_drained_begin(BlockDriverState *bs); */ void bdrv_drained_end(BlockDriverState *bs); +void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child, + Error **errp); +void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp); + #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index 9ef823a..704efe5 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -305,6 +305,11 @@ struct BlockDriver { */ void (*bdrv_drain)(BlockDriverState *bs); + void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *child, + Error **errp); + void (*bdrv_del_child)(BlockDriverState *parent, BdrvChild *child, + Error **errp); + QLIST_ENTRY(BlockDriver) list; };