From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1acH1N-0000b9-Q3 for qemu-devel@nongnu.org; Sat, 05 Mar 2016 13:33:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1acH1M-0007tg-GL for qemu-devel@nongnu.org; Sat, 05 Mar 2016 13:33:45 -0500 References: <1455615450-15138-1-git-send-email-xiecl.fnst@cn.fujitsu.com> <1455615450-15138-4-git-send-email-xiecl.fnst@cn.fujitsu.com> From: Max Reitz Message-ID: <56DB267D.9080202@redhat.com> Date: Sat, 5 Mar 2016 19:33:33 +0100 MIME-Version: 1.0 In-Reply-To: <1455615450-15138-4-git-send-email-xiecl.fnst@cn.fujitsu.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mdGcksjOFvbkOQM3g2WQcmJpsjK6rqb9J" Subject: Re: [Qemu-devel] [PATCH v10 3/3] qmp: add monitor command to add/remove a child List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Changlong Xie , qemu devel , Eric Blake , Alberto Garcia , Kevin Wolf , Stefan Hajnoczi Cc: qemu block , Jiang Yunhong , Dong Eddie , Markus Armbruster , "Dr. David Alan Gilbert" , Gonglei , zhanghailiang This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mdGcksjOFvbkOQM3g2WQcmJpsjK6rqb9J Content-Type: multipart/mixed; boundary="nPL9cLHh3f1Pn95h46TVHUA2wwwt4Be18" From: Max Reitz To: Changlong Xie , qemu devel , Eric Blake , Alberto Garcia , Kevin Wolf , Stefan Hajnoczi Cc: Markus Armbruster , "Dr. David Alan Gilbert" , Dong Eddie , Jiang Yunhong , Wen Congyang , qemu block , zhanghailiang , Gonglei Message-ID: <56DB267D.9080202@redhat.com> Subject: Re: [PATCH v10 3/3] qmp: add monitor command to add/remove a child References: <1455615450-15138-1-git-send-email-xiecl.fnst@cn.fujitsu.com> <1455615450-15138-4-git-send-email-xiecl.fnst@cn.fujitsu.com> In-Reply-To: <1455615450-15138-4-git-send-email-xiecl.fnst@cn.fujitsu.com> --nPL9cLHh3f1Pn95h46TVHUA2wwwt4Be18 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 16.02.2016 10:37, Changlong Xie wrote: > From: Wen Congyang >=20 > The new QMP command name is x-blockdev-change. It's just for adding/rem= oving > quorum's child now, and doesn't support all kinds of children, all kind= s of > operations, nor all block drivers. So it is experimental now. >=20 > Signed-off-by: Wen Congyang > Signed-off-by: zhanghailiang > Signed-off-by: Gonglei > Signed-off-by: Changlong Xie > --- > blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > qapi/block-core.json | 32 +++++++++++++++++++++++++++++++ > qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++++++++++++= ++++ > 3 files changed, 136 insertions(+) >=20 > diff --git a/blockdev.c b/blockdev.c > index 1f73478..ca040b0 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -3983,6 +3983,60 @@ out: > aio_context_release(aio_context); > } > =20 > +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) =3D=3D 0) { > + return child->bs; > + } > + } > + > + return NULL; > +} As I said for patch 1, making this function return a BdrvChild would be trivial... > + > +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 =3D NULL, *new_bs =3D NULL;= > + > + parent_bs =3D bdrv_lookup_bs(parent, parent, errp); > + if (!parent_bs) { > + return; > + } > + > + if (has_child =3D=3D has_node) { > + if (has_child) { > + error_setg(errp, "The parameters child and node are in con= flict"); > + } else { > + error_setg(errp, "Either child or node must be specified")= ; > + } > + return; > + } > + > + if (has_child) { > + child_bs =3D bdrv_find_child(parent_bs, child); > + if (!child_bs) { > + error_setg(errp, "Node '%s' does not have child '%s'", > + parent, child); > + return; > + } > + bdrv_del_child(parent_bs, child_bs, errp); =2E..and then we could pass the BdrvChild here. (It's your choice.) > + } > + > + if (has_node) { > + new_bs =3D 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 =3D NULL, **p_next =3D &head; > diff --git a/qapi/block-core.json b/qapi/block-core.json > index 33012b8..92eb7fe 100644 > --- a/qapi/block-core.json > +++ b/qapi/block-core.json > @@ -2482,3 +2482,35 @@ > ## > { '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 graph node. Currently only the > +# Quorum driver implements this feature to add or remove its child. Th= is > +# is useful to fix a broken quorum child. > +# > +# If @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 @node is not, @child will be detached from @parent. > +# > +# @parent: the id or name of the parent node. > +# > +# @child: #optional the name of a child under the given parent node. > +# > +# @node: #optional the name of the node that will be added. > +# > +# Note: this command is experimental, and its API is not stable. It > +# does not support all kinds of operations, all kinds of children, nor= > +# all block drivers. > +# > +# Warning: The data in a new quorum child MUST be consistent with that= of > +# the rest of the array. > +# > +# Since: 2.6 > +## > +{ 'command': 'x-blockdev-change', > + 'data' : { 'parent': 'str', > + '*child': 'str', > + '*node': 'str' } } > diff --git a/qmp-commands.hx b/qmp-commands.hx > index 020e5ee..1c9a06f 100644 > --- a/qmp-commands.hx > +++ b/qmp-commands.hx > @@ -4364,6 +4364,56 @@ Example: > EQMP > =20 > { > + .name =3D "x-blockdev-change", > + .args_type =3D "parent:B,child:B?,node:B?", > + .mhandler.cmd_new =3D 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 graph node. Currently only the > +Quorum driver implements this feature to add or remove its child. This= > +is useful to fix a broken quorum child. The explanation of its behavior is missing here (the second paragraph in the qapi/block-core.json comment). Max > + > +Arguments: > +- "parent": the id or name of the parent node (json-string) > +- "child": the name of a child under the given parent node (json-strin= g, optional) > +- "node": the name of the node that will be added (json-string, option= al) > + > +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. > + > +Warning: The data in a new quorum child MUST be consistent with that o= f > +the rest of the array. > + > +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 =3D "query-named-block-nodes", > .args_type =3D "", > .mhandler.cmd_new =3D qmp_marshal_query_named_block_nodes, >=20 --nPL9cLHh3f1Pn95h46TVHUA2wwwt4Be18-- --mdGcksjOFvbkOQM3g2WQcmJpsjK6rqb9J Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJW2yZ9AAoJEDuxQgLoOKytcXEH/2IFr53b8MiCk+BoICR8r2IS D/+3hK0GPmqr3jTR8d9goV/B9Oelqo08Lh4KLJdnDUiLA9jX3zWI0VZj3EPjaXvU gFIy5mc6rb8F1Ku+BXMP9llf5htwaTytz6BHULdL/pAKUFIhZMvKEaFrCE9CiV8o 1yt1PcZCSAg+0ueMBTeFk259YoOvTXFpCpMrkSloPKESyBWI/HBXEt+gXrsFXMof FagV7OiCHlAw0VkeBLnvXTfmjLoSoNIT082D9dYUBEgQ74nEAMax/uFPCJP2czpc 1y2C9mor3XJRUwtGyK3pjgRyybLzOZskvRpa0l7iLxf3TiCu5BQXMszJiCB1674= =RmgW -----END PGP SIGNATURE----- --mdGcksjOFvbkOQM3g2WQcmJpsjK6rqb9J--