All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][QEMU] Allow iohandler removal
@ 2007-08-27 18:51 Ben Guthro
  2007-08-27 19:18 ` Daniel P. Berrange
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Guthro @ 2007-08-27 18:51 UTC (permalink / raw)
  To: xen-devel, Gary Grebus

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

Allow an iohandler callback to safely remove itself from the iohandler list

Signed-off-by: Ben Guthro <bguthro@virtualiron.com>

Signed-off-by: Gary Grebus <ggrebus@virtualiron.com>


[-- Attachment #2: qemu-iohandler-removal.patch --]
[-- Type: text/x-patch, Size: 2731 bytes --]

diff -r 544710158453 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c	Mon Aug 13 13:59:36 2007 -0400
+++ b/tools/ioemu/vl.c	Mon Aug 13 13:59:36 2007 -0400
@@ -4377,6 +4377,7 @@ void dumb_display_init(DisplayState *ds)
 
 typedef struct IOHandlerRecord {
     int fd;
+    int defunct;
     IOCanRWHandler *fd_read_poll;
     IOHandler *fd_read;
     IOHandler *fd_write;
@@ -4405,8 +4406,7 @@ int qemu_set_fd_handler2(int fd,
             if (ioh == NULL)
                 break;
             if (ioh->fd == fd) {
-                *pioh = ioh->next;
-                qemu_free(ioh);
+                ioh->defunct = 1;  /* Defer removal to the main polling loop */
                 break;
             }
             pioh = &ioh->next;
@@ -4423,6 +4423,7 @@ int qemu_set_fd_handler2(int fd,
         first_io_handler = ioh;
     found:
         ioh->fd = fd;
+        ioh->defunct = 0;
         ioh->fd_read_poll = fd_read_poll;
         ioh->fd_read = fd_read;
         ioh->fd_write = fd_write;
@@ -6189,6 +6190,7 @@ void main_loop_wait(int timeout)
 void main_loop_wait(int timeout)
 {
     IOHandlerRecord *ioh, *ioh_next;
+    IOHandlerRecord **ioh_prvlnk;
     fd_set rfds, wfds, xfds;
     int ret, nfds;
     struct timeval tv;
@@ -6222,7 +6224,19 @@ void main_loop_wait(int timeout)
     FD_ZERO(&rfds);
     FD_ZERO(&wfds);
     FD_ZERO(&xfds);
-    for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
+    ioh_prvlnk = &first_io_handler;
+
+    for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
+
+        ioh_next = ioh->next;
+
+        if (ioh->defunct) {
+            *ioh_prvlnk = ioh->next;
+            ioh->next = NULL;
+            qemu_free(ioh);
+            continue;
+        }
+
         if (ioh->fd_read &&
             (!ioh->fd_read_poll ||
              ioh->fd_read_poll(ioh->opaque) != 0)) {
@@ -6235,6 +6249,8 @@ void main_loop_wait(int timeout)
             if (ioh->fd > nfds)
                 nfds = ioh->fd;
         }
+
+        ioh_prvlnk = &ioh->next;
     }
     
     tv.tv_sec = 0;
@@ -6250,13 +6266,12 @@ void main_loop_wait(int timeout)
 #endif
     ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
     if (ret > 0) {
-        /* XXX: better handling of removal */
         for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
             ioh_next = ioh->next;
-            if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
+            if (!ioh->defunct && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
                 ioh->fd_read(ioh->opaque);
             }
-            if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
+            if (!ioh->defunct && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
                 ioh->fd_write(ioh->opaque);
             }
         }

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][QEMU] Allow iohandler removal
  2007-08-27 18:51 [PATCH][QEMU] Allow iohandler removal Ben Guthro
@ 2007-08-27 19:18 ` Daniel P. Berrange
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrange @ 2007-08-27 19:18 UTC (permalink / raw)
  To: Ben Guthro; +Cc: Gary Grebus, xen-devel

On Mon, Aug 27, 2007 at 02:51:14PM -0400, Ben Guthro wrote:
> Allow an iohandler callback to safely remove itself from the iohandler list

Already fixed in upstream QEMU - please use the existing code from there
rather than re-writing it.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-27 19:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-27 18:51 [PATCH][QEMU] Allow iohandler removal Ben Guthro
2007-08-27 19:18 ` Daniel P. Berrange

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.