qapi: Convert simple union SocketAddressLegacy to flat one
Simple unions predate flat unions. Having both complicates the QAPI schema language and the QAPI generator. We haven't been using simple unions in new code for a long time, because they are less flexible and somewhat awkward on the wire. To prepare for their removal, convert simple union SocketAddressLegacy to an equivalent flat one, with existing enum SocketAddressType replacing implicit enum type SocketAddressLegacyKind. Adds some boilerplate to the schema, which is a bit ugly, but a lot easier to maintain than the simple union feature. Cc: "Daniel P. Berrangé" <berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20210917143134.412106-9-armbru@redhat.com>
This commit is contained in:
parent
3218c0e91c
commit
935a867c87
@ -1520,7 +1520,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
|||||||
addr = g_new0(SocketAddressLegacy, 1);
|
addr = g_new0(SocketAddressLegacy, 1);
|
||||||
if (path) {
|
if (path) {
|
||||||
UnixSocketAddress *q_unix;
|
UnixSocketAddress *q_unix;
|
||||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
|
addr->type = SOCKET_ADDRESS_TYPE_UNIX;
|
||||||
q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
|
q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
|
||||||
q_unix->path = g_strdup(path);
|
q_unix->path = g_strdup(path);
|
||||||
#ifdef CONFIG_LINUX
|
#ifdef CONFIG_LINUX
|
||||||
@ -1530,7 +1530,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
|||||||
q_unix->abstract = abstract;
|
q_unix->abstract = abstract;
|
||||||
#endif
|
#endif
|
||||||
} else if (host) {
|
} else if (host) {
|
||||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
|
addr->type = SOCKET_ADDRESS_TYPE_INET;
|
||||||
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
||||||
*addr->u.inet.data = (InetSocketAddress) {
|
*addr->u.inet.data = (InetSocketAddress) {
|
||||||
.host = g_strdup(host),
|
.host = g_strdup(host),
|
||||||
@ -1543,7 +1543,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
|
|||||||
.ipv6 = qemu_opt_get_bool(opts, "ipv6", 0),
|
.ipv6 = qemu_opt_get_bool(opts, "ipv6", 0),
|
||||||
};
|
};
|
||||||
} else if (fd) {
|
} else if (fd) {
|
||||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD;
|
addr->type = SOCKET_ADDRESS_TYPE_FD;
|
||||||
addr->u.fd.data = g_new(String, 1);
|
addr->u.fd.data = g_new(String, 1);
|
||||||
addr->u.fd.data->str = g_strdup(fd);
|
addr->u.fd.data->str = g_strdup(fd);
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,7 +165,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
|
|||||||
qemu_chr_parse_common(opts, qapi_ChardevUdp_base(udp));
|
qemu_chr_parse_common(opts, qapi_ChardevUdp_base(udp));
|
||||||
|
|
||||||
addr = g_new0(SocketAddressLegacy, 1);
|
addr = g_new0(SocketAddressLegacy, 1);
|
||||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
|
addr->type = SOCKET_ADDRESS_TYPE_INET;
|
||||||
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
||||||
*addr->u.inet.data = (InetSocketAddress) {
|
*addr->u.inet.data = (InetSocketAddress) {
|
||||||
.host = g_strdup(host),
|
.host = g_strdup(host),
|
||||||
@ -180,7 +180,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
|
|||||||
if (has_local) {
|
if (has_local) {
|
||||||
udp->has_local = true;
|
udp->has_local = true;
|
||||||
addr = g_new0(SocketAddressLegacy, 1);
|
addr = g_new0(SocketAddressLegacy, 1);
|
||||||
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
|
addr->type = SOCKET_ADDRESS_TYPE_INET;
|
||||||
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
addr->u.inet.data = g_new(InetSocketAddress, 1);
|
||||||
*addr->u.inet.data = (InetSocketAddress) {
|
*addr->u.inet.data = (InetSocketAddress) {
|
||||||
.host = g_strdup(localaddr),
|
.host = g_strdup(localaddr),
|
||||||
|
@ -110,6 +110,38 @@
|
|||||||
'cid': 'str',
|
'cid': 'str',
|
||||||
'port': 'str' } }
|
'port': 'str' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @InetSocketAddressWrapper:
|
||||||
|
#
|
||||||
|
# Since: 1.3
|
||||||
|
##
|
||||||
|
{ 'struct': 'InetSocketAddressWrapper',
|
||||||
|
'data': { 'data': 'InetSocketAddress' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @UnixSocketAddressWrapper:
|
||||||
|
#
|
||||||
|
# Since: 1.3
|
||||||
|
##
|
||||||
|
{ 'struct': 'UnixSocketAddressWrapper',
|
||||||
|
'data': { 'data': 'UnixSocketAddress' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @VsockSocketAddressWrapper:
|
||||||
|
#
|
||||||
|
# Since: 2.8
|
||||||
|
##
|
||||||
|
{ 'struct': 'VsockSocketAddressWrapper',
|
||||||
|
'data': { 'data': 'VsockSocketAddress' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @StringWrapper:
|
||||||
|
#
|
||||||
|
# Since: 1.3
|
||||||
|
##
|
||||||
|
{ 'struct': 'StringWrapper',
|
||||||
|
'data': { 'data': 'String' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @SocketAddressLegacy:
|
# @SocketAddressLegacy:
|
||||||
#
|
#
|
||||||
@ -117,18 +149,18 @@
|
|||||||
#
|
#
|
||||||
# Note: This type is deprecated in favor of SocketAddress. The
|
# Note: This type is deprecated in favor of SocketAddress. The
|
||||||
# difference between SocketAddressLegacy and SocketAddress is that the
|
# difference between SocketAddressLegacy and SocketAddress is that the
|
||||||
# latter is a flat union rather than a simple union. Flat is nicer
|
# latter is has fewer {} on the wire.
|
||||||
# because it avoids nesting on the wire, i.e. that form has fewer {}.
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Since: 1.3
|
# Since: 1.3
|
||||||
##
|
##
|
||||||
{ 'union': 'SocketAddressLegacy',
|
{ 'union': 'SocketAddressLegacy',
|
||||||
|
'base': { 'type': 'SocketAddressType' },
|
||||||
|
'discriminator': 'type',
|
||||||
'data': {
|
'data': {
|
||||||
'inet': 'InetSocketAddress',
|
'inet': 'InetSocketAddressWrapper',
|
||||||
'unix': 'UnixSocketAddress',
|
'unix': 'UnixSocketAddressWrapper',
|
||||||
'vsock': 'VsockSocketAddress',
|
'vsock': 'VsockSocketAddressWrapper',
|
||||||
'fd': 'String' } }
|
'fd': 'StringWrapper' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @SocketAddressType:
|
# @SocketAddressType:
|
||||||
|
@ -88,7 +88,7 @@ static void char_change_test(gconstpointer opaque)
|
|||||||
.type = CHARDEV_BACKEND_KIND_SOCKET,
|
.type = CHARDEV_BACKEND_KIND_SOCKET,
|
||||||
.u.socket.data = &(ChardevSocket) {
|
.u.socket.data = &(ChardevSocket) {
|
||||||
.addr = &(SocketAddressLegacy) {
|
.addr = &(SocketAddressLegacy) {
|
||||||
.type = SOCKET_ADDRESS_LEGACY_KIND_INET,
|
.type = SOCKET_ADDRESS_TYPE_INET,
|
||||||
.u.inet.data = &addr->u.inet
|
.u.inet.data = &addr->u.inet
|
||||||
},
|
},
|
||||||
.has_server = true,
|
.has_server = true,
|
||||||
@ -102,7 +102,7 @@ static void char_change_test(gconstpointer opaque)
|
|||||||
.type = CHARDEV_BACKEND_KIND_UDP,
|
.type = CHARDEV_BACKEND_KIND_UDP,
|
||||||
.u.udp.data = &(ChardevUdp) {
|
.u.udp.data = &(ChardevUdp) {
|
||||||
.remote = &(SocketAddressLegacy) {
|
.remote = &(SocketAddressLegacy) {
|
||||||
.type = SOCKET_ADDRESS_LEGACY_KIND_UNIX,
|
.type = SOCKET_ADDRESS_TYPE_UNIX,
|
||||||
.u.q_unix.data = &(UnixSocketAddress) {
|
.u.q_unix.data = &(UnixSocketAddress) {
|
||||||
.path = (char *)""
|
.path = (char *)""
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ static void char_change_test(gconstpointer opaque)
|
|||||||
.type = CHARDEV_BACKEND_KIND_SOCKET,
|
.type = CHARDEV_BACKEND_KIND_SOCKET,
|
||||||
.u.socket.data = &(ChardevSocket) {
|
.u.socket.data = &(ChardevSocket) {
|
||||||
.addr = &(SocketAddressLegacy) {
|
.addr = &(SocketAddressLegacy) {
|
||||||
.type = SOCKET_ADDRESS_LEGACY_KIND_INET,
|
.type = SOCKET_ADDRESS_TYPE_INET,
|
||||||
.u.inet.data = &(InetSocketAddress) {
|
.u.inet.data = &(InetSocketAddress) {
|
||||||
.host = (char *)"127.0.0.1",
|
.host = (char *)"127.0.0.1",
|
||||||
.port = (char *)"0"
|
.port = (char *)"0"
|
||||||
|
@ -1455,22 +1455,22 @@ SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy)
|
|||||||
addr = g_new(SocketAddress, 1);
|
addr = g_new(SocketAddress, 1);
|
||||||
|
|
||||||
switch (addr_legacy->type) {
|
switch (addr_legacy->type) {
|
||||||
case SOCKET_ADDRESS_LEGACY_KIND_INET:
|
case SOCKET_ADDRESS_TYPE_INET:
|
||||||
addr->type = SOCKET_ADDRESS_TYPE_INET;
|
addr->type = SOCKET_ADDRESS_TYPE_INET;
|
||||||
QAPI_CLONE_MEMBERS(InetSocketAddress, &addr->u.inet,
|
QAPI_CLONE_MEMBERS(InetSocketAddress, &addr->u.inet,
|
||||||
addr_legacy->u.inet.data);
|
addr_legacy->u.inet.data);
|
||||||
break;
|
break;
|
||||||
case SOCKET_ADDRESS_LEGACY_KIND_UNIX:
|
case SOCKET_ADDRESS_TYPE_UNIX:
|
||||||
addr->type = SOCKET_ADDRESS_TYPE_UNIX;
|
addr->type = SOCKET_ADDRESS_TYPE_UNIX;
|
||||||
QAPI_CLONE_MEMBERS(UnixSocketAddress, &addr->u.q_unix,
|
QAPI_CLONE_MEMBERS(UnixSocketAddress, &addr->u.q_unix,
|
||||||
addr_legacy->u.q_unix.data);
|
addr_legacy->u.q_unix.data);
|
||||||
break;
|
break;
|
||||||
case SOCKET_ADDRESS_LEGACY_KIND_VSOCK:
|
case SOCKET_ADDRESS_TYPE_VSOCK:
|
||||||
addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
|
addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
|
||||||
QAPI_CLONE_MEMBERS(VsockSocketAddress, &addr->u.vsock,
|
QAPI_CLONE_MEMBERS(VsockSocketAddress, &addr->u.vsock,
|
||||||
addr_legacy->u.vsock.data);
|
addr_legacy->u.vsock.data);
|
||||||
break;
|
break;
|
||||||
case SOCKET_ADDRESS_LEGACY_KIND_FD:
|
case SOCKET_ADDRESS_TYPE_FD:
|
||||||
addr->type = SOCKET_ADDRESS_TYPE_FD;
|
addr->type = SOCKET_ADDRESS_TYPE_FD;
|
||||||
QAPI_CLONE_MEMBERS(String, &addr->u.fd, addr_legacy->u.fd.data);
|
QAPI_CLONE_MEMBERS(String, &addr->u.fd, addr_legacy->u.fd.data);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user