From patchwork Wed Apr 25 20:46:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 155109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7A962B6FEC for ; Thu, 26 Apr 2012 07:25:48 +1000 (EST) Received: from localhost ([::1]:55011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN9ic-0005K5-Bg for incoming@patchwork.ozlabs.org; Wed, 25 Apr 2012 17:25:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN97b-0000Mp-30 for qemu-devel@nongnu.org; Wed, 25 Apr 2012 16:47:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SN97X-0002Rd-LZ for qemu-devel@nongnu.org; Wed, 25 Apr 2012 16:47:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN97X-0002RN-DY for qemu-devel@nongnu.org; Wed, 25 Apr 2012 16:47:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3PKlOdk010466 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Apr 2012 16:47:24 -0400 Received: from localhost (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3PKlMmq032158; Wed, 25 Apr 2012 16:47:23 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2012 17:46:39 -0300 Message-Id: <1335386800-28845-16-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1335386800-28845-1-git-send-email-lcapitulino@redhat.com> References: <1335386800-28845-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 15/16] qapi: convert netdev_add 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 This is not a full QAPI conversion, but an intermediate step. In essence, do_netdev_add() is split into three functions: 1. netdev_add(): performs the actual work. This function is fully converted to Error (thus, it's "qapi-friendly") 2. qmp_netdev_add(): the QMP front-end for netdev_add(). This is coded by hand and not auto-generated (gen=no in the schema). The reason for this it's a lot easier and simpler to with QemuOpts this way 3. hmp_netdev_add(): HMP front-end. This design was suggested by Paolo Bonzini. Signed-off-by: Luiz Capitulino --- hmp-commands.hx | 3 +-- hmp.c | 21 +++++++++++++++++++++ hmp.h | 1 + net.c | 41 +++++++++++++++++++++++++++-------------- net.h | 3 ++- qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 82 insertions(+), 21 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 461fa59..408a195 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1009,8 +1009,7 @@ ETEXI .args_type = "netdev:O", .params = "[user|tap|socket],id=str[,prop=value][,...]", .help = "add host network device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_netdev_add, + .mhandler.cmd = hmp_netdev_add, }, STEXI diff --git a/hmp.c b/hmp.c index f3e5163..e70f278 100644 --- a/hmp.c +++ b/hmp.c @@ -14,6 +14,8 @@ */ #include "hmp.h" +#include "net.h" +#include "qemu-option.h" #include "qemu-timer.h" #include "qmp-commands.h" @@ -943,3 +945,22 @@ void hmp_device_del(Monitor *mon, const QDict *qdict) qmp_device_del(id, &err); hmp_handle_error(mon, &err); } + +void hmp_netdev_add(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + QemuOpts *opts; + + opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); + if (error_is_set(&err)) { + goto out; + } + + netdev_add(opts, &err); + if (error_is_set(&err)) { + qemu_opts_del(opts); + } + +out: + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 443b812..2fc041a 100644 --- a/hmp.h +++ b/hmp.h @@ -61,5 +61,6 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); void hmp_device_del(Monitor *mon, const QDict *qdict); +void hmp_netdev_add(Monitor *mon, const QDict *qdict); #endif diff --git a/net.c b/net.c index 7e9d0c5..5f0c53c 100644 --- a/net.c +++ b/net.c @@ -1234,27 +1234,39 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict) qemu_del_vlan_client(vc); } -int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) +void netdev_add(QemuOpts *opts, Error **errp) +{ + net_client_init(opts, 1, errp); +} + +int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret) { Error *local_err = NULL; + QemuOptsList *opts_list; QemuOpts *opts; - int res; - opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &local_err); - if (!opts) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + opts_list = qemu_find_opts_err("netdev", &local_err); + if (error_is_set(&local_err)) { + goto exit_err; } - res = net_client_init(opts, 1, &local_err); - if (res < 0) { - qerror_report_err(local_err); - error_free(local_err); + opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); + if (error_is_set(&local_err)) { + goto exit_err; + } + + netdev_add(opts, &local_err); + if (error_is_set(&local_err)) { qemu_opts_del(opts); + goto exit_err; } - return res; + return 0; + +exit_err: + qerror_report_err(local_err); + error_free(local_err); + return -1; } int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data) @@ -1447,15 +1459,16 @@ static int net_init_client(QemuOpts *opts, void *dummy) static int net_init_netdev(QemuOpts *opts, void *dummy) { Error *local_err = NULL; + int ret; - net_client_init(opts, 1, &local_err); + ret = net_client_init(opts, 1, &local_err); if (error_is_set(&local_err)) { qerror_report_err(local_err); error_free(local_err); return -1; } - return 0; + return ret; } int net_init_clients(void) diff --git a/net.h b/net.h index 7ee97e9..1eb9280 100644 --- a/net.h +++ b/net.h @@ -170,7 +170,8 @@ void net_check_clients(void); void net_cleanup(void); void net_host_device_add(Monitor *mon, const QDict *qdict); void net_host_device_remove(Monitor *mon, const QDict *qdict); -int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data); +void netdev_add(QemuOpts *opts, Error **errp); +int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret); int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" diff --git a/qapi-schema.json b/qapi-schema.json index 6499895..f6d7002 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1722,3 +1722,32 @@ # Since: 0.14.0 ## { 'command': 'device_del', 'data': {'id': 'str'} } + +## +# @netdev_add: +# +# Add a network backend. +# +# @type: the type of network backend. Current valid values are 'user', 'tap', +# 'vde', 'socket', 'dump' and 'bridge' +# +# @id: the name of the new network backend +# +# @props: #optional a list of properties to be passed to the backend in +# the format 'name=value', like 'ifname=tap0,script=no' +# +# Notes: The semantics of @props is not well defined. Future commands will be +# introduced that provide stronger typing for backend creation. +# +# Since: 0.14.0 +# +# Returns: Nothing on success +# If @type is not a valid network backend, DeviceNotFound +# If @id is not a valid identifier, InvalidParameterValue +# if @id already exists, DuplicateId +# If @props contains an invalid parameter for this backend, +# InvalidParameter +## +{ 'command': 'netdev_add', + 'data': {'type': 'str', 'id': 'str', '*props': '**'}, + 'gen': 'no' } diff --git a/qmp-commands.hx b/qmp-commands.hx index f972332..7411bca 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -606,10 +606,7 @@ EQMP { .name = "netdev_add", .args_type = "netdev:O", - .params = "[user|tap|socket],id=str[,prop=value][,...]", - .help = "add host network device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_netdev_add, + .mhandler.cmd_new = qmp_netdev_add, }, SQMP