qapi: child add/delete support
v7 cover qapi: child add/delete support
If quorum's child is broken, we can use mirror job to replace it. But sometimes, the user only need to remove the broken child, and add it later when the problem is fixed.
It is based on the Kevin's child name related patch:
http://repo.or.cz/qemu/kevin.git/commitdiff/b8f3aba84160564576a5a068398f20eca13768af
ChangLog:
v7:
1. Remove the qmp command x-blockdev-change's parameter operation according to Kevin's comments.
2. Remove the hmp command.
v6:
1. Use a single qmp command x-blockdev-change to replace x-blockdev-child-add and x-blockdev-child-delete
v5:
1. Address Eric Blake's comments
v4:
1. drop nbd driver's implementation. We can use human-monitor-command to do it.
2. Rename the command name.
v3:
1. Don't open BDS in bdrv_add_child(). Use the existing BDS which is created by the QMP command blockdev-add.
2. The driver NBD can support filename, path, host:port now.
v2:
1. Use bdrv_get_device_or_node_name() instead of new function bdrv_get_id_or_node_name()
2. Update the error message
3. Update the documents in block-core.json
Wen Congyang (3):
Add new block driver interface to add/delete a BDS's child
quorum: implement bdrv_add_child() and bdrv_del_child()
qmp: add monitor command to add/remove a child
block.c | 58 ++++++++++++++++++++-- block/quorum.c | 124 +++++++++++++++++++++++++++++++++++++++++++++- blockdev.c | 54 ++++++++++++++++++++ include/block/block.h | 9 ++++ include/block/block_int.h | 5 ++ qapi/block-core.json | 25 ++++++++++ qmp-commands.hx | 47 ++++++++++++++++++ 7 files changed, 316 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.0
PATCH v7 1/3 Add new block driver interface to add/delete a BDS's child
In some cases, we want to take a quorum child offline, and take another child online.
--- block.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 5 +++++ include/block/block_int.h | 5 +++++ 3 files changed, 60 insertions(+)
block.c +50 -0
@@ -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); +}
include/block/block.h +5 -0
@@ -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
include/block/block_int.h +5 -0
@@ -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; };
Signature · 1 line
2.5.0
PATCH v7 2/3 quorum: implement bdrv_add_child() and bdrv_del_child()
In reply to Wen Congyang--- block.c | 8 ++-- block/quorum.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++- include/block/block.h | 4 ++ 3 files changed, 130 insertions(+), 6 deletions(-)
block.c +4 -4
@@ -1085,10 +1085,10 @@ static int bdrv_fill_options(QDict **options, const char **pfilename,return 0 ; } -static BdrvChild *bdrv_attach_child (BlockDriverState *parent_bs, -BlockDriverState *child_bs, -const char *child_name, -const BdrvChildRole *child_role) +BdrvChild *bdrv_attach_child (BlockDriverState *parent_bs, +BlockDriverState *child_bs, +const char *child_name, +const BdrvChildRole *child_role) {BdrvChild *child =g_new (BdrvChild,1 ); *child = (BdrvChild ) {
block/quorum.c +122 -2
167 lines not on this page · raw message
include/block/block.h +4 -0
@@ -512,6 +512,10 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_ref (BlockDriverState *bs);void bdrv_unref (BlockDriverState *bs);void bdrv_unref_child (BlockDriverState *parent,BdrvChild *child); +BdrvChild *bdrv_attach_child (BlockDriverState *parent_bs, +BlockDriverState *child_bs, +const char *child_name, +const BdrvChildRole *child_role);bool bdrv_op_is_blocked (BlockDriverState *bs,BlockOpType op,Error **errp);void bdrv_op_block (BlockDriverState *bs,BlockOpType op,Error *reason);
Signature · 1 line
2.5.0
PATCH v7 3/3 qmp: add monitor command to add/remove a child
In reply to Wen CongyangThe new QMP command name is x-blockdev-change. It justs for adding/removing quorum's child now, and don't support all kinds of children, all kinds of operations, nor all block drivers. So it is experimental now.
--- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 25 ++++++++++++++++++++++++ qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)
blockdev.c +54 -0
@@ -3837,6 +3837,60 @@ out:aio_context_release (aio_context); } +static BlockDriverState *bdrv_find_child (BlockDriverState *parent_bs, +const char *child_name) +{ +BdrvChild *child; + + QLIST_FOREACH(child, &parent_bs->children, next) { +if (strcmp (child->name, child_name) ==0 ) { +return child->bs; + } + } + +return NULL ; +} + +void qmp_x_blockdev_change (const char *parent,bool has_child, +const char *child,bool has_node, +const char *node,Error **errp) +{ +BlockDriverState *parent_bs, *child_bs =NULL , *new_bs =NULL ; + + parent_bs =bdrv_lookup_bs (parent, parent, errp); +if (!parent_bs) { +return ; + } + +if (has_child == has_node) { +if (has_child) { +error_setg (errp,"The paramter child and node is conflict" ); + }else { +error_setg (errp,"Either child or node should be specified" ); + } +return ; + } + +if (has_child) { + child_bs =bdrv_find_child (parent_bs, child); +if (!child_bs) { +error_setg (errp,"Node '%s' doesn't have child %s" , + parent, child); +return ; + } +bdrv_del_child (parent_bs, child_bs, errp); + } + +if (has_node) { + new_bs =bdrv_find_node (node); +if (!new_bs) { +error_setg (errp,"Node '%s' not found" , node); +return ; + } +bdrv_add_child (parent_bs, new_bs, errp); + } +} +BlockJobInfoList *qmp_query_block_jobs (Error **errp) {BlockJobInfoList *head =NULL , **p_next = &head;
qapi/block-core.json +25 -0
@@ -2400,3 +2400,28 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } + +## +# @x-blockdev-change +# +# Dynamically reconfigure the block driver state graph. It can be used +# to add, remove, insert or replace a block driver state. Currently only +# the Quorum driver implements this feature to add or remove its child. +# This is useful to fix a broken quorum child. +# +# @operation: the change operation. It can be add, delete. +# +# @parent: the id or name of the node that will be changed. +# +# @child: #optional the name of the child that will be deleted. +# +# @node: #optional the name of the node will be added. +# +# Note: this command is experimental, and its API is not stable. +# +# Since: 2.6 +## +{ 'command': 'x-blockdev-change', + 'data' : { 'parent': 'str', + '*child': 'str', + '*node': 'str' } }
qmp-commands.hx +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-devel] [Patch v7 3/3] qmp: add monitor command to add/remove a child
Quoted 1 line · Wen Congyang
The new QMP command name is x-blockdev-change. It justs for adding/removing
s/It justs/It's just/
Quoted 1 line
quorum's child now, and don't support all kinds of children, all kinds of
s/don't/doesn't/
Quoted 12 lines
operations, nor all block drivers. So it is experimental now.
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>---
+++
b/qapi/block-core.jsonqapi/block-core.json +0
-0@@ -2400,3 +2400,28 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } }
qapi/block-core.json line 2412
Quoted 10 lines
qapi/block-core.json +10
-0+ +## +# @x-blockdev-change +# +# Dynamically reconfigure the block driver state graph. It can be used +# to add, remove, insert or replace a block driver state. Currently only +# the Quorum driver implements this feature to add or remove its child. +# This is useful to fix a broken quorum child. +# +# @operation: the change operation. It can be add, delete.
Documented but not present below. Are you missing a parameter, or should this line be deleted?
Quoted 19 lines
qapi/block-core.json +16
-0+# +# @parent: the id or name of the node that will be changed. +# +# @child: #optional the name of the child that will be deleted. +# +# @node: #optional the name of the node will be added. +# +# Note: this command is experimental, and its API is not stable. +# +# Since: 2.6 +## +{ 'command': 'x-blockdev-change', + 'data' : { 'parent': 'str', + '*child': 'str', + '*node': 'str' } } +++ b/qmp-commands.hx@@ -4285,6 +4285,53 @@ Example: EQMP
qapi/block-core.json Example: · line 4295
Quoted 10 lines
qapi/block-core.json +8
-0{ + .name = "x-blockdev-change", + .args_type = "parent:B,child:B?,node:B?", + .mhandler.cmd_new = qmp_marshal_x_blockdev_change, + }, + +SQMP +x-blockdev-change +------------
Make the --- divider as long as the text it is underlining.
Review Example: · line 4297
Quoted 2 lines
(quoted diff) +2
-0+ +Dynamic reconfigure the block driver state graph. It can be used to
s/Dynamic/Dynamically/
qmp-commands.hx Example: · line 4298
Quoted 1 line
qmp-commands.hx +1
-0+add, remove, insert, replace a block driver state. Currently only
s/replace/or replace/
Isn't 'add' and 'insert' the same thing?
qmp-commands.hx Example: · line 4304
Quoted 6 lines
qmp-commands.hx +6
-0+the Quorum driver implements this feature to add and remove its child. +This is useful to fix a broken quorum child. + +Arguments: +- "parent": the id or node name of which node will be changed +- "child": the child name which will be delete
s/delete/deleted/; mention that it is optional (if nothing is going to be delted)
qmp-commands.hx Example: · line 4305
Quoted 1 line
qmp-commands.hx +1
-0+- "node": the new node-name which will be added
mention that it is optional (if nothing is going to be added)
qmp-commands.hx Example: · line 4308
Quoted 3 lines
qmp-commands.hx +3
-0+ +Note: this command is experimental, and not a stable API. It doesn't +support all kinds of operations, all kindes of children, nor all block
s/kindes/kinds/
qmp-commands.hx Example: · line 4313
Quoted 5 lines
qmp-commands.hx +5
-0+drivers. + +Example: + +Add a new quorum's node
s/quorum's node/node to a quorum/
Quoted 25 lines
qmp-commands.hx +21
-0+-> { "execute": blockdev-add", + "arguments": { "options": { "driver": "raw", + "node-name": "new_node", + "id": "test_new_node", + "file": { "driver": "file", + "filename": "test.raw" } } } } +<- { "return": {} } +-> { "execute": "x-blockdev-change", + "arguments": { "parent": "disk1", + "node": "new_node" } } +<- { "return": {} } + +Delete a quorum's node +-> { "execute": "x-blockdev-change", + "arguments": { "parent": "disk1", + "child": "children.2" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [Patch v7 3/3] qmp: add monitor command to add/remove a child
Quoted 26 lines · Eric Blake
Quoted 1 line · Wen Congyang
The new QMP command name is x-blockdev-change. It justs for adding/removing
s/It justs/It's just/
Quoted 1 line
quorum's child now, and don't support all kinds of children, all kinds of
s/don't/doesn't/
Quoted 17 lines
operations, nor all block drivers. So it is experimental now.
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>---
+++
b/qapi/block-core.jsonqapi/block-core.json +5
-0@@ -2400,3 +2400,28 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } + +## +# @x-blockdev-change +# +# Dynamically reconfigure the block driver state graph. It can be used
Quoted 8 lines
qapi/block-core.json line 2412
Quoted 5 lines
qapi/block-core.json +5
-0+# to add, remove, insert or replace a block driver state. Currently only +# the Quorum driver implements this feature to add or remove its child. +# This is useful to fix a broken quorum child. +# +# @operation: the change operation. It can be add, delete.Documented but not present below. Are you missing a parameter, or should this line be deleted?
This line should be deleted.
Quoted 21 lines
Quoted 21 lines
qapi/block-core.json +16
-0+# +# @parent: the id or name of the node that will be changed. +# +# @child: #optional the name of the child that will be deleted. +# +# @node: #optional the name of the node will be added. +# +# Note: this command is experimental, and its API is not stable. +# +# Since: 2.6 +## +{ 'command': 'x-blockdev-change', + 'data' : { 'parent': 'str', + '*child': 'str', + '*node': 'str' } } +++ b/qmp-commands.hx@@ -4285,6 +4285,53 @@ Example: EQMP
Quoted 11 lines
qmp-commands.hx Example: · line 4295
Quoted 9 lines
qmp-commands.hx +8
-0{ + .name = "x-blockdev-change", + .args_type = "parent:B,child:B?,node:B?", + .mhandler.cmd_new = qmp_marshal_x_blockdev_change, + }, + +SQMP +x-blockdev-change +------------Make the --- divider as long as the text it is underlining.
OK
Quoted 11 lines
Review Example: · line 4297
Quoted 3 lines
(quoted diff) +2
-0+ +Dynamic reconfigure the block driver state graph. It can be used tos/Dynamic/Dynamically/
qmp-commands.hx Example: · line 4298
Quoted 1 line
qmp-commands.hx +1
-0+add, remove, insert, replace a block driver state. Currently onlys/replace/or replace/
Isn't 'add' and 'insert' the same thing?
'insert' means that a filter driver is inserted betweean A and B(A is B's parent).
Quoted 11 lines
qmp-commands.hx Example: · line 4304
Quoted 7 lines
qmp-commands.hx +6
-0+the Quorum driver implements this feature to add and remove its child. +This is useful to fix a broken quorum child. + +Arguments: +- "parent": the id or node name of which node will be changed +- "child": the child name which will be deletes/delete/deleted/; mention that it is optional (if nothing is going to be delted)
Quoted 3 lines
qmp-commands.hx Example: · line 4305
Quoted 1 line
qmp-commands.hx +1
-0+- "node": the new node-name which will be addedmention that it is optional (if nothing is going to be added)
OK
Quoted 7 lines
qmp-commands.hx Example: · line 4308
Quoted 4 lines
qmp-commands.hx +3
-0+ +Note: this command is experimental, and not a stable API. It doesn't +support all kinds of operations, all kindes of children, nor all blocks/kindes/kinds/
Quoted 7 lines
qmp-commands.hx Example: · line 4313
Quoted 5 lines
qmp-commands.hx +5
-0+drivers. + +Example: + +Add a new quorum's nodes/quorum's node/node to a quorum/
All comments will be addressed.
Thanks
Wen Congyang
Quoted 27 lines
Quoted 26 lines
qmp-commands.hx +21
-0+-> { "execute": blockdev-add", + "arguments": { "options": { "driver": "raw", + "node-name": "new_node", + "id": "test_new_node", + "file": { "driver": "file", + "filename": "test.raw" } } } } +<- { "return": {} } +-> { "execute": "x-blockdev-change", + "arguments": { "parent": "disk1", + "node": "new_node" } } +<- { "return": {} } + +Delete a quorum's node +-> { "execute": "x-blockdev-change", + "arguments": { "parent": "disk1", + "child": "children.2" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,
Signature · 3 lines
This message has been scanned for viruses and dangerous content by FCNIC, and is believed to be clean.