From patchwork Tue May 10 07:36:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 9054691 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5DB9B9F1D3 for ; Tue, 10 May 2016 07:34:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88DD6200F3 for ; Tue, 10 May 2016 07:34:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B35B200F2 for ; Tue, 10 May 2016 07:34:16 +0000 (UTC) Received: from localhost ([::1]:44897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b02BL-00060S-Ku for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 May 2016 03:34:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b02B3-0005m9-86 for qemu-devel@nongnu.org; Tue, 10 May 2016 03:34:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b02Ay-0005qS-R6 for qemu-devel@nongnu.org; Tue, 10 May 2016 03:33:57 -0400 Received: from [59.151.112.132] (port=5975 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b02Aq-0005jR-3k; Tue, 10 May 2016 03:33:46 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="6388749" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 May 2016 15:33:14 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id A939242B561A; Tue, 10 May 2016 15:33:12 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Tue, 10 May 2016 15:33:12 +0800 From: Changlong Xie To: qemu devel , Eric Blake , Alberto Garcia , Kevin Wolf , Max Reitz , Stefan Hajnoczi Date: Tue, 10 May 2016 15:36:39 +0800 Message-ID: <1462865799-19402-4-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1462865799-19402-1-git-send-email-xiecl.fnst@cn.fujitsu.com> References: <1462865799-19402-1-git-send-email-xiecl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: A939242B561A.A10C1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xiecl.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v14 3/3] qmp: add monitor command to add/remove a child X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Changlong Xie , qemu block , Jiang Yunhong , Dong Eddie , Markus Armbruster , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wen Congyang 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 Signed-off-by: Changlong Xie Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia --- blockdev.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 32 ++++++++++++++++++++++++++++++ qmp-commands.hx | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/blockdev.c b/blockdev.c index f1f520a..d16d449 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4092,6 +4092,61 @@ out: aio_context_release(aio_context); } +static BdrvChild *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; + } + } + + 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, *new_bs = NULL; + BdrvChild *p_child; + + parent_bs = bdrv_lookup_bs(parent, parent, errp); + if (!parent_bs) { + return; + } + + if (has_child == has_node) { + if (has_child) { + error_setg(errp, "The parameters child and node are in conflict"); + } else { + error_setg(errp, "Either child or node must be specified"); + } + return; + } + + if (has_child) { + p_child = bdrv_find_child(parent_bs, child); + if (!p_child) { + error_setg(errp, "Node '%s' does not have child '%s'", + parent, child); + return; + } + bdrv_del_child(parent_bs, p_child, 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 1d09079..98a20d2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2556,3 +2556,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. This +# 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.7 +## +{ 'command': 'x-blockdev-change', + 'data' : { 'parent': 'str', + '*child': 'str', + '*node': 'str' } } diff --git a/qmp-commands.hx b/qmp-commands.hx index de896a5..94847e5 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -4398,6 +4398,59 @@ 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 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. + +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. + +Arguments: +- "parent": the id or name of the parent node (json-string) +- "child": the name of a child under the given parent node (json-string, optional) +- "node": the name of the node that 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. + +Warning: The data in a new quorum child MUST be consistent with that of +the rest of the array. + +Example: + +Add a new node to a quorum +-> { "execute": "blockdev-add", + "arguments": { "options": { "driver": "raw", + "node-name": "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 = "query-named-block-nodes", .args_type = "", .mhandler.cmd_new = qmp_marshal_query_named_block_nodes,