From patchwork Fri Oct 16 08:57:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 531153 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 9C1541402B2 for ; Fri, 16 Oct 2015 20:18:27 +1100 (AEDT) Received: from localhost ([::1]:52005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn19b-0003d5-Kr for incoming@patchwork.ozlabs.org; Fri, 16 Oct 2015 05:18:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0q7-00083u-6s for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:58:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn0q5-0002ui-TC for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:58:15 -0400 Received: from [59.151.112.132] (port=29450 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0q4-0002n4-Ib; Fri, 16 Oct 2015 04:58:13 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101913652" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Oct 2015 17:00:21 +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 t9G8vSjC018526; Fri, 16 Oct 2015 16:57:28 +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; Fri, 16 Oct 2015 16:57:56 +0800 From: Wen Congyang To: qemu devel , Eric Blake , Markus Armbruster , Alberto Garcia , Kevin Wolf , Stefan Hajnoczi Date: Fri, 16 Oct 2015 16:57:45 +0800 Message-ID: <1444985866-12969-4-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444985866-12969-1-git-send-email-wency@cn.fujitsu.com> References: <1444985866-12969-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: qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [PATCH v6 3/4] 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 The 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. Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- blockdev.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 40 +++++++++++++++++++++++++++ qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) diff --git a/blockdev.c b/blockdev.c index 6c8cce4..72efe5d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3086,6 +3086,82 @@ fail: qmp_output_visitor_cleanup(ov); } +void qmp_x_blockdev_change(ChangeOperation op, const char *parent, + bool has_child, const char *child, + bool has_new_node, const char *new_node, + Error **errp) +{ + BlockDriverState *parent_bs, *child_bs, *new_bs; + Error *local_err = NULL; + + parent_bs = bdrv_lookup_bs(parent, parent, &local_err); + if (!parent_bs) { + error_propagate(errp, local_err); + return; + } + + switch(op) { + case CHANGE_OPERATION_ADD: + if (has_child) { + error_setg(errp, "The operation %s doesn't support the parameter child", + ChangeOperation_lookup[op]); + return; + } + if (!has_new_node) { + error_setg(errp, "The operation %s needs the parameter new_node", + ChangeOperation_lookup[op]); + return; + } + break; + case CHANGE_OPERATION_DELETE: + if (has_new_node) { + error_setg(errp, "The operation %s doesn't support the parameter node", + ChangeOperation_lookup[op]); + return; + } + if (!has_child) { + error_setg(errp, "The operation %s needs the parameter child", + ChangeOperation_lookup[op]); + return; + } + default: + break; + } + + if (has_child) { + child_bs = bdrv_find_node(child); + if (!child_bs) { + error_setg(errp, "Node '%s' not found", child); + return; + } + } + + if (has_new_node) { + new_bs = bdrv_find_node(new_node); + if (!new_bs) { + error_setg(errp, "Node '%s' not found", new_node); + return; + } + } + + switch(op) { + case CHANGE_OPERATION_ADD: + bdrv_add_child(parent_bs, new_bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + break; + case CHANGE_OPERATION_DELETE: + bdrv_del_child(parent_bs, child_bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + break; + default: + break; + } +} + 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 bb2189e..361588f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2114,3 +2114,43 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } + +## +# @ChangeOperation: +# +# An enumeration of block device change operation. +# +# @add: Add a new block driver state to a existed block driver state. +# +# @delete: Delete a block driver state's child. +# +# Since: 2.5 +## +{ 'enum': 'ChangeOperation', + 'data': [ 'add', 'delete' ] } + +## +# @x-blockdev-change +# +# Dynamic reconfigure the block driver state graph. It can be used to +# add, remove, insert, 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. +# +# @operation: the chanage operation. It can be add, delete. +# +# @parent: the id or node name of which node will be changed. +# +# @child: the child node-name which will be deleted. +# +# @node: the new node-name which will be added. +# +# Note: this command is experimental, and not a stable API. +# +# Since: 2.5 +## +{ 'command': 'x-blockdev-change', + 'data' : { 'operation': 'ChangeOperation', + 'parent': 'str', + '*child': 'str', + '*node': 'str' } } diff --git a/qmp-commands.hx b/qmp-commands.hx index d2ba800..ede7b71 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3921,6 +3921,56 @@ Example (2): EQMP { + .name = "x-blockdev-change", + .args_type = "operation:s,parent:B,child:B?,node:B?", + .mhandler.cmd_new = qmp_marshal_x_blockdev_change, + }, + +SQMP +x-blockdev-change +------------ + +Dynamic reconfigure the block driver state graph. It can be used to +add, remove, insert, 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: +- "operation": the chanage operation. It can be add, delete. +- "parent": the id or node name of which node will be changed +- "child": the child node-name which will be delete +- "node": the new node-name which will be added + +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 +drivers. + +Example: + +Add a new quorum's node +-> { "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": { "operation": "add", + "parent": "disk1", + "node": "new_node" } } +<- { "return": {} } + +Delete a quorum's node +-> { "execute": "x-blockdev-change", + "arguments": { "operation": "delete", + "parent": "disk1", + "child": "new_node" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,