From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 46/46] chardev: convert the socket server to QIONetListener
Date: Wed, 20 Dec 2017 18:14:58 +0100 [thread overview]
Message-ID: <1513790098-9815-47-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1513790098-9815-1-git-send-email-pbonzini@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Instead of creating a QIOChannelSocket directly for the chardev
server socket, use a QIONetListener. This provides the ability
to listen on multiple sockets at the same time, so enables
full support for IPv4/IPv6 dual stack.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <20171218135417.28301-2-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
chardev/char-socket.c | 73 +++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 43 deletions(-)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 53eda8e..630a7f2 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -25,6 +25,7 @@
#include "chardev/char.h"
#include "io/channel-socket.h"
#include "io/channel-tls.h"
+#include "io/net-listener.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi/clone-visitor.h"
@@ -40,8 +41,7 @@ typedef struct {
Chardev parent;
QIOChannel *ioc; /* Client I/O channel */
QIOChannelSocket *sioc; /* Client master channel */
- QIOChannelSocket *listen_ioc;
- guint listen_tag;
+ QIONetListener *listener;
QCryptoTLSCreds *tls_creds;
int connected;
int max_size;
@@ -93,9 +93,9 @@ static void check_report_connect_error(Chardev *chr,
qemu_chr_socket_restart_timer(chr);
}
-static gboolean tcp_chr_accept(QIOChannel *chan,
- GIOCondition cond,
- void *opaque);
+static void tcp_chr_accept(QIONetListener *listener,
+ QIOChannelSocket *cioc,
+ void *opaque);
static int tcp_chr_read_poll(void *opaque);
static void tcp_chr_disconnect(Chardev *chr);
@@ -401,9 +401,9 @@ static void tcp_chr_disconnect(Chardev *chr)
tcp_chr_free_connection(chr);
- if (s->listen_ioc && s->listen_tag == 0) {
- s->listen_tag = qio_channel_add_watch(
- QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL);
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, tcp_chr_accept,
+ chr, NULL);
}
update_disconnected_filename(s);
if (emit_close) {
@@ -702,9 +702,8 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc)
if (s->do_nodelay) {
qio_channel_set_delay(s->ioc, false);
}
- if (s->listen_tag) {
- g_source_remove(s->listen_tag);
- s->listen_tag = 0;
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL);
}
if (s->tls_creds) {
@@ -736,24 +735,14 @@ static int tcp_chr_add_client(Chardev *chr, int fd)
return ret;
}
-static gboolean tcp_chr_accept(QIOChannel *channel,
- GIOCondition cond,
- void *opaque)
+static void tcp_chr_accept(QIONetListener *listener,
+ QIOChannelSocket *cioc,
+ void *opaque)
{
Chardev *chr = CHARDEV(opaque);
- QIOChannelSocket *sioc;
-
- sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(channel),
- NULL);
- if (!sioc) {
- return TRUE;
- }
-
- tcp_chr_new_client(chr, sioc);
- object_unref(OBJECT(sioc));
-
- return TRUE;
+ tcp_chr_set_client_ioc_name(chr, cioc);
+ tcp_chr_new_client(chr, cioc);
}
static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
@@ -767,9 +756,10 @@ static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
if (s->is_listen) {
info_report("QEMU waiting for connection on: %s",
chr->filename);
- qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
- tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
- qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
+ sioc = qio_net_listener_wait_client(s->listener);
+ tcp_chr_set_client_ioc_name(chr, sioc);
+ tcp_chr_new_client(chr, sioc);
+ object_unref(OBJECT(sioc));
} else {
sioc = qio_channel_socket_new();
tcp_chr_set_client_ioc_name(chr, sioc);
@@ -797,12 +787,9 @@ static void char_socket_finalize(Object *obj)
s->reconnect_timer = 0;
}
qapi_free_SocketAddress(s->addr);
- if (s->listen_tag) {
- g_source_remove(s->listen_tag);
- s->listen_tag = 0;
- }
- if (s->listen_ioc) {
- object_unref(OBJECT(s->listen_ioc));
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL);
+ object_unref(OBJECT(s->listener));
}
if (s->tls_creds) {
object_unref(OBJECT(s->tls_creds));
@@ -935,29 +922,29 @@ static void qmp_chardev_open_socket(Chardev *chr,
} else {
if (s->is_listen) {
char *name;
- sioc = qio_channel_socket_new();
+ s->listener = qio_net_listener_new();
name = g_strdup_printf("chardev-tcp-listener-%s", chr->label);
- qio_channel_set_name(QIO_CHANNEL(sioc), name);
+ qio_net_listener_set_name(s->listener, name);
g_free(name);
- if (qio_channel_socket_listen_sync(sioc, s->addr, errp) < 0) {
+ if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0) {
+ object_unref(OBJECT(s->listener));
+ s->listener = NULL;
goto error;
}
qapi_free_SocketAddress(s->addr);
- s->addr = socket_local_address(sioc->fd, errp);
+ s->addr = socket_local_address(s->listener->sioc[0]->fd, errp);
update_disconnected_filename(s);
- s->listen_ioc = sioc;
if (is_waitconnect &&
qemu_chr_wait_connected(chr, errp) < 0) {
return;
}
if (!s->ioc) {
- s->listen_tag = qio_channel_add_watch(
- QIO_CHANNEL(s->listen_ioc), G_IO_IN,
- tcp_chr_accept, chr, NULL);
+ qio_net_listener_set_client_func(s->listener, tcp_chr_accept,
+ chr, NULL);
}
} else if (qemu_chr_wait_connected(chr, errp) < 0) {
goto error;
--
1.8.3.1
next prev parent reply other threads:[~2017-12-20 17:16 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-20 17:14 [Qemu-devel] [PULL 00/46] First batch of misc patches for QEMU 2.12 Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 01/46] memfd: fix configure test Paolo Bonzini
2018-04-30 15:49 ` Greg Kurz
2017-12-20 17:14 ` [Qemu-devel] [PULL 02/46] qemu-thread: fix races on threads that exit very quickly Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 03/46] qemu-pr-helper: miscellaneous fixes Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 04/46] contrib: add systemd unit files Paolo Bonzini
2018-01-10 14:44 ` Daniel P. Berrange
2017-12-20 17:14 ` [Qemu-devel] [PULL 05/46] Revert "docker: Enable features explicitly in test-full" Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 06/46] scsi-block: Add share-rw option Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 07/46] MAITAINERS: List Fam Zheng as reviewer for SCSI patches Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 08/46] x86/cpu: Enable new SSE/AVX/AVX512 cpu features Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 09/46] hyperv: set partition-wide MSRs only on first vcpu Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 10/46] hyperv: ensure SINTx msrs are reset properly Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 11/46] hyperv: make SynIC version msr constant Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 12/46] cpus: make pause_all_cpus() play with SMP on single threaded TCG Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 13/46] cpu-exec: fix missed CPU kick during interrupt injection Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 14/46] target/i386: Fix compiler warnings Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 15/46] baum: Truncate braille device size to 84x1 Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 16/46] sockets: remove obsolete code that updated listen address Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 17/46] target/i386: Fix handling of VEX prefixes Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 18/46] tests/boot-serial-test: Make sure that we check the timeout regularly Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 19/46] tests/boot-serial-test: Add code to allow to specify our own kernel or bios Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 20/46] tests/boot-serial-test: Add support for the mcf5208evb board Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 21/46] tests/boot-serial-test: Add tests for microblaze boards Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 22/46] hw/moxie/moxiesim: Add support for loading a BIOS on moxiesim Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 23/46] tests/boot-serial-test: Add a test for the moxiesim machine Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 24/46] tests/boot-serial-test: Add support for the raspi2 machine Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 25/46] cpu: refactor cpu_address_space_init() Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 26/46] cpu: suffix cpu address spaces with cpu index Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 27/46] block/iscsi: dont leave allocmap in an invalid state on UNMAP failure Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 28/46] block/iscsi: only report an iSCSI Failure if we don't handle it gracefully Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 29/46] exec: Don't reuse unassigned_mem_ops for io_mem_rom Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 30/46] hw/mips/boston: Remove workaround for writes to ROM aborting Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 31/46] hw/i386/vmport: replace fprintf() by trace events or LOG_UNIMP Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 32/46] scsi: provide general-purpose functions to manage sense data Paolo Bonzini
2017-12-22 15:25 ` Roman Kagan
2017-12-20 17:14 ` [Qemu-devel] [PULL 33/46] scsi: replace hex constants with #defines Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 34/46] Remove legacy -no-kvm-pit option Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 35/46] i8259: convert DPRINTFs into trace Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 36/46] i8259: use DEBUG_IRQ_COUNT always Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 37/46] i8259: generalize statistics into common code Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 38/46] kvm-i8259: support "info pic" and "info irq" Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 39/46] i8259: move TYPE_INTERRUPT_STATS_PROVIDER upper Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 40/46] checkpatch: volatile with a comment or sig_atomic_t is okay Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 41/46] rcu: reduce more than 7MB heap memory by malloc_trim() Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 42/46] chardev: fix backend events regression with mux chardev Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 43/46] test: add some chardev mux event tests Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 44/46] blockdev: convert internal NBD server to QIONetListener Paolo Bonzini
2017-12-20 17:14 ` [Qemu-devel] [PULL 45/46] blockdev: convert qemu-nbd " Paolo Bonzini
2017-12-20 17:14 ` Paolo Bonzini [this message]
2017-12-20 18:21 ` [Qemu-devel] [PULL 00/46] First batch of misc patches for QEMU 2.12 no-reply
2017-12-20 19:20 ` Peter Maydell
2017-12-20 21:56 ` Paolo Bonzini
2017-12-21 12:49 ` [Qemu-devel] out of bounds in set_cc_op() (was: [PULL 00/46] First batch of misc patches for QEMU 2.12) Thomas Huth
2017-12-21 13:07 ` [Qemu-devel] out of bounds in set_cc_op() Laurent Vivier
2017-12-21 13:32 ` Laurent Vivier
2017-12-21 14:10 ` Paolo Bonzini
2017-12-21 14:13 ` Laurent Vivier
2017-12-21 14:14 ` Paolo Bonzini
2017-12-21 14:36 ` Laurent Vivier
2017-12-21 19:20 ` Laurent Vivier
2017-12-21 19:30 ` Paolo Bonzini
2018-01-02 16:57 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1513790098-9815-47-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).