From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3t62-0001zr-7S for qemu-devel@nongnu.org; Fri, 20 May 2016 18:40:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3t5w-0004Pu-6t for qemu-devel@nongnu.org; Fri, 20 May 2016 18:40:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3t5v-0004Ow-NP for qemu-devel@nongnu.org; Fri, 20 May 2016 18:40:35 -0400 From: Eric Blake Date: Fri, 20 May 2016 16:40:11 -0600 Message-Id: <1463784024-17242-3-git-send-email-eblake@redhat.com> In-Reply-To: <1463784024-17242-1-git-send-email-eblake@redhat.com> References: <1463784024-17242-1-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v7 02/15] net: use Netdev instead of NetClientOptions in client init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= , =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= , Jason Wang , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Samuel Thibault , Jan Kiszka , "Michael S. Tsirkin" From: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n This way we no longer need NetClientOptions and can convert Netdev into a flat union. Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n Reviewed-by: Eric Blake Message-Id: <93ffdfed7054529635e6acb935150d95dc173a12.1441627176.git.Dirt= Y.iCE.hu@gmail.com> [rework net_client_init1() to pass Netdev by copying from NetdevLegacy, rather than merging the two types; rebase to qapi changes] Signed-off-by: Eric Blake --- v7: rebase to master v6: rebase --- 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 =3D { .cleanup =3D 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 =3D=3D NET_CLIENT_OPTIONS_KIND_DUMP); - dump =3D opts->u.dump.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_DUMP); + dump =3D 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 =3D=3D NET_CLIENT_OPTIONS_KIND_HUBPORT); + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_HUBPORT); assert(!peer); - hubport =3D opts->u.hubport.data; + hubport =3D 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 =3D { .cleanup =3D 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 =3D 0; s->header_mismatch =3D false; - assert(opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_L2TPV3); - l2tpv3 =3D opts->u.l2tpv3.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_L2TPV3); + l2tpv3 =3D netdev->opts->u.l2tpv3.data; if (l2tpv3->has_ipv6 && l2tpv3->ipv6) { s->ipv6 =3D l2tpv3->ipv6; diff --git a/net/net.c b/net/net.c index 7a91e8f..ec4e700 100644 --- a/net/net.c +++ b/net/net.c @@ -864,15 +864,15 @@ int qemu_find_nic_model(NICInfo *nd, const char * c= onst *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 =3D=3D NET_CLIENT_OPTIONS_KIND_NIC); - nic =3D opts->u.nic.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_NIC); + nic =3D netdev->opts->u.nic.data; idx =3D nic_get_free_idx(); if (idx =3D=3D -1 || nb_nics >=3D MAX_NICS) { @@ -933,7 +933,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) =3D { [NET_CLIENT_OPTIONS_KIND_NIC] =3D net_init_nic, @@ -965,11 +965,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 **e= rrp) { const NetClientOptions *opts; + Netdev legacy =3D {0}; + const Netdev *netdev; const char *name; NetClientState *peer =3D NULL; if (is_netdev) { - const Netdev *netdev =3D object; + netdev =3D object; opts =3D netdev->opts; name =3D netdev->id; @@ -982,7 +984,9 @@ static int net_client_init1(const void *object, int i= s_netdev, Error **errp) } } else { const NetLegacy *net =3D object; - opts =3D net->opts; + legacy.id =3D net->id; + opts =3D legacy.opts =3D net->opts; + netdev =3D &legacy; /* missing optional values have been initialized to "all bits ze= ro" */ name =3D net->has_id ? net->id : net->name; @@ -1009,7 +1013,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 6cc0db5..addeedd 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -419,10 +419,10 @@ static NetClientInfo net_netmap_info =3D { * * ... -net netmap,ifname=3D"..." */ -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 =3D opts->u.netmap.data; + const NetdevNetmapOptions *netmap_opts =3D netdev->opts->u.netmap.da= ta; struct nm_desc *nmd; NetClientState *nc; Error *err =3D NULL; diff --git a/net/slirp.c b/net/slirp.c index 31630f0..bb49629 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -817,7 +817,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 */ @@ -828,8 +828,8 @@ int net_init_slirp(const NetClientOptions *opts, cons= t char *name, const char **dnssearch; bool ipv4 =3D true, ipv6 =3D true; - assert(opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_USER); - user =3D opts->u.user.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_USER); + user =3D 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 9fa2cd8..d258352 100644 --- a/net/socket.c +++ b/net/socket.c @@ -697,15 +697,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 =3D NULL; const NetdevSocketOptions *sock; - assert(opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_SOCKET); - sock =3D opts->u.socket.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_SOCKET); + sock =3D netdev->opts->u.socket.data; if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_= mcast + sock->has_udp !=3D 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, con= st 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 =3D=3D NET_CLIENT_OPTIONS_KIND_TAP); - tap =3D opts->u.tap.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_TAP); + tap =3D 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 740e8a2..9531880 100644 --- a/net/tap.c +++ b/net/tap.c @@ -558,7 +558,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; @@ -566,8 +566,8 @@ int net_init_bridge(const NetClientOptions *opts, con= st char *name, TAPState *s; int fd, vnet_hdr; - assert(opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_BRIDGE); - bridge =3D opts->u.bridge.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_BRIDGE); + bridge =3D netdev->opts->u.bridge.data; helper =3D bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELP= ER; br =3D bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTE= RFACE; @@ -717,7 +717,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; @@ -729,8 +729,8 @@ int net_init_tap(const NetClientOptions *opts, const = char *name, const char *vhostfdname; char ifname[128]; - assert(opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_TAP); - tap =3D opts->u.tap.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_TAP); + tap =3D netdev->opts->u.tap.data; queues =3D tap->has_queues ? tap->queues : 1; vhostfdname =3D 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 =3D=3D NET_CLIENT_OPTIONS_KIND_VDE); - vde =3D opts->u.vde.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_VDE); + vde =3D 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 1b9e73a..4607c7b 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -298,15 +298,15 @@ static int net_vhost_check_net(void *opaque, QemuOp= ts *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 =3D=3D NET_CLIENT_OPTIONS_KIND_VHOST_USER); - vhost_user_opts =3D opts->u.vhost_user.data; + assert(netdev->opts->type =3D=3D NET_CLIENT_OPTIONS_KIND_VHOST_USER)= ; + vhost_user_opts =3D netdev->opts->u.vhost_user.data; chr =3D net_vhost_parse_chardev(vhost_user_opts, errp); if (!chr) { --=20 2.5.5