From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org,
Zhang Chen <zhangchen.fnst@cn.fujitsu.com>,
Li Zhijian <lizhijian@cn.fujitsu.com>,
Wen Congyang <wency@cn.fujitsu.com>,
Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PULL V2 03/27] qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
Date: Tue, 27 Sep 2016 18:12:43 +0800 [thread overview]
Message-ID: <1474971187-15627-4-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1474971187-15627-1-git-send-email-jasowang@redhat.com>
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
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.
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>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
include/sysemu/char.h | 11 +++++++-
qemu-char.c | 77 +++++++++++++++++++++++++++++++++++----------------
2 files changed, 63 insertions(+), 25 deletions(-)
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index ee7e554..0d0465a 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -65,7 +65,8 @@ struct CharDriverState {
int (*chr_sync_read)(struct CharDriverState *s,
const uint8_t *buf, int len);
GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond);
- void (*chr_update_read_handler)(struct CharDriverState *s);
+ void (*chr_update_read_handler)(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);
@@ -422,6 +423,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 8826419..fb456ce 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -449,11 +449,12 @@ void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
static void remove_fd_in_watch(CharDriverState *chr);
-void qemu_chr_add_handlers(CharDriverState *s,
- IOCanReadHandler *fd_can_read,
- IOReadHandler *fd_read,
- IOEventHandler *fd_event,
- void *opaque)
+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;
@@ -467,8 +468,9 @@ void qemu_chr_add_handlers(CharDriverState *s,
s->chr_read = fd_read;
s->chr_event = fd_event;
s->handler_opaque = opaque;
- if (fe_open && s->chr_update_read_handler)
- s->chr_update_read_handler(s);
+ if (fe_open && s->chr_update_read_handler) {
+ s->chr_update_read_handler(s, context);
+ }
if (!s->explicit_fe_open) {
qemu_chr_fe_set_open(s, fe_open);
@@ -481,6 +483,16 @@ void qemu_chr_add_handlers(CharDriverState *s,
}
}
+void qemu_chr_add_handlers(CharDriverState *s,
+ IOCanReadHandler *fd_can_read,
+ IOReadHandler *fd_read,
+ IOEventHandler *fd_event,
+ void *opaque)
+{
+ qemu_chr_add_handlers_full(s, fd_can_read, fd_read,
+ fd_event, opaque, NULL);
+}
+
static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
return len;
@@ -722,7 +734,8 @@ static void mux_chr_event(void *opaque, int event)
mux_chr_send_event(d, i, event);
}
-static void mux_chr_update_read_handler(CharDriverState *chr)
+static void mux_chr_update_read_handler(CharDriverState *chr,
+ GMainContext *context)
{
MuxDriver *d = chr->opaque;
@@ -736,8 +749,10 @@ static void mux_chr_update_read_handler(CharDriverState *chr)
d->chr_event[d->mux_cnt] = chr->chr_event;
/* Fix up the real driver with mux routines */
if (d->mux_cnt == 0) {
- qemu_chr_add_handlers(d->drv, mux_chr_can_read, mux_chr_read,
- mux_chr_event, chr);
+ qemu_chr_add_handlers_full(d->drv, mux_chr_can_read,
+ mux_chr_read,
+ mux_chr_event,
+ chr, context);
}
if (d->focus != -1) {
mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT);
@@ -853,6 +868,7 @@ typedef struct IOWatchPoll
IOCanReadHandler *fd_can_read;
GSourceFunc fd_read;
void *opaque;
+ GMainContext *context;
} IOWatchPoll;
static IOWatchPoll *io_watch_poll_from_source(GSource *source)
@@ -860,7 +876,8 @@ static IOWatchPoll *io_watch_poll_from_source(GSource *source)
return container_of(source, IOWatchPoll, parent);
}
-static gboolean io_watch_poll_prepare(GSource *source, gint *timeout_)
+static gboolean io_watch_poll_prepare(GSource *source,
+ gint *timeout_)
{
IOWatchPoll *iwp = io_watch_poll_from_source(source);
bool now_active = iwp->fd_can_read(iwp->opaque) > 0;
@@ -873,7 +890,7 @@ static gboolean io_watch_poll_prepare(GSource *source, gint *timeout_)
iwp->src = qio_channel_create_watch(
iwp->ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL);
g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL);
- g_source_attach(iwp->src, NULL);
+ g_source_attach(iwp->src, iwp->context);
} else {
g_source_destroy(iwp->src);
g_source_unref(iwp->src);
@@ -920,19 +937,22 @@ static GSourceFuncs io_watch_poll_funcs = {
static guint io_add_watch_poll(QIOChannel *ioc,
IOCanReadHandler *fd_can_read,
QIOChannelFunc fd_read,
- gpointer user_data)
+ gpointer user_data,
+ GMainContext *context)
{
IOWatchPoll *iwp;
int tag;
- iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs, sizeof(IOWatchPoll));
+ iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs,
+ sizeof(IOWatchPoll));
iwp->fd_can_read = fd_can_read;
iwp->opaque = user_data;
iwp->ioc = ioc;
iwp->fd_read = (GSourceFunc) fd_read;
iwp->src = NULL;
+ iwp->context = context;
- tag = g_source_attach(&iwp->parent, NULL);
+ tag = g_source_attach(&iwp->parent, context);
g_source_unref(&iwp->parent);
return tag;
}
@@ -1064,7 +1084,8 @@ static GSource *fd_chr_add_watch(CharDriverState *chr, GIOCondition cond)
return qio_channel_create_watch(s->ioc_out, cond);
}
-static void fd_chr_update_read_handler(CharDriverState *chr)
+static void fd_chr_update_read_handler(CharDriverState *chr,
+ GMainContext *context)
{
FDCharDriver *s = chr->opaque;
@@ -1072,7 +1093,8 @@ static void fd_chr_update_read_handler(CharDriverState *chr)
if (s->ioc_in) {
chr->fd_in_tag = io_add_watch_poll(s->ioc_in,
fd_chr_read_poll,
- fd_chr_read, chr);
+ fd_chr_read, chr,
+ context);
}
}
@@ -1319,7 +1341,8 @@ static void pty_chr_update_read_handler_locked(CharDriverState *chr)
}
}
-static void pty_chr_update_read_handler(CharDriverState *chr)
+static void pty_chr_update_read_handler(CharDriverState *chr,
+ GMainContext *context)
{
qemu_mutex_lock(&chr->chr_write_lock);
pty_chr_update_read_handler_locked(chr);
@@ -1423,7 +1446,8 @@ static void pty_chr_state(CharDriverState *chr, int connected)
if (!chr->fd_in_tag) {
chr->fd_in_tag = io_add_watch_poll(s->ioc,
pty_chr_read_poll,
- pty_chr_read, chr);
+ pty_chr_read,
+ chr, NULL);
}
}
}
@@ -2565,7 +2589,8 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
return TRUE;
}
-static void udp_chr_update_read_handler(CharDriverState *chr)
+static void udp_chr_update_read_handler(CharDriverState *chr,
+ GMainContext *context)
{
NetCharDriver *s = chr->opaque;
@@ -2573,7 +2598,8 @@ static void udp_chr_update_read_handler(CharDriverState *chr)
if (s->ioc) {
chr->fd_in_tag = io_add_watch_poll(s->ioc,
udp_chr_read_poll,
- udp_chr_read, chr);
+ udp_chr_read, chr,
+ context);
}
}
@@ -2976,12 +3002,14 @@ static void tcp_chr_connect(void *opaque)
if (s->ioc) {
chr->fd_in_tag = io_add_watch_poll(s->ioc,
tcp_chr_read_poll,
- tcp_chr_read, chr);
+ tcp_chr_read,
+ chr, NULL);
}
qemu_chr_be_generic_open(chr);
}
-static void tcp_chr_update_read_handler(CharDriverState *chr)
+static void tcp_chr_update_read_handler(CharDriverState *chr,
+ GMainContext *context)
{
TCPCharDriver *s = chr->opaque;
@@ -2993,7 +3021,8 @@ static void tcp_chr_update_read_handler(CharDriverState *chr)
if (s->ioc) {
chr->fd_in_tag = io_add_watch_poll(s->ioc,
tcp_chr_read_poll,
- tcp_chr_read, chr);
+ tcp_chr_read, chr,
+ context);
}
}
--
2.7.4
next prev parent reply other threads:[~2016-09-27 10:13 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-27 10:12 [Qemu-devel] [PULL V2 00/27] Net patches Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 01/27] virtio-net: allow increasing rx queue size Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 02/27] net: hmp_host_net_remove: Del the -net option of the removed host_net Jason Wang
2016-09-27 10:12 ` Jason Wang [this message]
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 04/27] colo-compare: introduce colo compare initialization Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 05/27] net/colo.c: add colo.c to define and handle packet Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 06/27] Jhash: add linux kernel jhashtable in qemu Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 07/27] colo-compare: track connection and enqueue packet Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 08/27] colo-compare: introduce packet comparison thread Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 09/27] colo-compare: add TCP, UDP, ICMP packet comparison Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 10/27] filter-rewriter: introduce filter-rewriter initialization Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 11/27] filter-rewriter: track connection and parse packet Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 12/27] filter-rewriter: rewrite tcp packet to keep secondary connection Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 13/27] MAINTAINERS: add maintainer for COLO-proxy Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 14/27] docs: Add documentation " Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 15/27] e1000: fix buliding complaint Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 16/27] tap: Allow specifying a bridge Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 17/27] net: limit allocation in nc_sendv_compat Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 18/27] e1000e: Flush all receive queues on receive enable Jason Wang
2016-09-27 10:12 ` [Qemu-devel] [PULL V2 19/27] e1000e: Flush receive queues on link up Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 20/27] e1000e: Fix CTRL_EXT.EIAME behavior Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 21/27] e1000e: Fix PBACLR implementation Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 22/27] e1000e: Fix OTHER interrupts processing for MSI-X Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 23/27] e1000e: Fix spurious RX TCP ACK interrupts Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 24/27] e1000e: Fix EIAC register implementation Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 25/27] net: mcf: limit buffer descriptor count Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 26/27] mcf_fec: fix error in qemu_send_packet argument Jason Wang
2016-09-27 10:13 ` [Qemu-devel] [PULL V2 27/27] imx_fec: " Jason Wang
2016-09-27 18:24 ` [Qemu-devel] [PULL V2 00/27] Net patches Peter Maydell
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=1474971187-15627-4-git-send-email-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=wency@cn.fujitsu.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).