From patchwork Fri Jul 31 09:19:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 502452 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 138B01402A9 for ; Fri, 31 Jul 2015 19:23:40 +1000 (AEST) Received: from localhost ([::1]:43691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6XR-0007B9-TI for incoming@patchwork.ozlabs.org; Fri, 31 Jul 2015 05:23:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6Tb-000173-B8 for qemu-devel@nongnu.org; Fri, 31 Jul 2015 05:19:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZL6TX-0006nA-3K for qemu-devel@nongnu.org; Fri, 31 Jul 2015 05:19:39 -0400 Received: from [59.151.112.132] (port=57623 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL6TU-0006hx-T4; Fri, 31 Jul 2015 05:19:35 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99117525" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Jul 2015 17:22:52 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6V9HR7T006234; Fri, 31 Jul 2015 17:17:27 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 31 Jul 2015 17:19:19 +0800 From: Wen Congyang To: qemu devel , Eric Blake , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi Date: Fri, 31 Jul 2015 17:19:15 +0800 Message-ID: <1438334355-26914-7-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1438334355-26914-1-git-send-email-wency@cn.fujitsu.com> References: <1438334355-26914-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" , Luiz Capitulino , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [PATCH for-2.5 6/6] hmp: 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 Cc: Luiz Capitulino --- blockdev.c | 33 +++++++++++++++++++++++++++++++++ hmp-commands.hx | 28 ++++++++++++++++++++++++++++ include/sysemu/blockdev.h | 2 ++ 3 files changed, 63 insertions(+) diff --git a/blockdev.c b/blockdev.c index df40e92..4d9dfd9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2203,6 +2203,39 @@ static void do_child_add(const char *device, QDict *opts, Error **errp) } } +void hmp_child_add(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + const char *optstr = qdict_get_str(qdict, "opts"); + QemuOpts *opts; + QDict *bs_opts = qdict_new(); + Error *local_err = NULL; + + opts = drive_def(optstr); + if (!opts) { + /* We have reported error in drive_def */ + return; + } + + bs_opts = qemu_opts_to_qdict(opts, bs_opts); + do_child_add(id, bs_opts, &local_err); + if (local_err) { + error_report_err(local_err); + } +} + +void hmp_child_del(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + const char *child_id = qdict_get_str(qdict, "child"); + Error *local_err = NULL; + + qmp_child_del(id, child_id, &local_err); + if (local_err) { + error_report_err(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) diff --git a/hmp-commands.hx b/hmp-commands.hx index d3b7932..1d5b392 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -193,6 +193,34 @@ actions (drive options rerror, werror). ETEXI { + .name = "child_add", + .args_type = "id:B,opts:s", + .params = "device child.file=file", + .help = "add a child to a BDS", + .mhandler.cmd = hmp_child_add, + }, + +STEXI +@item child_add @var{device} @var{options} +@findex child_add +Add a child to the block device. +ETEXI + + { + .name = "child_del", + .args_type = "id:B,child:B", + .params = "parent child", + .help = "remove a child from a BDS", + .mhandler.cmd = hmp_child_del, + }, + +STEXI +@item child_del @var{parent device} @var{child device} +@findex child_del +Remove a child from the parent device. +ETEXI + + { .name = "change", .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]", diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 3104150..594bfab 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -67,4 +67,6 @@ void qmp_change_blockdev(const char *device, const char *filename, const char *format, Error **errp); void hmp_commit(Monitor *mon, const QDict *qdict); void hmp_drive_del(Monitor *mon, const QDict *qdict); +void hmp_child_add(Monitor *mon, const QDict *qdict); +void hmp_child_del(Monitor *mon, const QDict *qdict); #endif