From patchwork Tue Jul 19 11:39:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9236867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C1CB6602F0 for ; Tue, 19 Jul 2016 11:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1AF62026B for ; Tue, 19 Jul 2016 11:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6891205AF; Tue, 19 Jul 2016 11:53:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EADF42026B for ; Tue, 19 Jul 2016 11:53:18 +0000 (UTC) Received: from localhost ([::1]:54889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTaQ-0008It-2x for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 07:53:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNL-0001ZJ-HK for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPTNG-0001uE-6D for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNF-0001tn-TZ for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:42 -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 1A17C627EE; Tue, 19 Jul 2016 11:39:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JBdcjx000742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2016 07:39:39 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0705311AD28F; Tue, 19 Jul 2016 13:39:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 13:39:25 +0200 Message-Id: <1468928377-20384-4-git-send-email-armbru@redhat.com> In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com> References: <1468928377-20384-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 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.38]); Tue, 19 Jul 2016 11:39:41 +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] [PULL for-2.7 03/15] net: use Netdev instead of NetClientOptions in client init 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: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Kővágó, Zoltán This way we no longer need NetClientOptions and can convert Netdev into a flat union. Signed-off-by: Kővágó, Zoltán Reviewed-by: Eric Blake Message-Id: <93ffdfed7054529635e6acb935150d95dc173a12.1441627176.git.DirtY.iCE.hu@gmail.com> [rework net_client_init1() to pass Netdev by copying from NetdevLegacy, rather than merging the two types - which means that we still need NetClientOptions after all. Rebase to qapi changes. The bulk of the patch is mechanical, replacing 'opts' by 'netdev->opts', while net_client_init1() takes care of converting between legacy and modern types.] Signed-off-by: Eric Blake Message-Id: <1468468228-27827-2-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- net/clients.h | 20 ++++++++++---------- net/dump.c | 6 +++--- net/hub.c | 6 +++--- net/l2tpv3.c | 6 +++--- net/net.c | 18 +++++++++++------- net/netmap.c | 4 ++-- net/slirp.c | 6 +++--- net/socket.c | 6 +++--- net/tap-win32.c | 6 +++--- net/tap.c | 12 ++++++------ net/vde.c | 6 +++--- net/vhost-user.c | 6 +++--- 12 files changed, 53 insertions(+), 49 deletions(-) diff --git a/net/clients.h b/net/clients.h index d47530e..5cae479 100644 --- a/net/clients.h +++ b/net/clients.h @@ -27,39 +27,39 @@ #include "net/net.h" #include "qapi-types.h" -int net_init_dump(const NetClientOptions *opts, const char *name, +int net_init_dump(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #ifdef CONFIG_SLIRP -int net_init_slirp(const NetClientOptions *opts, const char *name, +int net_init_slirp(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #endif -int net_init_hubport(const NetClientOptions *opts, const char *name, +int net_init_hubport(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); -int net_init_socket(const NetClientOptions *opts, const char *name, +int net_init_socket(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); -int net_init_tap(const NetClientOptions *opts, const char *name, +int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); -int net_init_bridge(const NetClientOptions *opts, const char *name, +int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); -int net_init_l2tpv3(const NetClientOptions *opts, const char *name, +int net_init_l2tpv3(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #ifdef CONFIG_VDE -int net_init_vde(const NetClientOptions *opts, const char *name, +int net_init_vde(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #endif #ifdef CONFIG_NETMAP -int net_init_netmap(const NetClientOptions *opts, const char *name, +int net_init_netmap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #endif -int net_init_vhost_user(const NetClientOptions *opts, const char *name, +int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/dump.c b/net/dump.c index 41f7673..f8a500f 100644 --- a/net/dump.c +++ b/net/dump.c @@ -179,7 +179,7 @@ static NetClientInfo net_dump_info = { .cleanup = dumpclient_cleanup, }; -int net_init_dump(const NetClientOptions *opts, const char *name, +int net_init_dump(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { int len, rc; @@ -189,8 +189,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *nc; DumpNetClient *dnc; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_DUMP); - dump = opts->u.dump.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_DUMP); + dump = netdev->opts->u.dump.data; assert(peer); diff --git a/net/hub.c b/net/hub.c index 6d90c6e..ec4626f 100644 --- a/net/hub.c +++ b/net/hub.c @@ -281,14 +281,14 @@ int net_hub_id_for_client(NetClientState *nc, int *id) return 0; } -int net_init_hubport(const NetClientOptions *opts, const char *name, +int net_init_hubport(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevHubPortOptions *hubport; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT); assert(!peer); - hubport = opts->u.hubport.data; + hubport = netdev->opts->u.hubport.data; net_hub_add_port(hubport->hubid, name); return 0; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 5c668f7..df02f5b 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -524,7 +524,7 @@ static NetClientInfo net_l2tpv3_info = { .cleanup = net_l2tpv3_cleanup, }; -int net_init_l2tpv3(const NetClientOptions *opts, +int net_init_l2tpv3(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -545,8 +545,8 @@ int net_init_l2tpv3(const NetClientOptions *opts, s->queue_tail = 0; s->header_mismatch = false; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3); - l2tpv3 = opts->u.l2tpv3.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3); + l2tpv3 = netdev->opts->u.l2tpv3.data; if (l2tpv3->has_ipv6 && l2tpv3->ipv6) { s->ipv6 = l2tpv3->ipv6; diff --git a/net/net.c b/net/net.c index 019aaad..d80fd82 100644 --- a/net/net.c +++ b/net/net.c @@ -862,15 +862,15 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, return -1; } -static int net_init_nic(const NetClientOptions *opts, const char *name, +static int net_init_nic(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { int idx; NICInfo *nd; const NetLegacyNicOptions *nic; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_NIC); - nic = opts->u.nic.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_NIC); + nic = netdev->opts->u.nic.data; idx = nic_get_free_idx(); if (idx == -1 || nb_nics >= MAX_NICS) { @@ -931,7 +931,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name, static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])( - const NetClientOptions *opts, + const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) = { [NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic, @@ -963,11 +963,13 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])( static int net_client_init1(const void *object, int is_netdev, Error **errp) { const NetClientOptions *opts; + Netdev legacy = {0}; + const Netdev *netdev; const char *name; NetClientState *peer = NULL; if (is_netdev) { - const Netdev *netdev = object; + netdev = object; opts = netdev->opts; name = netdev->id; @@ -980,7 +982,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } } else { const NetLegacy *net = object; - opts = net->opts; + legacy.id = net->id; + opts = legacy.opts = net->opts; + netdev = &legacy; /* missing optional values have been initialized to "all bits zero" */ name = net->has_id ? net->id : net->name; @@ -1007,7 +1011,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } } - if (net_client_init_fun[opts->type](opts, name, peer, errp) < 0) { + if (net_client_init_fun[opts->type](netdev, name, peer, errp) < 0) { /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { error_setg(errp, QERR_DEVICE_INIT_FAILED, diff --git a/net/netmap.c b/net/netmap.c index 64967b9..beb8d28 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -418,10 +418,10 @@ static NetClientInfo net_netmap_info = { * * ... -net netmap,ifname="..." */ -int net_init_netmap(const NetClientOptions *opts, +int net_init_netmap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { - const NetdevNetmapOptions *netmap_opts = opts->u.netmap.data; + const NetdevNetmapOptions *netmap_opts = netdev->opts->u.netmap.data; struct nm_desc *nmd; NetClientState *nc; Error *err = NULL; diff --git a/net/slirp.c b/net/slirp.c index 28207b6..ca34bad 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -828,7 +828,7 @@ static const char **slirp_dnssearch(const StringList *dnsname) return ret; } -int net_init_slirp(const NetClientOptions *opts, const char *name, +int net_init_slirp(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ @@ -839,8 +839,8 @@ int net_init_slirp(const NetClientOptions *opts, const char *name, const char **dnssearch; bool ipv4 = true, ipv6 = true; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_USER); - user = opts->u.user.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_USER); + user = netdev->opts->u.user.data; if ((user->has_ipv6 && user->ipv6 && !user->has_ipv4) || (user->has_ipv4 && !user->ipv4)) { diff --git a/net/socket.c b/net/socket.c index ae6f921..6e5c902 100644 --- a/net/socket.c +++ b/net/socket.c @@ -663,15 +663,15 @@ static int net_socket_udp_init(NetClientState *peer, return 0; } -int net_init_socket(const NetClientOptions *opts, const char *name, +int net_init_socket(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ Error *err = NULL; const NetdevSocketOptions *sock; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET); - sock = opts->u.socket.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET); + sock = netdev->opts->u.socket.data; if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast + sock->has_udp != 1) { diff --git a/net/tap-win32.c b/net/tap-win32.c index f1e142a..0f23b19 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -788,14 +788,14 @@ static int tap_win32_init(NetClientState *peer, const char *model, return 0; } -int net_init_tap(const NetClientOptions *opts, const char *name, +int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ const NetdevTapOptions *tap; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_TAP); - tap = opts->u.tap.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP); + tap = netdev->opts->u.tap.data; if (!tap->has_ifname) { error_report("tap: no interface name"); diff --git a/net/tap.c b/net/tap.c index e9c32f3..ceb8c43 100644 --- a/net/tap.c +++ b/net/tap.c @@ -571,7 +571,7 @@ static int net_bridge_run_helper(const char *helper, const char *bridge, } } -int net_init_bridge(const NetClientOptions *opts, const char *name, +int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevBridgeOptions *bridge; @@ -579,8 +579,8 @@ int net_init_bridge(const NetClientOptions *opts, const char *name, TAPState *s; int fd, vnet_hdr; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE); - bridge = opts->u.bridge.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE); + bridge = netdev->opts->u.bridge.data; helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER; br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE; @@ -735,7 +735,7 @@ static int get_fds(char *str, char *fds[], int max) return i; } -int net_init_tap(const NetClientOptions *opts, const char *name, +int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap; @@ -747,8 +747,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name, const char *vhostfdname; char ifname[128]; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_TAP); - tap = opts->u.tap.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP); + tap = netdev->opts->u.tap.data; queues = tap->has_queues ? tap->queues : 1; vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL; diff --git a/net/vde.c b/net/vde.c index 9427eaa..53cdbbf 100644 --- a/net/vde.c +++ b/net/vde.c @@ -109,14 +109,14 @@ static int net_vde_init(NetClientState *peer, const char *model, return 0; } -int net_init_vde(const NetClientOptions *opts, const char *name, +int net_init_vde(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ const NetdevVdeOptions *vde; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_VDE); - vde = opts->u.vde.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VDE); + vde = netdev->opts->u.vde.data; /* missing optional values have been initialized to "all bits zero" */ if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group, diff --git a/net/vhost-user.c b/net/vhost-user.c index a88dfe0..dfdcca2 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -334,15 +334,15 @@ static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) return 0; } -int net_init_vhost_user(const NetClientOptions *opts, const char *name, +int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { int queues; const NetdevVhostUserOptions *vhost_user_opts; CharDriverState *chr; - assert(opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER); - vhost_user_opts = opts->u.vhost_user.data; + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER); + vhost_user_opts = netdev->opts->u.vhost_user.data; chr = net_vhost_parse_chardev(vhost_user_opts, errp); if (!chr) {