qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <mlureau@redhat.com>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: jasowang@redhat.com,
	"zhangchen fnst" <zhangchen.fnst@cn.fujitsu.com>,
	lizhijian@cn.fujitsu.com, qemu-devel@nongnu.org,
	xuquan8@huawei.com, "pss wulizhen" <pss.wulizhen@huawei.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers()
Date: Fri, 17 Feb 2017 02:35:01 -0500 (EST)	[thread overview]
Message-ID: <1598585072.6518123.1487316901556.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <1487299994-98348-4-git-send-email-zhang.zhanghailiang@huawei.com>

Hi

----- Original Message -----
> We can call qemu_chr_fe_set_handlers() to add/remove fd been watched
> in 'context' which can be either default main context or other explicit
> context. But the original logic is not correct, we didn't remove
> the right fd because we call g_main_context_find_source_by_id(NULL, tag)
> which always try to find the Gsource from default context.
> 
> Fix it by passing the right context to g_main_context_find_source_by_id().
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  chardev/char-fd.c     | 6 +++---
>  chardev/char-io.c     | 8 ++++----
>  chardev/char-io.h     | 2 +-
>  chardev/char-pty.c    | 2 +-
>  chardev/char-socket.c | 4 ++--
>  chardev/char-udp.c    | 6 +++---
>  chardev/char.c        | 2 +-
>  7 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/chardev/char-fd.c b/chardev/char-fd.c
> index fb51ab4..548dd4c 100644
> --- a/chardev/char-fd.c
> +++ b/chardev/char-fd.c
> @@ -58,7 +58,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition
> cond, void *opaque)
>      ret = qio_channel_read(
>          chan, (gchar *)buf, len, NULL);
>      if (ret == 0) {
> -        remove_fd_in_watch(chr);
> +        remove_fd_in_watch(chr, NULL);
>          qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
>          return FALSE;
>      }
> @@ -89,7 +89,7 @@ static void fd_chr_update_read_handler(Chardev *chr,
>  {
>      FDChardev *s = FD_CHARDEV(chr);
>  
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      if (s->ioc_in) {
>          chr->fd_in_tag = io_add_watch_poll(chr, s->ioc_in,
>                                             fd_chr_read_poll,
> @@ -103,7 +103,7 @@ static void char_fd_finalize(Object *obj)
>      Chardev *chr = CHARDEV(obj);
>      FDChardev *s = FD_CHARDEV(obj);
>  
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      if (s->ioc_in) {
>          object_unref(OBJECT(s->ioc_in));
>      }
> diff --git a/chardev/char-io.c b/chardev/char-io.c
> index 7dfc3f2..b4bb094 100644
> --- a/chardev/char-io.c
> +++ b/chardev/char-io.c
> @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
>      return tag;
>  }
>  
> -static void io_remove_watch_poll(guint tag)
> +static void io_remove_watch_poll(guint tag, GMainContext *context)
>  {
>      GSource *source;
>      IOWatchPoll *iwp;
>  
>      g_return_if_fail(tag > 0);
>  
> -    source = g_main_context_find_source_by_id(NULL, tag);
> +    source = g_main_context_find_source_by_id(context, tag);
>      g_return_if_fail(source != NULL);
>  
>      iwp = io_watch_poll_from_source(source);
> @@ -146,10 +146,10 @@ static void io_remove_watch_poll(guint tag)
>      g_source_destroy(&iwp->parent);
>  }
>  
> -void remove_fd_in_watch(Chardev *chr)
> +void remove_fd_in_watch(Chardev *chr, GMainContext *context)
>  {
>      if (chr->fd_in_tag) {
> -        io_remove_watch_poll(chr->fd_in_tag);
> +        io_remove_watch_poll(chr->fd_in_tag, context);
>          chr->fd_in_tag = 0;
>      }
>  }
> diff --git a/chardev/char-io.h b/chardev/char-io.h
> index d7ae5f1..842be56 100644
> --- a/chardev/char-io.h
> +++ b/chardev/char-io.h
> @@ -36,7 +36,7 @@ guint io_add_watch_poll(Chardev *chr,
>                          gpointer user_data,
>                          GMainContext *context);
>  
> -void remove_fd_in_watch(Chardev *chr);
> +void remove_fd_in_watch(Chardev *chr, GMainContext *context);
>  
>  int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
>  
> diff --git a/chardev/char-pty.c b/chardev/char-pty.c
> index ecf2c7a..a6337be 100644
> --- a/chardev/char-pty.c
> +++ b/chardev/char-pty.c
> @@ -199,7 +199,7 @@ static void pty_chr_state(Chardev *chr, int connected)
>              g_source_remove(s->open_tag);
>              s->open_tag = 0;
>          }
> -        remove_fd_in_watch(chr);
> +        remove_fd_in_watch(chr, NULL);
>          s->connected = 0;
>          /* (re-)connect poll interval for idle guests: once per second.
>           * We check more frequently in case the guests sends data to
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 865c527..d7e92e1 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -328,7 +328,7 @@ static void tcp_chr_free_connection(Chardev *chr)
>      }
>  
>      tcp_set_msgfds(chr, NULL, 0);
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      object_unref(OBJECT(s->sioc));
>      s->sioc = NULL;
>      object_unref(OBJECT(s->ioc));
> @@ -498,7 +498,7 @@ static void tcp_chr_update_read_handler(Chardev *chr,
>          return;
>      }
>  
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      if (s->ioc) {
>          chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
>                                             tcp_chr_read_poll,
> diff --git a/chardev/char-udp.c b/chardev/char-udp.c
> index 2c6c7dd..804bd22 100644
> --- a/chardev/char-udp.c
> +++ b/chardev/char-udp.c
> @@ -81,7 +81,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition
> cond, void *opaque)
>      ret = qio_channel_read(
>          s->ioc, (char *)s->buf, sizeof(s->buf), NULL);
>      if (ret <= 0) {
> -        remove_fd_in_watch(chr);
> +        remove_fd_in_watch(chr, NULL);
>          return FALSE;
>      }
>      s->bufcnt = ret;
> @@ -101,7 +101,7 @@ static void udp_chr_update_read_handler(Chardev *chr,
>  {
>      UdpChardev *s = UDP_CHARDEV(chr);
>  
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      if (s->ioc) {
>          chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
>                                             udp_chr_read_poll,
> @@ -115,7 +115,7 @@ static void char_udp_finalize(Object *obj)
>      Chardev *chr = CHARDEV(obj);
>      UdpChardev *s = UDP_CHARDEV(obj);
>  
> -    remove_fd_in_watch(chr);
> +    remove_fd_in_watch(chr, NULL);
>      if (s->ioc) {
>          object_unref(OBJECT(s->ioc));
>      }
> diff --git a/chardev/char.c b/chardev/char.c
> index abd525f..8af3634 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
>      cc = CHARDEV_GET_CLASS(s);
>      if (!opaque && !fd_can_read && !fd_read && !fd_event) {
>          fe_open = 0;
> -        remove_fd_in_watch(s);
> +        remove_fd_in_watch(s, context);
>      } else {
>          fe_open = 1;
>      }
> --
> 1.8.3.1
> 
> 
> 

  reply	other threads:[~2017-02-17  7:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17  2:53 [Qemu-devel] [PATCH v3 0/4] colo-compare: fix some bugs zhanghailiang
2017-02-17  2:53 ` [Qemu-devel] [PATCH v3 1/4] colo-compare: use g_timeout_source_new() to process the stale packets zhanghailiang
2017-02-17  8:50   ` Zhang Chen
2017-02-17  2:53 ` [Qemu-devel] [PATCH v3 2/4] colo-compare: kick compare thread to exit after some cleanup in finalization zhanghailiang
2017-02-17  3:50   ` Zhang Chen
2017-02-17  2:53 ` [Qemu-devel] [PATCH v3 3/4] char: remove the right fd been watched in qemu_chr_fe_set_handlers() zhanghailiang
2017-02-17  7:35   ` Marc-André Lureau [this message]
2017-02-17  2:53 ` [Qemu-devel] [PATCH v3 4/4] colo-compare: Fix removing fds been watched incorrectly in finalization zhanghailiang
2017-02-17  3:50   ` Zhang Chen
2017-02-20  3:34 ` [Qemu-devel] [PATCH v3 0/4] colo-compare: fix some bugs Jason Wang

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=1598585072.6518123.1487316901556.JavaMail.zimbra@redhat.com \
    --to=mlureau@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pss.wulizhen@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xuquan8@huawei.com \
    --cc=zhang.zhanghailiang@huawei.com \
    --cc=zhangchen.fnst@cn.fujitsu.com \
    /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).