qapi: child add/delete support
v9 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.
ChangLog:
v9:
1. Rebase to the newest codes
2. Remove redundant codes in quorum_add_child() and quorum_del_child()
3. Fix typos and in qmp-commands.hx
v8:
1. Rebase to the newest codes
2. Address the comments from Eric Blake
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 | 122 +++++++++++++++++++++++++++++++++++++++++++++- blockdev.c | 54 ++++++++++++++++++++ include/block/block.h | 9 ++++ include/block/block_int.h | 5 ++ qapi/block-core.json | 23 +++++++++ qmp-commands.hx | 47 ++++++++++++++++++ 7 files changed, 312 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.3
PATCH v9 1/3 Add new block driver interface to add/delete a BDS's child
From: Wen Congyang <[email protected]>
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
@@ -4320,3 +4320,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
@@ -578,4 +578,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
@@ -303,6 +303,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
1.9.3
PATCH v9 2/3 quorum: implement bdrv_add_child() and bdrv_del_child()
In reply to Changlong XieFrom: Wen Congyang <[email protected]>
--- block.c | 8 ++-- block/quorum.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++- include/block/block.h | 4 ++ 3 files changed, 128 insertions(+), 6 deletions(-)
block.c +4 -4
@@ -1196,10 +1196,10 @@ static int bdrv_fill_options(QDict **options, const char *filename,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 +120 -2
165 lines not on this page · raw message
include/block/block.h +4 -0
@@ -513,6 +513,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
1.9.3
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
block/quorum.c static int quorum_open(BlockDriverState *bs, QDict *options, int flags, · line 886
Quoted 12 lines · Changlong Xie
block/quorum.c +2
-2@@ -875,9 +878,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto exit; } -if (s->num_children <2 ) { +if (s->num_children <1 ) {error_setg (&local_err, -"Number of provided children must be greater than 1" ); +"Number of provided children must be 1 or more" ); ret = -EINVAL ; goto exit; }
I have a question: if you have a Quorum with just one member and you add a new one, how do you know if it has the same data as the existing one?
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Berto
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 17 lines · Alberto Garcia
block/quorum.c static int quorum_open(BlockDriverState *bs, QDict *options, int flags, · line 886
Quoted 12 lines · Changlong Xie
block/quorum.c +2
-2@@ -875,9 +878,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto exit; } -if (s->num_children <2 ) { +if (s->num_children <1 ) {error_setg (&local_err, -"Number of provided children must be greater than 1" ); +"Number of provided children must be 1 or more" ); ret = -EINVAL ; goto exit; }I have a question: if you have a Quorum with just one member and you add a new one, how do you know if it has the same data as the existing one?
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Thanks
Wen Congyang
Quoted 6 lines
Berto
.
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 17 lines · Wen Congyang
Quoted 17 lines
block/quorum.c static int quorum_open(BlockDriverState *bs, QDict *options, int flags, · line 886
Quoted 12 lines
block/quorum.c +2
-2@@ -875,9 +878,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto exit; } -if (s->num_children <2 ) { +if (s->num_children <1 ) {error_setg (&local_err, -"Number of provided children must be greater than 1" ); +"Number of provided children must be 1 or more" ); ret = -EINVAL ; goto exit; }I have a question: if you have a Quorum with just one member and you add a new one, how do you know if it has the same data as the existing one?
Quoted 5 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
Berto
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 22 lines · Alberto Garcia
Quoted 20 lines · Wen Congyang
Quoted 19 lines
block/quorum.c static int quorum_open(BlockDriverState *bs, QDict *options, int flags, · line 886
Quoted 12 lines
block/quorum.c +2
-2@@ -875,9 +878,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto exit; } -if (s->num_children <2 ) { +if (s->num_children <1 ) {error_setg (&local_err, -"Number of provided children must be greater than 1" ); +"Number of provided children must be 1 or more" ); ret = -EINVAL ; goto exit; }I have a question: if you have a Quorum with just one member and you add a new one, how do you know if it has the same data as the existing one?
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quoted 6 lines
Quoted 2 lines
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 6 lines · Eric Blake
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Quoted 8 lines
Quoted 3 lines
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
But the backing file is read-only so the user can guarantee that the destination has the same data before the shallow mirror. How do you do that in this case?
Berto
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 11 lines · * Alberto Garcia ([email protected]) wrote:
Quoted 10 lines · Eric Blake
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
Quoted 8 lines
Quoted 4 lines
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
But the backing file is read-only so the user can guarantee that the destination has the same data before the shallow mirror. How do you do that in this case?
I think in the colo case they're relying on doing a block migrate to synchronise the remote disk prior to switching into colo mode.
Dave
Quoted 1 line
Berto
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 17 lines · Dr. David Alan Gilbert
Quoted 16 lines · * Alberto Garcia ([email protected]) wrote:
Quoted 14 lines · Eric Blake
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
Quoted 6 lines
Quoted 3 lines
But the backing file is read-only so the user can guarantee that the destination has the same data before the shallow mirror. How do you do that in this case?
I think in the colo case they're relying on doing a block migrate to synchronise the remote disk prior to switching into colo mode.
Yes, we can do a block migration to sync the disk. After the migration finished, we stop block migration before starting colo.
Thanks
Wen Congyang
Quoted 10 lines
Dave
Quoted 1 line
Berto
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
In reply to Dr. David Alan GilbertQuoted 17 lines · Dr. David Alan Gilbert
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
Quoted 6 lines
Quoted 3 lines
But the backing file is read-only so the user can guarantee that the destination has the same data before the shallow mirror. How do you do that in this case?
I think in the colo case they're relying on doing a block migrate to synchronise the remote disk prior to switching into colo mode.
Yes but this is a general API that can be used independently from COLO. I'd say if we want to allow that we should at least place a big warning in the documentation.
Berto
Re: [Qemu-devel] [PATCH v9 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Quoted 23 lines · Alberto Garcia
Quoted 21 lines · Dr. David Alan Gilbert
Quoted 20 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
In general, what do you do to make sure that the data in a new Quorum child is consistent with that of the rest of the array?
Quorum can have more than one child when it starts. But we don't do the similar check. So I don't think we should do such check here.
Yes, but when you start a VM you can verify in advance that all members of the Quorum have the same data. If you do that on a running VM how can you know if the new disk is consistent with the others?
Quoted 4 lines
User error if it is not. Just the same as it is user error if you request a shallow drive-mirror but the destination is not the same contents as the backing file. I don't think qemu has to protect us from user error in this case.
But the backing file is read-only so the user can guarantee that the destination has the same data before the shallow mirror. How do you do that in this case?
Quoted 7 lines
Quoted 2 lines
I think in the colo case they're relying on doing a block migrate to synchronise the remote disk prior to switching into colo mode.
Yes but this is a general API that can be used independently from COLO. I'd say if we want to allow that we should at least place a big warning in the documentation.
Ok, that's fair enough. Will add in next version.
Thanks
-Xie
Quoted 5 lines
Berto
.
PATCH v9 3/3 qmp: add monitor command to add/remove a child
In reply to Changlong XieFrom: Wen Congyang <[email protected]>
The new QMP command name is x-blockdev-change. It's just for adding/removing quorum's child now, and doesn'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 | 23 ++++++++++++++++++++++ qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+)
blockdev.c +54 -0
@@ -3836,6 +3836,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 +23 -0
@@ -2408,3 +2408,26 @@ ## { '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. +# +# @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
1.9.3
Re: [Qemu-devel] [Qemu-block] [PATCH v9 3/3] qmp: add monitor command to add/remove a child
Quoted 42 lines · Changlong Xie
From: Wen Congyang <[email protected]>
The new QMP command name is x-blockdev-change. It's just for adding/removing quorum's child now, and doesn't support all kinds of children, all kinds of 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]>Signed-off-by Changlong Xie <[email protected]>--- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 23 ++++++++++++++++++++++ qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+)blockdev.c +18
-0@@ -3836,6 +3836,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) +{
blockdev.c out: · line 3866
Quoted 10 lines
blockdev.c +10
-0+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" );
"The parameters child and node are in conflict"
Or, more naturally:
"child and node may not be specified at the same time"
blockdev.c out: · line 3868
Quoted 2 lines
blockdev.c +2
-0+ }else { +error_setg (errp,"Either child or node should be specified" );
s/should/must/
blockdev.c out: · line 3876
Quoted 8 lines
blockdev.c +8
-0+ } +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",
s/doesn't/does not/
(This is a personal opinion, but a pretty strong one.)
Also, if you put quotes around the node name, maybe you should do the same around the child name.
Quoted 24 lines
blockdev.c +16
-0+ 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 +0
-0
qapi/block-core.json line 2416
Quoted 9 lines
qapi/block-core.json +6
-0@@ -2408,3 +2408,26 @@ ## { '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
I'd prefer "graph node" over BDS in this line.
qapi/block-core.json line 2419
Quoted 3 lines
qapi/block-core.json +3
-0+# the Quorum driver implements this feature to add or remove its child. +# This is useful to fix a broken quorum child. +#
I'd like a list here what this command does depending on the parameters given. For instance:
If @(new-)node is specified, it will be inserted under @parent. @child may not be specified in this case.
If both @parent and @child are specified but @(new-)node is not, @child will be detached from @parent.
qapi/block-core.json line 2420
Quoted 1 line
qapi/block-core.json +1
-0+# @parent: the id or name of the node that will be changed.
I don't know. The parent will actually not be changed, it's an edge that will be changed; and the parent is the parent node of that edge. Just put
@parent: the id or name of the parent node
here.
qapi/block-core.json line 2422
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @child: #optional the name of the child that will be deleted.
For now. But maybe that will change in the future. Generally, it is just the child node of the edge that will be changed. So just putting
@child: #optional the name of a child under the given parent node
(Let's hope this is clear enough that people know that this is not a node name.)
qapi/block-core.json line 2424
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @node: #optional the name of the node will be added.
Maybe this should be named new-node instead.
Also: "...of the node that will be added."
Quoted 29 lines
qapi/block-core.json +9
-0+# +# 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 +12
-0@@ -4293,6 +4293,53 @@ Example: EQMP { + .name = "x-blockdev-change", + .args_type = "parent:B,child:B?,node:B?", + .mhandler.cmd_new = qmp_marshal_x_blockdev_change, + }, + +SQMP +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 and remove its child.
qmp-commands.hx Example: · line 4317
Quoted 10 lines
qmp-commands.hx +10
-0+This is useful to fix a broken quorum child. + +Arguments: +- "parent": the id or node name of which node will be changed (json-string) +- "child": the child name which will be deleted (json-string, optional) +- "node": the new node-name which will be added (json-string, optional) + +Note: this command is experimental, and not a stable API. It doesn't +support all kinds of operations, all kinds of children, nor all block +drivers.
I think this second sentence should be present in qapi/block-core.json as well.
Max
Quoted 29 lines
qmp-commands.hx +25
-0+ +Example: + +Add a new node to a quorum +-> { "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.1" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,
Re: [Qemu-devel] [Qemu-block] [PATCH v9 3/3] qmp: add monitor command to add/remove a child
Quoted 56 lines · Max Reitz
Quoted 42 lines · Changlong Xie
From: Wen Congyang <[email protected]>
The new QMP command name is x-blockdev-change. It's just for adding/removing quorum's child now, and doesn't support all kinds of children, all kinds of 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]>Signed-off-by Changlong Xie <[email protected]>--- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 23 ++++++++++++++++++++++ qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+)blockdev.c +18
-0@@ -3836,6 +3836,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) +{blockdev.c out: · line 3866
Quoted 10 lines
blockdev.c +10
-0+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" );"The parameters child and node are in conflict"
Quoted 4 lines
Or, more naturally:
"child and node may not be specified at the same time"
OK
Quoted 4 lines
blockdev.c out: · line 3868
Quoted 2 lines
blockdev.c +2
-0+ }else { +error_setg (errp,"Either child or node should be specified" );s/should/must/
Ok
Quoted 10 lines
blockdev.c out: · line 3876
Quoted 9 lines
blockdev.c +8
-0+ } +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",
Quoted 6 lines
s/doesn't/does not/
(This is a personal opinion, but a pretty strong one.)
Also, if you put quotes around the node name, maybe you should do the same around the child name.
OK
Quoted 28 lines
Quoted 28 lines
blockdev.c +16
-0+ 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 +0
-0@@ -2408,3 +2408,26 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } }
Quoted 8 lines
qapi/block-core.json line 2416
Quoted 6 lines
qapi/block-core.json +6
-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 onlyI'd prefer "graph node" over BDS in this line.
ok
Quoted 8 lines
qapi/block-core.json line 2419
Quoted 4 lines
qapi/block-core.json +3
-0+# the Quorum driver implements this feature to add or remove its child. +# This is useful to fix a broken quorum child. +#I'd like a list here what this command does depending on the parameters given. For instance:
Quoted 6 lines
If @(new-)node is specified, it will be inserted under @parent. @child may not be specified in this case.
If both @parent and @child are specified but @(new-)node is not, @child will be detached from @parent.
ok
Quoted 9 lines
qapi/block-core.json line 2420
Quoted 1 line
qapi/block-core.json +1
-0+# @parent: the id or name of the node that will be changed.I don't know. The parent will actually not be changed, it's an edge that will be changed; and the parent is the parent node of that edge. Just put
@parent: the id or name of the parent node
here.
Yes, you are right here.
Quoted 11 lines
qapi/block-core.json line 2422
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @child: #optional the name of the child that will be deleted.For now. But maybe that will change in the future. Generally, it is just the child node of the edge that will be changed. So just putting
@child: #optional the name of a child under the given parent node
(Let's hope this is clear enough that people know that this is not a node name.)
ok
Quoted 6 lines
qapi/block-core.json line 2424
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @node: #optional the name of the node will be added.Maybe this should be named new-node instead.
Also: "...of the node that will be added."
Yes, it's more clear.
Quoted 35 lines
Quoted 35 lines
qapi/block-core.json +9
-0+# +# 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 +17
-0@@ -4293,6 +4293,53 @@ Example: EQMP { + .name = "x-blockdev-change", + .args_type = "parent:B,child:B?,node:B?", + .mhandler.cmd_new = qmp_marshal_x_blockdev_change, + }, + +SQMP +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 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 (json-string) +- "child": the child name which will be deleted (json-string, optional)
Quoted 8 lines
qmp-commands.hx Example: · line 4317
Quoted 5 lines
qmp-commands.hx +5
-0+- "node": the new node-name which will be added (json-string, optional) + +Note: this command is experimental, and not a stable API. It doesn't +support all kinds of operations, all kinds of children, nor all block +drivers.I think this second sentence should be present in
qapi/block-core.jsonas well.
Will *highlight* it in qapi/block-core.json. Thanks for your review.
Thanks
-Xie
Quoted 34 lines
Max
Quoted 29 lines
qmp-commands.hx +25
-0+ +Example: + +Add a new node to a quorum +-> { "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.1" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,
Ping...
Quoted 49 lines · Changlong Xie
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.
ChangLog:
v9:
1. Rebase to the newest codes
2. Remove redundant codes inquorum_add_child()andquorum_del_child()
3. Fix typos and in qmp-commands.hx
v8:
1. Rebase to the newest codes
2. Address the comments from Eric Blake
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 inbdrv_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. Usebdrv_get_device_or_node_name()instead of new functionbdrv_get_id_or_node_name()
2. Update the error message
3. Update the documents in block-core.jsonWen Congyang (3):
Add new block driver interface to add/delete a BDS's child
quorum: implementbdrv_add_child()andbdrv_del_child()
qmp: add monitor command to add/remove a childblock.c | 58 ++++++++++++++++++++-- block/quorum.c | 122 +++++++++++++++++++++++++++++++++++++++++++++- blockdev.c | 54 ++++++++++++++++++++ include/block/block.h | 9 ++++ include/block/block_int.h | 5 ++ qapi/block-core.json | 23 +++++++++ qmp-commands.hx | 47 ++++++++++++++++++ 7 files changed, 312 insertions(+), 6 deletions(-)