From patchwork Thu Sep 10 04:06:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 516118 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D707140271 for ; Thu, 10 Sep 2015 14:27:58 +1000 (AEST) Received: from localhost ([::1]:46918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZtSm-0001gg-Dx for incoming@patchwork.ozlabs.org; Thu, 10 Sep 2015 00:27:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZt8c-0003Tp-5h for qemu-devel@nongnu.org; Thu, 10 Sep 2015 00:07:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZt8a-00057o-UA for qemu-devel@nongnu.org; Thu, 10 Sep 2015 00:07:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZt8a-00057c-E4 for qemu-devel@nongnu.org; Thu, 10 Sep 2015 00:07:04 -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 (Postfix) with ESMTPS id 0D0682ED13B; Thu, 10 Sep 2015 04:07:04 +0000 (UTC) Received: from red.redhat.com ([10.3.113.15]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8A46Zhq031165; Thu, 10 Sep 2015 00:07:03 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 9 Sep 2015 22:06:31 -0600 Message-Id: <1441857991-7309-30-git-send-email-eblake@redhat.com> In-Reply-To: <1441857991-7309-1-git-send-email-eblake@redhat.com> References: <1441857991-7309-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: marcandre.lureau@redhat.com, Jason Wang , armbru@redhat.com, Stefan Hajnoczi , DirtY.iCE.hu@gmail.com Subject: [Qemu-devel] [PATCH RFC v4 29/29] net: Complete qapi-fication of 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 We finally have all the required pieces for doing a type-safe representation of netdev_add as a flat union, where the discriminator 'type' now selects which additional members may appear in the "arguments" JSON object sent over QMP, while making no changes to the set of previously-valid QMP commands that would work, and without breaking command line parsing. Signed-off-by: Eric Blake --- include/net/net.h | 1 - net/net.c | 25 ++----------------------- qapi-schema.json | 15 +++------------ qmp-commands.hx | 2 +- 4 files changed, 6 insertions(+), 37 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 8c12eff..475f1e8 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -197,7 +197,6 @@ void net_cleanup(void); void hmp_host_net_add(Monitor *mon, const QDict *qdict); void hmp_host_net_remove(Monitor *mon, const QDict *qdict); void netdev_add(QemuOpts *opts, Error **errp); -void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp); int net_hub_id_for_client(NetClientState *nc, int *id); NetClientState *net_hub_port_find(int hub_id); diff --git a/net/net.c b/net/net.c index d1ec9aa..69456b2 100644 --- a/net/net.c +++ b/net/net.c @@ -1116,30 +1116,9 @@ void netdev_add(QemuOpts *opts, Error **errp) net_client_init(opts, true, errp); } -void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp) +void qmp_netdev_add(Netdev *netdev, Error **errp) { - Error *local_err = NULL; - QemuOptsList *opts_list; - QemuOpts *opts; - - opts_list = qemu_find_opts_err("netdev", &local_err); - if (local_err) { - goto out; - } - - opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); - if (local_err) { - goto out; - } - - netdev_add(opts, &local_err); - if (local_err) { - qemu_opts_del(opts); - goto out; - } - -out: - error_propagate(errp, local_err); + net_client_init1(netdev, true, errp); } void qmp_netdev_del(const char *id, Error **errp) diff --git a/qapi-schema.json b/qapi-schema.json index 02ccbb7..0b1c7ec 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2077,26 +2077,17 @@ # # Add a network backend. # -# @type: the type of network backend. Current valid values are 'user', 'tap', -# 'vde', 'socket', 'dump' and 'bridge' +# @type: the type of network backend; determines which additional arguments +# are valid. See Netdev documentation for more details. # # @id: the name of the new network backend # -# Additional arguments depend on the type. -# -# TODO This command effectively bypasses QAPI completely due to its -# "additional arguments" business. It shouldn't have been added to -# the schema in this form. It should be qapified properly, or -# replaced by a properly qapified command. -# # Since: 0.14.0 # # Returns: Nothing on success # If @type is not a valid network backend, DeviceNotFound ## -{ 'command': 'netdev_add', - 'data': {'type': 'str', 'id': 'str'}, - 'gen': false } # so we can get the additional arguments +{ 'command': 'netdev_add', 'data': 'Netdev', 'box': true } ## # @netdev_del: diff --git a/qmp-commands.hx b/qmp-commands.hx index 66f0300..eecfa86 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -900,7 +900,7 @@ EQMP { .name = "netdev_add", .args_type = "netdev:O", - .mhandler.cmd_new = qmp_netdev_add, + .mhandler.cmd_new = qmp_marshal_netdev_add, }, SQMP