From patchwork Tue Aug 11 07:51:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 505884 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 EE822140081 for ; Tue, 11 Aug 2015 17:52:53 +1000 (AEST) Received: from localhost ([::1]:33192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP4Md-0005fm-S4 for incoming@patchwork.ozlabs.org; Tue, 11 Aug 2015 03:52:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP4Lk-0003Sb-4X for qemu-devel@nongnu.org; Tue, 11 Aug 2015 03:51:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZP4Li-0001DA-I2 for qemu-devel@nongnu.org; Tue, 11 Aug 2015 03:51:56 -0400 Received: from [59.151.112.132] (port=47243 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP4Lg-00010x-Nl; Tue, 11 Aug 2015 03:51:54 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99501295" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Aug 2015 15:55:09 +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 t7B7pjl1019141; Tue, 11 Aug 2015 15:51:45 +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; Tue, 11 Aug 2015 15:51:45 +0800 From: Wen Congyang To: qemu devel , Eric Blake , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi Date: Tue, 11 Aug 2015 15:51:28 +0800 Message-ID: <1439279489-13338-6-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1439279489-13338-1-git-send-email-wency@cn.fujitsu.com> References: <1439279489-13338-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 for-2.5 v2 5/6] 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 | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 40 ++++++++++++++++++++++++++ qmp-commands.hx | 67 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 186 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..50292b9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2122,3 +2122,43 @@ ## { 'command': 'block-set-write-threshold', 'data': { 'node-name': 'str', 'write-threshold': 'uint64' } } + +## +# @BlockdevOptionsChild +# +# Driver specific block device options for child block device. +# +# Since: 2.5 +## +{ 'struct': 'BlockdevOptionsChild', + 'data': { 'child': 'BlockdevOptions' } } + +## +# @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. +# +# @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 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 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,