[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 01/16] net: use Netdev instead of NetClientOption
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v6 01/16] net: use Netdev instead of NetClientOptions in client init |
Date: |
Wed, 23 Dec 2015 13:55:30 -0700 |
From: Kővágó, Zoltán <address@hidden>
This way we no longer need NetClientOptions and can convert Netdev
into a flat union.
Signed-off-by: Kővágó, Zoltán <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
[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 <address@hidden>
---
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 3764a7c..b75b49a 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -177,7 +177,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;
@@ -187,8 +187,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_DUMP);
+ dump = netdev->opts->u.dump;
assert(peer);
diff --git a/net/hub.c b/net/hub.c
index 9ae9f01..9a57905 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -280,14 +280,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;
+ hubport = netdev->opts->u.hubport;
net_hub_add_port(hubport->hubid, name);
return 0;
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index 8e68e54..c3511d7 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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3);
+ l2tpv3 = netdev->opts->u.l2tpv3;
if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
s->ipv6 = l2tpv3->ipv6;
diff --git a/net/net.c b/net/net.c
index 428636a..0902ed2 100644
--- a/net/net.c
+++ b/net/net.c
@@ -875,15 +875,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_NIC);
+ nic = netdev->opts->u.nic;
idx = nic_get_free_idx();
if (idx == -1 || nb_nics >= MAX_NICS) {
@@ -944,7 +944,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,
@@ -976,11 +976,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;
@@ -993,7 +995,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;
@@ -1020,7 +1024,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 5558368..89419c1 100644
--- a/net/netmap.c
+++ b/net/netmap.c
@@ -433,10 +433,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;
+ const NetdevNetmapOptions *netmap_opts = netdev->opts->u.netmap;
NetClientState *nc;
Error *err = NULL;
NetmapPriv me;
diff --git a/net/slirp.c b/net/slirp.c
index f505570..a3c40d9 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -736,7 +736,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 */
@@ -746,8 +746,8 @@ int net_init_slirp(const NetClientOptions *opts, const char
*name,
const NetdevUserOptions *user;
const char **dnssearch;
- assert(opts->type == NET_CLIENT_OPTIONS_KIND_USER);
- user = opts->u.user;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_USER);
+ user = netdev->opts->u.user;
vnet = user->has_net ? g_strdup(user->net) :
user->has_ip ? g_strdup_printf("%s/24", user->ip) :
diff --git a/net/socket.c b/net/socket.c
index e8605d4..0098896 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -699,15 +699,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET);
+ sock = netdev->opts->u.socket;
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 7fddb20..e442727 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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP);
+ tap = netdev->opts->u.tap;
if (!tap->has_ifname) {
error_report("tap: no interface name");
diff --git a/net/tap.c b/net/tap.c
index 85c4142..b218913 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -557,7 +557,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;
@@ -565,8 +565,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE);
+ bridge = netdev->opts->u.bridge;
helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
@@ -716,7 +716,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;
@@ -728,8 +728,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP);
+ tap = netdev->opts->u.tap;
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 4475d92..23834d7 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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VDE);
+ vde = netdev->opts->u.vde;
/* 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 b368a90..506398e 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -294,15 +294,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;
+ assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+ vhost_user_opts = netdev->opts->u.vhost_user;
chr = net_vhost_parse_chardev(vhost_user_opts, errp);
if (!chr) {
--
2.4.3
- [Qemu-devel] [PATCH v6 00/16] qapi netdev_add introspection (post-introspection cleanups subset F), Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 03/16] qapi: Forbid empty unions and useless alternates, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 04/16] qapi: Drop useless 'data' member of unions, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 01/16] net: use Netdev instead of NetClientOptions in client init,
Eric Blake <=
- [Qemu-devel] [PATCH v6 08/16] qapi: support implicit structs in OptsVisitor, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 07/16] qapi: Implement boxed types for commands/events, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 05/16] qapi: Hide tag_name data member of variants, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 02/16] qapi: Avoid use of 'data' member of qapi unions, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 06/16] qapi: Plumb in 'box' to qapi generator lower levels, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 11/16] net: Complete qapi-fication of netdev_add, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 14/16] qapi: Use anonymous base in Netdev, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 13/16] qapi: Use anonymous base in SchemaInfo, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 15/16] qapi: Use anonymous base in CpuInfo, Eric Blake, 2015/12/23
- [Qemu-devel] [PATCH v6 10/16] net: Use correct type for bool flag, Eric Blake, 2015/12/23