From patchwork Fri Nov 27 06:06:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 549310 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 AC45F1402D0 for ; Fri, 27 Nov 2015 17:09:42 +1100 (AEDT) Received: from localhost ([::1]:54845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2CE0-0000X9-L2 for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2015 01:09:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2CCN-0006Ws-78 for qemu-devel@nongnu.org; Fri, 27 Nov 2015 01:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2CCK-0006Xq-0q for qemu-devel@nongnu.org; Fri, 27 Nov 2015 01:07:59 -0500 Received: from [59.151.112.132] (port=26029 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2CCB-0006VJ-Ap; Fri, 27 Nov 2015 01:07:48 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="903911" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2015 14:07:30 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 3E06C4066D08; Fri, 27 Nov 2015 14:07:25 +0800 (CST) 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, 27 Nov 2015 14:07:24 +0800 From: Wen Congyang To: qemu devel , Eric Blake , Alberto Garcia , Kevin Wolf , Stefan Hajnoczi Date: Fri, 27 Nov 2015 14:06:37 +0800 Message-ID: <1448604397-14975-4-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1448604397-14975-1-git-send-email-wency@cn.fujitsu.com> References: <1448604397-14975-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner-ID: 3E06C4066D08.A90A5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wency@cn.fujitsu.com 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 , Markus Armbruster , "Dr. David Alan Gilbert" , Gonglei , zhanghailiang Subject: [Qemu-devel] [Patch v8 3/3] 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'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 Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 23 ++++++++++++++++++++++ qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/blockdev.c b/blockdev.c index 2b076fb..7d8a2b4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -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; diff --git a/qapi/block-core.json b/qapi/block-core.json index a07b13f..feb8da2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2400,3 +2400,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' } } diff --git a/qmp-commands.hx b/qmp-commands.hx index 9d8b42f..9b49d51 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -4285,6 +4285,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) +- "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. + +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.2" } } +<- { "return": {} } + +EQMP + + { .name = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,