iohandler: update qemu_fd_set_handler to work with null call back arg
PATCH 1/1 iohandler: update qemu_fd_set_handler to work with null call back arg
Many users of qemu_fd_set_handler including VirtFS use NULL call back arg. Update fd_trampoline and qemu_fd_set_handler to work with NULL call back arg
---
Changes from V1:
Add support for dropping event source
iohandler.c | 31 +++++++++++++------------------ 1 files changed, 13 insertions(+), 18 deletions(-)
iohandler.c +13 -18
@@ -93,9 +93,8 @@ static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq {IOTrampoline *tramp = opaque; -if (tramp->opaque ==NULL ) { +if (!tramp->fd_read && !tramp->fd_write)return FALSE; - }if ((cond &G_IO_IN ) && tramp->fd_read) { tramp->fd_read (tramp->opaque);
@@ -113,6 +112,7 @@ int qemu_set_fd_handler(int fd, IOHandler *fd_write, void *opaque) { +GIOCondition cond =0 ;static IOTrampoline fd_trampolines[FD_SETSIZE ];IOTrampoline *tramp = &fd_trampolines[fd];
@@ -121,25 +121,20 @@ int qemu_set_fd_handler(int fd,g_source_remove (tramp->tag); } -if (opaque) { -GIOCondition cond =0 ; - - tramp->fd_read = fd_read; - tramp->fd_write = fd_write; - tramp->opaque = opaque; - -if (fd_read) { - cond |=G_IO_IN |G_IO_ERR ; - } - -if (fd_write) { - cond |=G_IO_OUT |G_IO_ERR ; - } +if (fd_read) { + cond |=G_IO_IN |G_IO_ERR ; + } - tramp->chan =g_io_channel_unix_new (fd); - tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp); +if (fd_write) { + cond |=G_IO_OUT |G_IO_ERR ; } + tramp->fd_read = fd_read; + tramp->fd_write = fd_write; + tramp->opaque = opaque; + tramp->chan =g_io_channel_unix_new (fd); + tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp); +return 0 ; }
Signature · 1 line
1.7.4.1
Quoted 16 lines · Aneesh Kumar K.V
Many users of
qemu_fd_set_handlerincluding VirtFS use NULL call back arg. Updatefd_trampolineandqemu_fd_set_handlerto work with NULL call back argSigned-off-by Aneesh Kumar K.V<[email protected]>---
Changes from V1:
Add support for dropping event sourceiohandler.c | 31 +++++++++++++------------------ 1 files changed, 13 insertions(+), 18 deletions(-)iohandler.c +0
-0
iohandler.c static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq · line 98
Quoted 7 lines
iohandler.c +1
-2@@ -93,9 +93,8 @@ static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq {IOTrampoline *tramp = opaque; -if (tramp->opaque ==NULL ) { +if (!tramp->fd_read&& !tramp->fd_write)return FALSE; - }
Heh, this is pretty anti-CODING_STYLE :-)
At any rate, I think this whole segment has to go. It's easier to not deal with removing sources in two places.
Quoted 35 lines
iohandler.c +4
-16if ((cond&G_IO_IN )&& tramp->fd_read) { tramp->fd_read (tramp->opaque);@@ -113,6 +112,7 @@ int qemu_set_fd_handler(int fd, IOHandler *fd_write, void *opaque) { +GIOCondition cond =0 ;static IOTrampoline fd_trampolines[FD_SETSIZE ];IOTrampoline *tramp =&fd_trampolines[fd];@@ -121,25 +121,20 @@ int qemu_set_fd_handler(int fd,g_source_remove (tramp->tag); } -if (opaque) { -GIOCondition cond =0 ; - - tramp->fd_read = fd_read; - tramp->fd_write = fd_write; - tramp->opaque = opaque; - -if (fd_read) { - cond |=G_IO_IN |G_IO_ERR ; - } - -if (fd_write) { - cond |=G_IO_OUT |G_IO_ERR ; - } +if (fd_read) { + cond |=G_IO_IN |G_IO_ERR ; + } - tramp->chan =g_io_channel_unix_new (fd); - tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp);
iohandler.c int qemu_set_fd_handler(int fd, · line 137
Quoted 10 lines
iohandler.c +8
-0+if (fd_write) { + cond |=G_IO_OUT |G_IO_ERR ; } + tramp->fd_read = fd_read; + tramp->fd_write = fd_write; + tramp->opaque = opaque; + tramp->chan =g_io_channel_unix_new (fd); + tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp); +
I think this is a bit more complicated than is really needed. Here's what I came up with which also fixes another bug where the io channel could be freed twice. I stumbled across this via a very strange failure scenario. Avi, it might be worth trying this patch to see if it fixes your problem too.
One thing that I found challenging debugging this, coroutines make valgrind very unhappy. Is it possible that we could have a command line switch to fall back to the thread based coroutines so to make things more valgrind friendly?
iohandler.c +2 -5
@@ -93,10 +93,6 @@ static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq {IOTrampoline *tramp = opaque; -if (tramp->opaque ==NULL ) { -return FALSE; - } -if ((cond &G_IO_IN ) && tramp->fd_read) { tramp->fd_read (tramp->opaque); }
@@ -119,9 +115,10 @@ int qemu_set_fd_handler(int fd,if (tramp->tag !=0 ) {g_io_channel_unref (tramp->chan);g_source_remove (tramp->tag); + tramp->tag =0 ; } -if (opaque) { +if (fd_read || fd_write || opaque) {GIOCondition cond =0 ; tramp->fd_read = fd_read;
Regards,
Anthony Liguori
Quoted 3 lines
iohandler.c +0
-0return 0 ; }
Quoted 82 lines · Anthony Liguori
Quoted 16 lines · Aneesh Kumar K.V
Many users of
qemu_fd_set_handlerincluding VirtFS use NULL call back arg. Updatefd_trampolineandqemu_fd_set_handlerto work with NULL call back argSigned-off-by Aneesh Kumar K.V<[email protected]>---
Changes from V1:
Add support for dropping event sourceiohandler.c | 31 +++++++++++++------------------ 1 files changed, 13 insertions(+), 18 deletions(-)iohandler.c +0
-0iohandler.c static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq · line 98
Quoted 7 lines
iohandler.c +1
-2@@ -93,9 +93,8 @@ static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaq {IOTrampoline *tramp = opaque; -if (tramp->opaque ==NULL ) { +if (!tramp->fd_read&& !tramp->fd_write)return FALSE; - }Heh, this is pretty anti-CODING_STYLE :-)
At any rate, I think this whole segment has to go. It's easier to not deal with removing sources in two places.
Quoted 35 lines
iohandler.c +4
-16if ((cond&G_IO_IN )&& tramp->fd_read) { tramp->fd_read (tramp->opaque);@@ -113,6 +112,7 @@ int qemu_set_fd_handler(int fd, IOHandler *fd_write, void *opaque) { +GIOCondition cond =0 ;static IOTrampoline fd_trampolines[FD_SETSIZE ];IOTrampoline *tramp =&fd_trampolines[fd];@@ -121,25 +121,20 @@ int qemu_set_fd_handler(int fd,g_source_remove (tramp->tag); } -if (opaque) { -GIOCondition cond =0 ; - - tramp->fd_read = fd_read; - tramp->fd_write = fd_write; - tramp->opaque = opaque; - -if (fd_read) { - cond |=G_IO_IN |G_IO_ERR ; - } - -if (fd_write) { - cond |=G_IO_OUT |G_IO_ERR ; - } +if (fd_read) { + cond |=G_IO_IN |G_IO_ERR ; + } - tramp->chan =g_io_channel_unix_new (fd); - tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp);iohandler.c int qemu_set_fd_handler(int fd, · line 137
Quoted 10 lines
iohandler.c +8
-0+if (fd_write) { + cond |=G_IO_OUT |G_IO_ERR ; } + tramp->fd_read = fd_read; + tramp->fd_write = fd_write; + tramp->opaque = opaque; + tramp->chan =g_io_channel_unix_new (fd); + tramp->tag =g_io_add_watch (tramp->chan, cond, fd_trampoline, tramp); +I think this is a bit more complicated than is really needed. Here's what I came up with which also fixes another bug where the io channel could be freed twice. I stumbled across this via a very strange failure scenario. Avi, it might be worth trying this patch to see if it fixes your problem too.
Quoted 4 lines
One thing that I found challenging debugging this, coroutines make valgrind very unhappy. Is it possible that we could have a command line switch to fall back to the thread based coroutines so to make things more valgrind friendly?
We definitely can look at a configure option that build with coroutine-gthread
Quoted 20 lines
iohandler.c +0
-0@@ -93,10 +93,6 @@ static gboolean fd_trampoline(GIOChannel *chan,GIOCondition cond, gpointer opaq
{ IOTrampoline *tramp = opaque;iohandler.c +0
-4-if (tramp->opaque ==NULL ) { -return FALSE; - } -if ((cond &G_IO_IN ) && tramp->fd_read) { tramp->fd_read (tramp->opaque); }@@ -119,9 +115,10 @@ int qemu_set_fd_handler(int fd,if (tramp->tag !=0 ) {
iohandler.c int qemu_set_fd_handler(int fd, · line 124
Quoted 10 lines
iohandler.c +2
-1g_io_channel_unref (tramp->chan);g_source_remove (tramp->tag); + tramp->tag =0 ; } -if (opaque) { +if (fd_read || fd_write || opaque) {GIOCondition cond =0 ; tramp->fd_read = fd_read;
I tested above change with virtfs and it works.
-aneesh
Quoted 2 lines · Anthony Liguori
I think this is a bit more complicated than is really needed. Here's what I came up with which also fixes another bug where the io channel could be freed twice. I stumbled across this via a very strange failure scenario. Avi, it might be worth trying this patch to see if it fixes your problem too.
Right now, I've got more than just one problem.
Quoted 2 lines
One thing that I found challenging debugging this, coroutines make valgrind very unhappy. Is it possible that we could have a command line switch to fall back to the thread based coroutines so to make things more valgrind friendly?
How is valgrind even aware of coroutines? Unless is doesn't implement makecontext correctly, it shouldn't even be aware of them.
Signature · 1 line
error compiling committee.c: too many arguments to function
Am 08.09.2011 12:07, schrieb Avi Kivity:
Quoted 11 lines · Anthony Liguori
Quoted 6 lines
I think this is a bit more complicated than is really needed. Here's what I came up with which also fixes another bug where the io channel could be freed twice. I stumbled across this via a very strange failure scenario. Avi, it might be worth trying this patch to see if it fixes your problem too.
Right now, I've got more than just one problem.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
One thing that I found challenging debugging this, coroutines make valgrind very unhappy. Is it possible that we could have a command line switch to fall back to the thread based coroutines so to make things more valgrind friendly?
How is valgrind even aware of coroutines? Unless is doesn't implement makecontext correctly, it shouldn't even be aware of them.
The F15 valgrind complains three times that the program is switching stacks, but then it shuts up and just works as normal.
Kevin
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Anthony Liguori
I think this is a bit more complicated than is really needed. Here's what I came up with which also fixes another bug where the io channel could be freed twice. I stumbled across this via a very strange failure scenario. Avi, it might be worth trying this patch to see if it fixes your problem too.
Right now, I've got more than just one problem.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
One thing that I found challenging debugging this, coroutines make valgrind very unhappy. Is it possible that we could have a command line switch to fall back to the thread based coroutines so to make things more valgrind friendly?
How is valgrind even aware of coroutines? Unless is doesn't implement makecontext correctly, it shouldn't even be aware of them.
It detects stack switching and has trouble differentiating between a legitimate stack switch and something more nefarious. I believe the heuristic it currently uses is the distance that RSP moves. If it moves more than a certain threshold, it assumes that's a stack switch.
Regards,
Anthony Liguori