From patchwork Thu Sep 10 09:55:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 516207 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 09D4D140157 for ; Thu, 10 Sep 2015 19:56:47 +1000 (AEST) Received: from localhost ([::1]:48154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZyay-0000hW-Qm for incoming@patchwork.ozlabs.org; Thu, 10 Sep 2015 05:56:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZyaH-0007rq-Uo for qemu-devel@nongnu.org; Thu, 10 Sep 2015 05:56:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZyaG-0008Hq-Dx for qemu-devel@nongnu.org; Thu, 10 Sep 2015 05:56:01 -0400 Received: from [59.151.112.132] (port=30822 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZyaF-0008HI-Kz; Thu, 10 Sep 2015 05:56:00 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100563403" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Sep 2015 17:58:53 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8A9tiBF001069; Thu, 10 Sep 2015 17:55:44 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 10 Sep 2015 17:55:56 +0800 From: Wen Congyang To: qemu devel , Eric Blake , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi Date: Thu, 10 Sep 2015 17:55:04 +0800 Message-ID: <1441878905-5272-5-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441878905-5272-1-git-send-email-wency@cn.fujitsu.com> References: <1441878905-5272-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Kevin Wolf , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [PATCH v3 4/5] qmp: add monitor command to add/remove a child X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- blockdev.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 34 +++++++++++++++++++++++++++++++++ qmp-commands.hx | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) diff --git a/blockdev.c b/blockdev.c index bd47756..0a40607 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3413,6 +3413,53 @@ fail: qmp_output_visitor_cleanup(ov); } +void qmp_x_child_add(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_find_node(child); + if (!child_bs) { + error_setg(errp, "Node '%s' not found", child); + return; + } + + bdrv_add_child(parent_bs, child_bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } +} + +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_find_node(child); + if (!child_bs) { + error_setg(errp, "Node '%s' not found", child); + 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 e68a59f..b959577 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2272,3 +2272,37 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } + +## +# @x-child-add +# +# Add a new child to the parent BDS. Currently only the Quorum driver +# implements this feature. This is useful to fix a broken quorum child. +# +# @parent: graph node name or id which the child will be added to. +# +# @child: graph node name that will be added. +# +# Note: this command is experimental, and not a stable API. +# +# Since: 2.5 +## +{ 'command': 'x-child-add', + 'data' : { 'parent': 'str', 'child': 'str' } } + +## +# @child-del +# +# Remove a child from the parent BDS. Currently only the Quorum driver +# implements this feature. This is useful to fix a broken quorum child. +# Note, you can't remove a child if it would bring the quorum below its +# threshold. +# +# @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 495670b..139a23b 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -4053,6 +4053,59 @@ Example: EQMP { + .name = "x-child-add", + .args_type = "parent:B,child:B", + .mhandler.cmd_new = qmp_marshal_input_x_child_add, + }, + +SQMP +x-child-add +------------ + +Add a child to a quorum node. + +Arguments: + +- "parent": the quorum's id or node name +- "child": the child node-name which will be added + +Note: this command is experimental, and not a stable API. + +Example: + +-> { "execute": "x-child-add", + "arguments": { "parent": "disk1", "child": "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,