diff options
author | Eric Blake <eblake@redhat.com> | 2016-03-17 16:48:37 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-03-18 10:29:26 +0100 |
commit | 32bafa8fdd098d52fbf1102d5a5e48d29398c0aa (patch) | |
tree | ca10fdb98f8c5c7cbecee273e64691c2c8f17728 /net | |
parent | 861877a0dd0a8e1bdbcc9743530f4dc9745a736a (diff) | |
download | qemu-32bafa8fdd098d52fbf1102d5a5e48d29398c0aa.tar.gz qemu-32bafa8fdd098d52fbf1102d5a5e48d29398c0aa.tar.bz2 qemu-32bafa8fdd098d52fbf1102d5a5e48d29398c0aa.zip |
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/dump.c | 2 | ||||
-rw-r--r-- | net/hub.c | 2 | ||||
-rw-r--r-- | net/l2tpv3.c | 2 | ||||
-rw-r--r-- | net/net.c | 4 | ||||
-rw-r--r-- | net/netmap.c | 2 | ||||
-rw-r--r-- | net/slirp.c | 2 | ||||
-rw-r--r-- | net/socket.c | 2 | ||||
-rw-r--r-- | net/tap-win32.c | 2 | ||||
-rw-r--r-- | net/tap.c | 4 | ||||
-rw-r--r-- | net/vde.c | 2 | ||||
-rw-r--r-- | net/vhost-user.c | 2 |
11 files changed, 13 insertions, 13 deletions
diff --git a/net/dump.c b/net/dump.c index 61dec9d61d..94ac32a39f 100644 --- a/net/dump.c +++ b/net/dump.c @@ -189,7 +189,7 @@ int net_init_dump(const NetClientOptions *opts, const char *name, DumpNetClient *dnc; assert(opts->type == NET_CLIENT_OPTIONS_KIND_DUMP); - dump = opts->u.dump; + dump = opts->u.dump.data; assert(peer); @@ -288,7 +288,7 @@ int net_init_hubport(const NetClientOptions *opts, const char *name, assert(opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT); assert(!peer); - hubport = opts->u.hubport; + hubport = opts->u.hubport.data; net_hub_add_port(hubport->hubid, name); return 0; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 824161c5b8..5c668f7376 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -546,7 +546,7 @@ int net_init_l2tpv3(const NetClientOptions *opts, s->header_mismatch = false; assert(opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3); - l2tpv3 = opts->u.l2tpv3; + l2tpv3 = opts->u.l2tpv3.data; if (l2tpv3->has_ipv6 && l2tpv3->ipv6) { s->ipv6 = l2tpv3->ipv6; @@ -893,7 +893,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name, const NetLegacyNicOptions *nic; assert(opts->type == NET_CLIENT_OPTIONS_KIND_NIC); - nic = opts->u.nic; + nic = opts->u.nic.data; idx = nic_get_free_idx(); if (idx == -1 || nb_nics >= MAX_NICS) { @@ -1025,7 +1025,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) /* Do not add to a vlan if it's a nic with a netdev= parameter. */ if (opts->type != NET_CLIENT_OPTIONS_KIND_NIC || - !opts->u.nic->has_netdev) { + !opts->u.nic.data->has_netdev) { peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL); } } diff --git a/net/netmap.c b/net/netmap.c index 1b427287a7..6fa2c418a5 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -420,7 +420,7 @@ static NetClientInfo net_netmap_info = { int net_init_netmap(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { - const NetdevNetmapOptions *netmap_opts = opts->u.netmap; + const NetdevNetmapOptions *netmap_opts = opts->u.netmap.data; struct nm_desc *nmd; NetClientState *nc; Error *err = NULL; diff --git a/net/slirp.c b/net/slirp.c index 9954160de3..95239bceb0 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -814,7 +814,7 @@ int net_init_slirp(const NetClientOptions *opts, const char *name, const char **dnssearch; assert(opts->type == NET_CLIENT_OPTIONS_KIND_USER); - user = opts->u.user; + user = opts->u.user.data; 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 73dc49a3a4..9826efb46f 100644 --- a/net/socket.c +++ b/net/socket.c @@ -704,7 +704,7 @@ int net_init_socket(const NetClientOptions *opts, const char *name, const NetdevSocketOptions *sock; assert(opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET); - sock = opts->u.socket; + sock = 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 38bbac0cd9..f1e142ace6 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -795,7 +795,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, const NetdevTapOptions *tap; assert(opts->type == NET_CLIENT_OPTIONS_KIND_TAP); - tap = opts->u.tap; + tap = opts->u.tap.data; if (!tap->has_ifname) { error_report("tap: no interface name"); @@ -565,7 +565,7 @@ int net_init_bridge(const NetClientOptions *opts, const char *name, int fd, vnet_hdr; assert(opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE); - bridge = opts->u.bridge; + bridge = opts->u.bridge.data; helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER; br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE; @@ -728,7 +728,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, char ifname[128]; assert(opts->type == NET_CLIENT_OPTIONS_KIND_TAP); - tap = opts->u.tap; + tap = opts->u.tap.data; queues = tap->has_queues ? tap->queues : 1; vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL; @@ -116,7 +116,7 @@ int net_init_vde(const NetClientOptions *opts, const char *name, const NetdevVdeOptions *vde; assert(opts->type == NET_CLIENT_OPTIONS_KIND_VDE); - vde = opts->u.vde; + vde = 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 58b8dae766..1b9e73a2dc 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -306,7 +306,7 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name, CharDriverState *chr; assert(opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER); - vhost_user_opts = opts->u.vhost_user; + vhost_user_opts = opts->u.vhost_user.data; chr = net_vhost_parse_chardev(vhost_user_opts, errp); if (!chr) { |