char: remove the right fd been watched in qemu_chr_fe_set_handlers()
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> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
dfd917a9c2
commit
8487ce45f8
@ -58,7 +58,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
|
|||||||
ret = qio_channel_read(
|
ret = qio_channel_read(
|
||||||
chan, (gchar *)buf, len, NULL);
|
chan, (gchar *)buf, len, NULL);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
|
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ static void fd_chr_update_read_handler(Chardev *chr,
|
|||||||
{
|
{
|
||||||
FDChardev *s = FD_CHARDEV(chr);
|
FDChardev *s = FD_CHARDEV(chr);
|
||||||
|
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
if (s->ioc_in) {
|
if (s->ioc_in) {
|
||||||
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc_in,
|
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc_in,
|
||||||
fd_chr_read_poll,
|
fd_chr_read_poll,
|
||||||
@ -103,7 +103,7 @@ static void char_fd_finalize(Object *obj)
|
|||||||
Chardev *chr = CHARDEV(obj);
|
Chardev *chr = CHARDEV(obj);
|
||||||
FDChardev *s = FD_CHARDEV(obj);
|
FDChardev *s = FD_CHARDEV(obj);
|
||||||
|
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
if (s->ioc_in) {
|
if (s->ioc_in) {
|
||||||
object_unref(OBJECT(s->ioc_in));
|
object_unref(OBJECT(s->ioc_in));
|
||||||
}
|
}
|
||||||
|
@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr,
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_remove_watch_poll(guint tag)
|
static void io_remove_watch_poll(guint tag, GMainContext *context)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
IOWatchPoll *iwp;
|
IOWatchPoll *iwp;
|
||||||
|
|
||||||
g_return_if_fail(tag > 0);
|
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);
|
g_return_if_fail(source != NULL);
|
||||||
|
|
||||||
iwp = io_watch_poll_from_source(source);
|
iwp = io_watch_poll_from_source(source);
|
||||||
@ -146,10 +146,10 @@ static void io_remove_watch_poll(guint tag)
|
|||||||
g_source_destroy(&iwp->parent);
|
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) {
|
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;
|
chr->fd_in_tag = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ guint io_add_watch_poll(Chardev *chr,
|
|||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GMainContext *context);
|
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);
|
int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ static void pty_chr_state(Chardev *chr, int connected)
|
|||||||
g_source_remove(s->open_tag);
|
g_source_remove(s->open_tag);
|
||||||
s->open_tag = 0;
|
s->open_tag = 0;
|
||||||
}
|
}
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
s->connected = 0;
|
s->connected = 0;
|
||||||
/* (re-)connect poll interval for idle guests: once per second.
|
/* (re-)connect poll interval for idle guests: once per second.
|
||||||
* We check more frequently in case the guests sends data to
|
* We check more frequently in case the guests sends data to
|
||||||
|
@ -328,7 +328,7 @@ static void tcp_chr_free_connection(Chardev *chr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tcp_set_msgfds(chr, NULL, 0);
|
tcp_set_msgfds(chr, NULL, 0);
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
object_unref(OBJECT(s->sioc));
|
object_unref(OBJECT(s->sioc));
|
||||||
s->sioc = NULL;
|
s->sioc = NULL;
|
||||||
object_unref(OBJECT(s->ioc));
|
object_unref(OBJECT(s->ioc));
|
||||||
@ -498,7 +498,7 @@ static void tcp_chr_update_read_handler(Chardev *chr,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
if (s->ioc) {
|
if (s->ioc) {
|
||||||
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
|
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
|
||||||
tcp_chr_read_poll,
|
tcp_chr_read_poll,
|
||||||
|
@ -81,7 +81,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
|
|||||||
ret = qio_channel_read(
|
ret = qio_channel_read(
|
||||||
s->ioc, (char *)s->buf, sizeof(s->buf), NULL);
|
s->ioc, (char *)s->buf, sizeof(s->buf), NULL);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
s->bufcnt = ret;
|
s->bufcnt = ret;
|
||||||
@ -101,7 +101,7 @@ static void udp_chr_update_read_handler(Chardev *chr,
|
|||||||
{
|
{
|
||||||
UdpChardev *s = UDP_CHARDEV(chr);
|
UdpChardev *s = UDP_CHARDEV(chr);
|
||||||
|
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
if (s->ioc) {
|
if (s->ioc) {
|
||||||
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
|
chr->fd_in_tag = io_add_watch_poll(chr, s->ioc,
|
||||||
udp_chr_read_poll,
|
udp_chr_read_poll,
|
||||||
@ -115,7 +115,7 @@ static void char_udp_finalize(Object *obj)
|
|||||||
Chardev *chr = CHARDEV(obj);
|
Chardev *chr = CHARDEV(obj);
|
||||||
UdpChardev *s = UDP_CHARDEV(obj);
|
UdpChardev *s = UDP_CHARDEV(obj);
|
||||||
|
|
||||||
remove_fd_in_watch(chr);
|
remove_fd_in_watch(chr, NULL);
|
||||||
if (s->ioc) {
|
if (s->ioc) {
|
||||||
object_unref(OBJECT(s->ioc));
|
object_unref(OBJECT(s->ioc));
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
|
|||||||
cc = CHARDEV_GET_CLASS(s);
|
cc = CHARDEV_GET_CLASS(s);
|
||||||
if (!opaque && !fd_can_read && !fd_read && !fd_event) {
|
if (!opaque && !fd_can_read && !fd_read && !fd_event) {
|
||||||
fe_open = 0;
|
fe_open = 0;
|
||||||
remove_fd_in_watch(s);
|
remove_fd_in_watch(s, context);
|
||||||
} else {
|
} else {
|
||||||
fe_open = 1;
|
fe_open = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user