[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH FYI 28/46] sockets: remove use of QemuOpts from sock
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH FYI 28/46] sockets: remove use of QemuOpts from socket_dgram |
Date: |
Thu, 3 Sep 2015 16:39:10 +0100 |
The socket_dgram method accepts a QAPI SocketAddress object
which it then turns into QemuOpts before calling the
inet_dgram_opts helper method. By converting the latter to
use QAPI SocketAddress directly, the QemuOpts conversion
step can be eliminated.
This removes the very last use of QemuOpts from the
sockets code, so the socket_optslist[] array is also
removed.
Signed-off-by: Daniel P. Berrange <address@hidden>
---
include/qemu/sockets.h | 1 -
util/qemu-sockets.c | 89 ++++++++++++--------------------------------------
2 files changed, 21 insertions(+), 69 deletions(-)
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 2741b97..bf7154c 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -26,7 +26,6 @@ int inet_aton(const char *cp, struct in_addr *ia);
#endif /* !_WIN32 */
-#include "qemu/option.h"
#include "qapi/error.h"
#include "qapi-types.h"
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 866ef05..c1a37d2 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -36,39 +36,6 @@
# define AI_V4MAPPED 0
#endif
-/* used temporarily until all users are converted to QemuOpts */
-static QemuOptsList socket_optslist = {
- .name = "socket",
- .head = QTAILQ_HEAD_INITIALIZER(socket_optslist.head),
- .desc = {
- {
- .name = "path",
- .type = QEMU_OPT_STRING,
- },{
- .name = "host",
- .type = QEMU_OPT_STRING,
- },{
- .name = "port",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localaddr",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localport",
- .type = QEMU_OPT_STRING,
- },{
- .name = "to",
- .type = QEMU_OPT_NUMBER,
- },{
- .name = "ipv4",
- .type = QEMU_OPT_BOOL,
- },{
- .name = "ipv6",
- .type = QEMU_OPT_BOOL,
- },
- { /* end if list */ }
- },
-};
static int inet_getport(struct addrinfo *e)
{
@@ -440,7 +407,9 @@ static int inet_connect_saddr(InetSocketAddress *saddr,
Error **errp,
return sock;
}
-static int inet_dgram_opts(QemuOpts *opts, Error **errp)
+static int inet_dgram_saddr(InetSocketAddress *sraddr,
+ InetSocketAddress *sladdr,
+ Error **errp)
{
struct addrinfo ai, *peer = NULL, *local = NULL;
const char *addr;
@@ -453,8 +422,8 @@ static int inet_dgram_opts(QemuOpts *opts, Error **errp)
ai.ai_family = PF_UNSPEC;
ai.ai_socktype = SOCK_DGRAM;
- addr = qemu_opt_get(opts, "host");
- port = qemu_opt_get(opts, "port");
+ addr = sraddr->host;
+ port = sraddr->port;
if (addr == NULL || strlen(addr) == 0) {
addr = "localhost";
}
@@ -463,10 +432,12 @@ static int inet_dgram_opts(QemuOpts *opts, Error **errp)
return -1;
}
- if (qemu_opt_get_bool(opts, "ipv4", 0))
+ if (sraddr->has_ipv4 && sraddr->ipv4) {
ai.ai_family = PF_INET;
- if (qemu_opt_get_bool(opts, "ipv6", 0))
+ }
+ if (sraddr->has_ipv6 && sraddr->ipv6) {
ai.ai_family = PF_INET6;
+ }
if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) {
error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
@@ -480,13 +451,19 @@ static int inet_dgram_opts(QemuOpts *opts, Error **errp)
ai.ai_family = peer->ai_family;
ai.ai_socktype = SOCK_DGRAM;
- addr = qemu_opt_get(opts, "localaddr");
- port = qemu_opt_get(opts, "localport");
- if (addr == NULL || strlen(addr) == 0) {
+ if (sladdr) {
+ addr = sladdr->host;
+ port = sladdr->port;
+ if (addr == NULL || strlen(addr) == 0) {
+ addr = NULL;
+ }
+ if (!port || strlen(port) == 0) {
+ port = "0";
+ }
+ } else {
addr = NULL;
- }
- if (!port || strlen(port) == 0)
port = "0";
+ }
if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
@@ -595,22 +572,6 @@ fail:
return NULL;
}
-static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress *addr)
-{
- bool ipv4 = addr->ipv4 || !addr->has_ipv4;
- bool ipv6 = addr->ipv6 || !addr->has_ipv6;
-
- if (!ipv4 || !ipv6) {
- qemu_opt_set_bool(opts, "ipv4", ipv4, &error_abort);
- qemu_opt_set_bool(opts, "ipv6", ipv6, &error_abort);
- }
- if (addr->has_to) {
- qemu_opt_set_number(opts, "to", addr->to, &error_abort);
- }
- qemu_opt_set(opts, "host", addr->host, &error_abort);
- qemu_opt_set(opts, "port", addr->port, &error_abort);
-}
-
int inet_listen(const char *str, char *ostr, int olen,
int socktype, int port_offset, Error **errp)
{
@@ -987,25 +948,17 @@ int socket_listen(SocketAddress *addr, Error **errp)
int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)
{
- QemuOpts *opts;
int fd;
- opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
switch (remote->kind) {
case SOCKET_ADDRESS_KIND_INET:
- inet_addr_to_opts(opts, remote->inet);
- if (local) {
- qemu_opt_set(opts, "localaddr", local->inet->host, &error_abort);
- qemu_opt_set(opts, "localport", local->inet->port, &error_abort);
- }
- fd = inet_dgram_opts(opts, errp);
+ fd = inet_dgram_saddr(remote->inet, local ? local->inet : NULL, errp);
break;
default:
error_setg(errp, "socket type unsupported for datagram");
fd = -1;
}
- qemu_opts_del(opts);
return fd;
}
--
2.4.3
- Re: [Qemu-devel] [PATCH FYI 13/46] io: add QIOChannelWebsock class, (continued)
- [Qemu-devel] [PATCH FYI 17/46] ui: convert VNC server to use QIOChannelTLS, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 16/46] ui: convert VNC server to use QIOChannelSocket, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 19/46] char: remove fixed length filename allocation, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 18/46] ui: convert VNC server to use QIOChannelWebsock, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 24/46] qemu-nbd: convert to use the QAPI SocketAddress object, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 22/46] char: introduce support for TLS encrypted TCP chardev backend, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 20/46] char: convert from GIOChannel to QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 25/46] sockets: remove use of QemuOpts from header file, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 26/46] sockets: remove use of QemuOpts from socket_listen, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 28/46] sockets: remove use of QemuOpts from socket_dgram,
Daniel P. Berrange <=
- [Qemu-devel] [PATCH FYI 27/46] sockets: remove use of QemuOpts from socket_connect, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 29/46] migration: remove use of qemu_bufopen from vmstate tests, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 31/46] migration: move definition of struct QEMUFile back into qemu-file.c, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 32/46] migration: split migration hooks out of QEMUFileOps, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 30/46] migration: remove memory buffer based QEMUFile backend, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 33/46] migration: ensure qemu_fflush() always writes full data amount, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 34/46] migration: introduce qemu_fset_blocking function on QEMUFile, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 36/46] migration: introduce a new QEMUFile impl based on QIOChannel, Daniel P. Berrange, 2015/09/03