From patchwork Sun Jul 3 02:58:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 643675 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 3rhw5C73w3z9t0d for ; Sun, 3 Jul 2016 13:05:50 +1000 (AEST) Received: from localhost ([::1]:40954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJXj9-0003aP-Qk for incoming@patchwork.ozlabs.org; Sat, 02 Jul 2016 23:05:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJXck-0003jc-U9 for qemu-devel@nongnu.org; Sat, 02 Jul 2016 22:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJXcj-0002hf-M2 for qemu-devel@nongnu.org; Sat, 02 Jul 2016 22:59:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJXcj-0002hV-DS for qemu-devel@nongnu.org; Sat, 02 Jul 2016 22:59:09 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0B35C049D59 for ; Sun, 3 Jul 2016 02:59:08 +0000 (UTC) Received: from red.redhat.com (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u632wpes006603; Sat, 2 Jul 2016 22:59:08 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 2 Jul 2016 20:58:47 -0600 Message-Id: <1467514729-29366-15-git-send-email-eblake@redhat.com> In-Reply-To: <1467514729-29366-1-git-send-email-eblake@redhat.com> References: <1467514729-29366-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 03 Jul 2016 02:59:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 14/16] net: Complete qapi-fication of netdev_add 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: Jason Wang , armbru@redhat.com, Luiz Capitulino Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, and exposes those types through introspection, and without breaking command line parsing. Inline the function netdev_add() into its lone remaining caller. There are a few places where the QMP 'netdev_add' command is now more strict: anywhere that the QAPI lists an integer member, we now require a strict JSON integer (previously, we allowed both integers and strings, because the conversion from QMP to QemuOpts back to QObject collapsed them into integers). For example, pre-patch, both of these examples succeed, but post-patch, the second example fails: {'execute':'netdev_add', 'arguments':{'id':'net1', 'type':'hubport', 'hubid':1}} {"return": {}} {'execute':'netdev_add', 'arguments':{'id':'net2', 'type':'hubport', 'hubid':"2"}} {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'hubid', expected: integer"}} If that turns out to be problematic, we could resolve the problem by either adding a loose parsing mode to qmp-input-visitor (teaching it to accept a string encoding of an integer in place of an actual integer), or by using QAPI alternates. But that work should be in followup patches, if at all. In qmp_netdev_add(), we still have to create a QemuOpts object so that qmp_netdev_del() will be able to remove a hotplugged network device; but the opts->head remains empty since we now manage all parsing through the QAPI object rather than QemuOpts. Signed-off-by: Eric Blake --- v8: improve commit message, call out a change in QMP behavior, inline netdev_add() v7: no change v6: don't lose qemu_opts handling --- qapi-schema.json | 15 +++------------ include/net/net.h | 2 -- hmp.c | 2 +- net/net.c | 11 +++-------- qmp-commands.hx | 2 +- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index e8a015f..3a7632b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2362,26 +2362,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/include/net/net.h b/include/net/net.h index e8d9e9e..820f880 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -210,8 +210,6 @@ void net_check_clients(void); 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/hmp.c b/hmp.c index 4819abc..3502abf 100644 --- a/hmp.c +++ b/hmp.c @@ -1672,7 +1672,7 @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict) goto out; } - netdev_add(opts, &err); + net_client_init(opts, true, &err); if (err) { qemu_opts_del(opts); } diff --git a/net/net.c b/net/net.c index c124b11..1bd7936 100644 --- a/net/net.c +++ b/net/net.c @@ -1181,12 +1181,7 @@ void hmp_host_net_remove(Monitor *mon, const QDict *qdict) qemu_del_net_client(nc); } -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; @@ -1197,12 +1192,12 @@ void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp) goto out; } - opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); + opts = qemu_opts_create(opts_list, netdev->id, 1, &local_err); if (local_err) { goto out; } - netdev_add(opts, &local_err); + net_client_init1(netdev, true, &local_err); if (local_err) { qemu_opts_del(opts); goto out; diff --git a/qmp-commands.hx b/qmp-commands.hx index 6937e83..cfc4086 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -976,7 +976,7 @@ EQMP { .name = "netdev_add", .args_type = "netdev:O", - .mhandler.cmd_new = qmp_netdev_add, + .mhandler.cmd_new = qmp_marshal_netdev_add, }, SQMP