From: Wen Congyang <wency@cn.fujitsu.com>
To: qemu devel <qemu-devel@nongnu.org>,
Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Alberto Garcia <berto@igalia.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, qemu block <qemu-block@nongnu.org>,
Jiang Yunhong <yunhong.jiang@intel.com>,
Dong Eddie <eddie.dong@intel.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Gonglei <arei.gonglei@huawei.com>,
Yang Hongyang <yanghy@cn.fujitsu.com>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PATCH for-2.5 5/6] qmp: add monitor command to add/remove a child
Date: Fri, 31 Jul 2015 17:19:14 +0800 [thread overview]
Message-ID: <1438334355-26914-6-git-send-email-wency@cn.fujitsu.com> (raw)
In-Reply-To: <1438334355-26914-1-git-send-email-wency@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
blockdev.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 32 +++++++++++++++++++++
qmp-commands.hx | 67 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 178 insertions(+)
diff --git a/blockdev.c b/blockdev.c
index 62a4586..df40e92 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2186,6 +2186,23 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)
aio_context_release(aio_context);
}
+static void do_child_add(const char *device, QDict *opts, Error **errp)
+{
+ BlockDriverState *bs;
+ Error *local_err = NULL;
+
+ bs = bdrv_lookup_bs(device, device, &local_err);
+ if (!bs) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ bdrv_add_child(bs, opts, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ }
+}
+
void qmp_block_resize(bool has_device, const char *device,
bool has_node_name, const char *node_name,
int64_t size, Error **errp)
@@ -3096,6 +3113,68 @@ fail:
qmp_output_visitor_cleanup(ov);
}
+void qmp_child_add(const char *device, BlockdevOptionsChild *options,
+ Error **errp)
+{
+ QmpOutputVisitor *ov = qmp_output_visitor_new();
+ QObject *obj;
+ QDict *qdict;
+ Error *local_err = NULL;
+
+ if (options->child->has_id || options->child->has_discard ||
+ options->child->has_cache || options->child->has_aio ||
+ options->child->has_rerror || options->child->has_werror ||
+ options->child->has_read_only || options->child->has_detect_zeroes) {
+ error_setg(errp, "id, discard, cache, aio, rerror, werror, readonly"
+ " and detect_zeroes cann't be used for child-add");
+ goto fail;
+ }
+
+ visit_type_BlockdevOptionsChild(qmp_output_get_visitor(ov),
+ &options, NULL, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ goto fail;
+ }
+
+ obj = qmp_output_get_qobject(ov);
+ qdict = qobject_to_qdict(obj);
+
+ qdict_flatten(qdict);
+
+ do_child_add(device, qdict, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ goto fail;
+ }
+
+fail:
+ qmp_output_visitor_cleanup(ov);
+}
+
+void qmp_child_del(const char *parent, const char *child, Error **errp)
+{
+ BlockDriverState *parent_bs, *child_bs;
+ Error *local_err = NULL;
+
+ parent_bs = bdrv_lookup_bs(parent, parent, &local_err);
+ if (!parent_bs) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ child_bs = bdrv_lookup_bs(child, child, &local_err);
+ if (!child_bs) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ bdrv_del_child(parent_bs, child_bs, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ }
+}
+
BlockJobInfoList *qmp_query_block_jobs(Error **errp)
{
BlockJobInfoList *head = NULL, **p_next = &head;
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 3ed8114..4d82944 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2122,3 +2122,35 @@
##
{ 'command': 'block-set-write-threshold',
'data': { 'node-name': 'str', 'write-threshold': 'uint64' } }
+
+{
+ 'struct': 'BlockdevOptionsChild',
+ 'data': { 'child': 'BlockdevOptions'} }
+
+##
+# @child-add
+#
+# Add a new child to quorum. This is useful to fix a broken quorum child.
+#
+# @device: graph node name or id which the child will be added to.
+#
+# @options: the options to create child BDS.
+#
+# Since: 2.5
+##
+{ 'command': 'child-add',
+ 'data' : { 'device': 'str', 'options': 'BlockdevOptionsChild' } }
+
+##
+# @child-del
+#
+# Remove a child from quorum. This is useful to fix a broken quorum child.
+#
+# @parent: graph node name or id from which the child will removed.
+#
+# @child: graph node name that will be removed.
+#
+# Since: 2.5
+##
+{ 'command': 'child-del',
+ 'data' : { 'parent': 'str', 'child': 'str' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index ba630b1..79a1146 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3872,6 +3872,73 @@ Example (2):
EQMP
{
+ .name = "child-add",
+ .args_type = "device:B,options:q",
+ .mhandler.cmd_new = qmp_marshal_input_child_add,
+ },
+
+SQMP
+child-add
+------------
+
+Add a child to a quorum node.
+
+This command is still a work in progress. It doesn't support all
+block drivers. Stay away from it unless you want it to help with
+its development.
+
+Arguments:
+
+- "device": the quorum's id or node name
+- "options": the new child options
+
+Example:
+
+-> { "execute": "child-add",
+ "arguments": {
+ "device": "disk1",
+ "options" : {
+ "child": {
+ "driver": "qcow2",
+ "file": {
+ "driver": "file",
+ "filename": "test.qcow2"
+ },
+ "node-name": "new_node"
+ }
+ }
+ }
+<- { "return": {} }
+
+EQMP
+
+ {
+ .name = "child-del",
+ .args_type = "parent:B,child:B",
+ .mhandler.cmd_new = qmp_marshal_input_child_del,
+ },
+
+SQMP
+child-del
+------------
+
+Delete a child from a quorum node. It can be used to remove a broken
+quorum child.
+
+Arguments:
+
+- "parent": the quorum's id or node name
+- "child": the child node-name which will be removed
+
+Example:
+
+-> { "execute": "child-del",
+ "arguments": { "parent": "disk1", "child": "new_node" } }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "query-named-block-nodes",
.args_type = "",
.mhandler.cmd_new = qmp_marshal_input_query_named_block_nodes,
--
2.4.3
next prev parent reply other threads:[~2015-07-31 9:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 9:19 [Qemu-devel] [PATCH for-2.5 0/6] qapi: child add/delete support Wen Congyang
2015-07-31 9:19 ` [Qemu-devel] [PATCH for-2.5 1/6] QAPI: move InetSocketAddress to qapi/common.json Wen Congyang
2015-08-07 13:10 ` Alberto Garcia
2015-07-31 9:19 ` [Qemu-devel] [PATCH for-2.5 2/6] support nbd driver in blockdev-add Wen Congyang
2015-08-07 12:48 ` Alberto Garcia
2015-07-31 9:19 ` [Qemu-devel] [PATCH for-2.5 3/6] Add new block driver interface to add/delete a BDS's child Wen Congyang
2015-08-06 14:33 ` Alberto Garcia
2015-08-07 1:03 ` Wen Congyang
2015-08-07 11:52 ` Alberto Garcia
2015-08-10 8:19 ` Alberto Garcia
2015-08-10 9:53 ` Wen Congyang
2015-07-31 9:19 ` [Qemu-devel] [PATCH for-2.5 4/6] quorum: implement block driver interfaces " Wen Congyang
2015-08-07 12:08 ` Alberto Garcia
2015-07-31 9:19 ` Wen Congyang [this message]
2015-08-07 13:12 ` [Qemu-devel] [PATCH for-2.5 5/6] qmp: add monitor command to add/remove a child Alberto Garcia
2015-08-10 1:00 ` Wen Congyang
2015-08-10 8:13 ` Alberto Garcia
2015-07-31 9:19 ` [Qemu-devel] [PATCH for-2.5 6/6] hmp: " Wen Congyang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438334355-26914-6-git-send-email-wency@cn.fujitsu.com \
--to=wency@cn.fujitsu.com \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eddie.dong@intel.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=yanghy@cn.fujitsu.com \
--cc=yunhong.jiang@intel.com \
--cc=zhang.zhanghailiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).