[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [Patch for-2.5 v2 3/6] Add new block driver interface to ad
From: |
Wen Congyang |
Subject: |
[Qemu-block] [Patch for-2.5 v2 3/6] Add new block driver interface to add/delete a BDS's child |
Date: |
Tue, 11 Aug 2015 15:51:26 +0800 |
In some cases, we want to take a quorum child offline, and take
another child online.
Signed-off-by: Wen Congyang <address@hidden>
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Gonglei <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
---
block.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/block/block.h | 4 ++++
include/block/block_int.h | 5 +++++
3 files changed, 52 insertions(+)
diff --git a/block.c b/block.c
index d088ee0..1746d99 100644
--- a/block.c
+++ b/block.c
@@ -4251,3 +4251,46 @@ 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, "The BDS %s doesn't support adding a child",
+ bdrv_get_device_or_node_name(bs));
+ 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, "The BDS %s doesn't support removing a child",
+ bdrv_get_device_or_node_name(bs));
+ return;
+ }
+
+ QLIST_FOREACH(child, &bs->children, next) {
+ if (child->bs == child_bs) {
+ break;
+ }
+ }
+
+ if (!child) {
+ error_setg(errp, "The BDS %s is not the BDS %s's child",
+ bdrv_get_device_or_node_name(child_bs),
+ bdrv_get_device_or_node_name(bs));
+ return;
+ }
+
+ bs->drv->bdrv_del_child(bs, child_bs, errp);
+}
diff --git a/include/block/block.h b/include/block/block.h
index 37916f7..4a03fb6 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -616,4 +616,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 14ad4c3..b6f2905 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