qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/9] chardev: update net listener gcontext


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH 3/9] chardev: update net listener gcontext
Date: Mon, 5 Mar 2018 12:48:01 +0100

On Mon, Mar 5, 2018 at 7:50 AM, Peter Xu <address@hidden> wrote:
> 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.
>
> Signed-off-by: Peter Xu <address@hidden>
> ---
>  chardev/char-socket.c | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)
>


Reviewed-by: Marc-André Lureau <address@hidden>


> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 205ee377a4..5aa01e15ff 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -422,8 +422,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) {
> @@ -559,6 +559,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;
>      }
> @@ -743,7 +753,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) {
> @@ -824,7 +835,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) {
> @@ -980,8 +992,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;
> --
> 2.14.3
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]