qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Cc: qemu devel <qemu-devel@nongnu.org>,
	Jason Wang <jasowang@redhat.com>,
	Li Zhijian <lizhijian@cn.fujitsu.com>,
	Wen Congyang <wency@cn.fujitsu.com>,
	zhanghailiang <zhang.zhanghailiang@huawei.com>,
	"eddie . dong" <eddie.dong@intel.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC PATCH V8 5/7] qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
Date: Thu, 21 Jul 2016 10:00:06 +0100	[thread overview]
Message-ID: <20160721090006.GB13528@redhat.com> (raw)
In-Reply-To: <1469089573-20923-6-git-send-email-zhangchen.fnst@cn.fujitsu.com>

On Thu, Jul 21, 2016 at 04:26:11PM +0800, Zhang Chen wrote:
> Add qemu_chr_add_handlers_full() API, we can use
> this API pass in a GMainContext,make handler run
> in the context rather than main_loop.
> This comments from Daniel P . Berrange.
> 
> Cc: Daniel P . Berrange <berrange@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> 
> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> ---
>  include/sysemu/char.h |  10 ++++
>  qemu-char.c           | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 155 insertions(+)
> 
> diff --git a/include/sysemu/char.h b/include/sysemu/char.h
> index 307fd8f..3ab897e 100644
> --- a/include/sysemu/char.h
> +++ b/include/sysemu/char.h
> @@ -66,6 +66,8 @@ struct CharDriverState {
>                           const uint8_t *buf, int len);
>      GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond);
>      void (*chr_update_read_handler)(struct CharDriverState *s);

I'd expect this to be deleted, and all existing impls given a
new GMainContext * argument.

> +    void (*chr_update_read_handler_full)(struct CharDriverState *s,
> +                                         GMainContext *context);
>      int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
>      int (*get_msgfds)(struct CharDriverState *s, int* fds, int num);
>      int (*set_msgfds)(struct CharDriverState *s, int *fds, int num);
> @@ -388,6 +390,14 @@ void qemu_chr_add_handlers(CharDriverState *s,
>                             IOEventHandler *fd_event,
>                             void *opaque);
>  
> +/* This API can make handler run in the context what you pass to. */
> +void qemu_chr_add_handlers_full(CharDriverState *s,
> +                                IOCanReadHandler *fd_can_read,
> +                                IOReadHandler *fd_read,
> +                                IOEventHandler *fd_event,
> +                                void *opaque,
> +                                GMainContext *context);
> +
>  void qemu_chr_be_generic_open(CharDriverState *s);
>  void qemu_chr_accept_input(CharDriverState *s);
>  int qemu_chr_add_client(CharDriverState *s, int fd);
> diff --git a/qemu-char.c b/qemu-char.c
> index b597ee1..607b3b8 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -480,6 +480,40 @@ void qemu_chr_add_handlers(CharDriverState *s,
>      }
>  }
>  
> +void qemu_chr_add_handlers_full(CharDriverState *s,
> +                                IOCanReadHandler *fd_can_read,
> +                                IOReadHandler *fd_read,
> +                                IOEventHandler *fd_event,
> +                                void *opaque,
> +                                GMainContext *context)
> +{
> +    int fe_open;
> +
> +    if (!opaque && !fd_can_read && !fd_read && !fd_event) {
> +        fe_open = 0;
> +        remove_fd_in_watch(s);
> +    } else {
> +        fe_open = 1;
> +    }
> +    s->chr_can_read = fd_can_read;
> +    s->chr_read = fd_read;
> +    s->chr_event = fd_event;
> +    s->handler_opaque = opaque;
> +    if (fe_open && s->chr_update_read_handler) {

You should be checking s->chr_update_read_handler_full

> +        s->chr_update_read_handler_full(s, context);
> +    }
> +
> +    if (!s->explicit_fe_open) {
> +        qemu_chr_fe_set_open(s, fe_open);
> +    }
> +
> +    /* We're connecting to an already opened device, so let's make sure we
> +       also get the open event */
> +    if (fe_open && s->be_open) {
> +        qemu_chr_be_generic_open(s);
> +    }
> +}

I would expect the entire of the qemu_chr_add_handlers() method body
to be deleted and have it simply call qemu_chr_add_handlers_full(),
passing in a NULL GMainContext. That way we avoid code duplication.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2016-07-21  9:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21  8:26 [Qemu-devel] [RFC PATCH V8 0/7] Introduce COLO-compare Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 1/7] colo-compare: introduce colo compare initialization Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 2/7] colo-base: add colo-base to define and handle packet Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 3/7] Jhash: add linux kernel jhashtable in qemu Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 4/7] colo-compare: track connection and enqueue packet Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 5/7] qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext Zhang Chen
2016-07-21  9:00   ` Daniel P. Berrange [this message]
2016-07-21  9:29     ` Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 6/7] colo-compare: introduce packet comparison thread Zhang Chen
2016-07-21  8:26 ` [Qemu-devel] [RFC PATCH V8 7/7] colo-compare: add TCP, UDP, ICMP packet comparison Zhang Chen

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=20160721090006.GB13528@redhat.com \
    --to=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eddie.dong@intel.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wency@cn.fujitsu.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).