diff options
author | Peter Xu <peterx@redhat.com> | 2018-03-06 13:33:14 +0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-03-12 16:12:46 +0100 |
commit | 3da9de5ce22125c917f722f13f91a0e3b096a251 (patch) | |
tree | f5acd9ad1dc1b1ebbd9d2d16428ecb8a3dbff8a1 | |
parent | c863fdec6aff6b5a4ca8fff1537b80d9f8b97726 (diff) | |
download | qemu-3da9de5ce22125c917f722f13f91a0e3b096a251.zip qemu-3da9de5ce22125c917f722f13f91a0e3b096a251.tar.gz qemu-3da9de5ce22125c917f722f13f91a0e3b096a251.tar.bz2 |
chardev: update net listener gcontext
TCP chardevs can be using QIO network listeners working in the
background when in listening mode. However the network listeners are
always running in main context. This can race with chardevs that are
running in non-main contexts.
To solve this, we need to re-setup the net listeners in
tcp_chr_update_read_handler() with the newly cached gcontext.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180306053320.15401-4-peterx@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | chardev/char-socket.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 541fcf4..2475e1d 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -423,8 +423,8 @@ static void tcp_chr_disconnect(Chardev *chr) tcp_chr_free_connection(chr); if (s->listener) { - qio_net_listener_set_client_func(s->listener, tcp_chr_accept, - chr, NULL); + qio_net_listener_set_client_func_full(s->listener, tcp_chr_accept, + chr, NULL, chr->gcontext); } update_disconnected_filename(s); if (emit_close) { @@ -560,6 +560,16 @@ static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); + if (s->listener) { + /* + * It's possible that chardev context is changed in + * qemu_chr_be_update_read_handlers(). Reset it for QIO net + * listener if there is. + */ + qio_net_listener_set_client_func_full(s->listener, tcp_chr_accept, + chr, NULL, chr->gcontext); + } + if (!s->connected) { return; } @@ -744,7 +754,8 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc) qio_channel_set_delay(s->ioc, false); } if (s->listener) { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + qio_net_listener_set_client_func_full(s->listener, NULL, NULL, + NULL, chr->gcontext); } if (s->tls_creds) { @@ -825,7 +836,8 @@ static void char_socket_finalize(Object *obj) tcp_chr_reconn_timer_cancel(s); qapi_free_SocketAddress(s->addr); if (s->listener) { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + qio_net_listener_set_client_func_full(s->listener, NULL, NULL, + NULL, chr->gcontext); object_unref(OBJECT(s->listener)); } if (s->tls_creds) { @@ -981,8 +993,10 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } if (!s->ioc) { - qio_net_listener_set_client_func(s->listener, tcp_chr_accept, - chr, NULL); + qio_net_listener_set_client_func_full(s->listener, + tcp_chr_accept, + chr, NULL, + chr->gcontext); } } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; |