[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [Patch v7 1/3] Add new block driver interface to add/delete
From: |
Wen Congyang |
Subject: |
[Qemu-devel] [Patch v7 1/3] Add new block driver interface to add/delete a BDS's child |
Date: |
Mon, 23 Nov 2015 14:23:43 +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: Eric Blake <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
---
block.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
include/block/block.h | 5 +++++
include/block/block_int.h | 5 +++++
3 files changed, 60 insertions(+)
diff --git a/block.c b/block.c
index adabdfb..ba5806e 100644
--- a/block.c
+++ b/block.c
@@ -4075,3 +4075,53 @@ 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 doesn't 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, BlockDriverState *child_bs,
+ Error **errp)
+{
+ BdrvChild *child;
+
+ if (!parent_bs->drv || !parent_bs->drv->bdrv_del_child) {
+ error_setg(errp, "The node %s doesn't support removing a child",
+ bdrv_get_device_or_node_name(parent_bs));
+ return;
+ }
+
+ QLIST_FOREACH(child, &parent_bs->children, next) {
+ if (child->bs == child_bs) {
+ break;
+ }
+ }
+
+ if (!child) {
+ error_setg(errp, "The node %s is not a child of %s",
+ bdrv_get_device_or_node_name(child_bs),
+ bdrv_get_device_or_node_name(parent_bs));
+ return;
+ }
+
+ parent_bs->drv->bdrv_del_child(parent_bs, child_bs, errp);
+}
diff --git a/include/block/block.h b/include/block/block.h
index 73edb1a..f5a73e2 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -637,4 +637,9 @@ 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, BlockDriverState *child,
+ Error **errp);
+
#endif
diff --git a/include/block/block_int.h b/include/block/block_int.h
index b30a8d1..ecd9ab3 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -301,6 +301,11 @@ struct BlockDriver {
*/
void (*bdrv_drain)(BlockDriverState *bs);
+ void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *child,
+ Error **errp);
+ void (*bdrv_del_child)(BlockDriverState *parent, BlockDriverState *child,
+ Error **errp);
+
QLIST_ENTRY(BlockDriver) list;
};
--
2.5.0