qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler()


From: Juan Quintela
Subject: [Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler()
Date: Wed, 10 Mar 2010 11:03:28 +0100

Switch all users of qemu_set_fd_handler(fd, NULL, NULL, NULL) to this
new function.

Signed-off-by: Juan Quintela <address@hidden>
---
 audio/alsaaudio.c |    4 ++--
 audio/ossaudio.c  |    6 +++---
 hw/xen_backend.c  |    4 ++--
 migration-exec.c  |    2 +-
 migration-fd.c    |    2 +-
 migration-tcp.c   |    4 ++--
 migration-unix.c  |    4 ++--
 migration.c       |    6 +++---
 net/socket.c      |    6 +++---
 net/vde.c         |    2 +-
 qemu-char.c       |   24 +++++++++++-------------
 qemu-char.h       |    1 +
 usb-linux.c       |    2 +-
 vl.c              |   19 +++++++++++++------
 vnc.c             |    4 ++--
 15 files changed, 48 insertions(+), 42 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 88344ff..b4437e6 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -134,7 +134,7 @@ static void alsa_fini_poll (struct pollhlp *hlp)

     if (pfds) {
         for (i = 0; i < hlp->count; ++i) {
-            qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
+            qemu_remove_fd_handler (pfds[i].fd);
         }
         qemu_free (pfds);
     }
@@ -286,7 +286,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct 
pollhlp *hlp, int mask)
                    pfds[i].events, i, pfds[i].fd, err);

             while (i--) {
-                qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
+                qemu_remove_fd_handler (pfds[i].fd);
             }
             qemu_free (pfds);
             return -1;
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 42bffae..ccabf05 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -122,7 +122,7 @@ static void oss_anal_close (int *fdp)
 {
     int err;

-    qemu_set_fd_handler (*fdp, NULL, NULL, NULL);
+    qemu_set_fd_handler (*fdp);
     err = close (*fdp);
     if (err) {
         oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
@@ -651,7 +651,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)

     case VOICE_DISABLE:
         if (hw->poll_mode) {
-            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
+            qemu_remove_fd_handler (oss->fd);
             hw->poll_mode = 0;
         }

@@ -835,7 +835,7 @@ static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
     case VOICE_DISABLE:
         if (hw->poll_mode) {
             hw->poll_mode = 0;
-            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
+            qemu_set_fd_handler (oss->fd);
         }
         break;
     }
diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index a2e408f..37d24c5 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -635,7 +635,7 @@ int xen_be_init(void)
     return 0;

 err:
-    qemu_set_fd_handler(xs_fileno(xenstore), NULL, NULL, NULL);
+    qemu_clear_fd_handler(xs_fileno(xenstore));
     xs_daemon_close(xenstore);
     xenstore = NULL;

@@ -667,7 +667,7 @@ void xen_be_unbind_evtchn(struct XenDevice *xendev)
 {
     if (xendev->local_port == -1)
        return;
-    qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
+    qemu_remove_fd_handler(xc_evtchn_fd(xendev->evtchndev));
     xc_evtchn_unbind(xendev->evtchndev, xendev->local_port);
     xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port);
     xendev->local_port = -1;
diff --git a/migration-exec.c b/migration-exec.c
index c971145..45667d7 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -125,7 +125,7 @@ static void exec_accept_incoming_migration(void *opaque)
         vm_start();

 err:
-    qemu_set_fd_handler(qemu_stdio_fd(f), NULL, NULL, NULL);
+    qemu_remove_fd_handler(qemu_stdio_fd(f));
     qemu_fclose(f);
 }

diff --git a/migration-fd.c b/migration-fd.c
index 93e1c4e..9aa4191 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -118,7 +118,7 @@ static void fd_accept_incoming_migration(void *opaque)
         vm_start();

 err:
-    qemu_set_fd_handler(qemu_stdio_fd(f), NULL, NULL, NULL);
+    qemu_remove_fd_handler(qemu_stdio_fd(f));
     qemu_fclose(f);
 }

diff --git a/migration-tcp.c b/migration-tcp.c
index 80ebbc5..228f279 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -66,7 +66,7 @@ static void tcp_wait_for_connect(void *opaque)
         return;
     }

-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);

     if (val == 0)
         migrate_fd_connect(s);
@@ -176,7 +176,7 @@ static void tcp_accept_incoming_migration(void *opaque)
 out_fopen:
     qemu_fclose(f);
 out:
-    qemu_set_fd_handler(s, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s);
     close(s);
     close(c);
 }
diff --git a/migration-unix.c b/migration-unix.c
index 891b3a7..c998e95 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -65,7 +65,7 @@ static void unix_wait_for_connect(void *opaque)
         return;
     }

-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);

     if (val == 0)
         migrate_fd_connect(s);
@@ -182,7 +182,7 @@ static void unix_accept_incoming_migration(void *opaque)
 out_fopen:
     qemu_fclose(f);
 out:
-    qemu_set_fd_handler(s, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s);
     close(s);
     close(c);
 }
diff --git a/migration.c b/migration.c
index 2da715c..282ba99 100644
--- a/migration.c
+++ b/migration.c
@@ -292,7 +292,7 @@ void migrate_fd_error(FdMigrationState *s)

 void migrate_fd_cleanup(FdMigrationState *s)
 {
-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);

     if (s->file) {
         DPRINTF("closing file\n");
@@ -315,7 +315,7 @@ void migrate_fd_put_notify(void *opaque)
 {
     FdMigrationState *s = opaque;

-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);
     qemu_file_put_notify(s->file);
 }

@@ -449,6 +449,6 @@ int migrate_fd_close(void *opaque)
 {
     FdMigrationState *s = opaque;

-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);
     return s->close(s);
 }
diff --git a/net/socket.c b/net/socket.c
index 442a9c7..e47374e 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -84,7 +84,7 @@ static void net_socket_send(void *opaque)
     } else if (size == 0) {
         /* end of connection */
     eoc:
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         closesocket(s->fd);
         return;
     }
@@ -143,7 +143,7 @@ static void net_socket_send_dgram(void *opaque)
         return;
     if (size == 0) {
         /* end of connection */
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         return;
     }
     qemu_send_packet(&s->nc, s->buf, size);
@@ -212,7 +212,7 @@ fail:
 static void net_socket_cleanup(VLANClientState *nc)
 {
     NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);
     close(s->fd);
 }

diff --git a/net/vde.c b/net/vde.c
index 0b46fa6..598604f 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -65,7 +65,7 @@ static ssize_t vde_receive(VLANClientState *nc, const uint8_t 
*buf, size_t size)
 static void vde_cleanup(VLANClientState *nc)
 {
     VDEState *s = DO_UPCAST(VDEState, nc, nc);
-    qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL);
+    qemu_remove_fd_handler(vde_datafd(s->vde));
     vde_close(s->vde);
 }

diff --git a/qemu-char.c b/qemu-char.c
index 3635f4e..8574a0f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -553,8 +553,7 @@ static void fd_chr_read(void *opaque)
         return;
     size = read(s->fd_in, buf, len);
     if (size == 0) {
-        /* FD has been closed. Remove it from the active list.  */
-        qemu_set_fd_handler(s->fd_in, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd_in);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -582,7 +581,7 @@ static void fd_chr_close(struct CharDriverState *chr)
     if (s->fd_in >= 0) {
         if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
         } else {
-            qemu_set_fd_handler(s->fd_in, NULL, NULL, NULL);
+            qemu_remove_fd_handler(s->fd_in);
         }
     }

@@ -673,8 +672,7 @@ static void stdio_read(void *opaque)
     }
     size = read(0, buf, 1);
     if (size == 0) {
-        /* stdin has been closed. Remove it from the active list.  */
-        qemu_set_fd_handler(0, NULL, NULL, NULL);
+        qemu_remove_fd_handler(0);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -730,7 +728,7 @@ static void qemu_chr_close_stdio(struct CharDriverState 
*chr)
 {
     term_exit();
     stdio_nb_clients--;
-    qemu_set_fd_handler(0, NULL, NULL, NULL);
+    qemu_remove_fd_handler(0);
     fd_chr_close(chr);
 }

@@ -883,7 +881,7 @@ static void pty_chr_state(CharDriverState *chr, int 
connected)
     PtyCharDriver *s = chr->opaque;

     if (!connected) {
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         s->connected = 0;
         s->polling = 0;
         /* (re-)connect poll interval for idle guests: once per second.
@@ -919,7 +917,7 @@ static void pty_chr_close(struct CharDriverState *chr)
 {
     PtyCharDriver *s = chr->opaque;

-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->fd);
     close(s->fd);
     qemu_del_timer(s->timer);
     qemu_free_timer(s->timer);
@@ -1810,7 +1808,7 @@ static void udp_chr_close(CharDriverState *chr)
 {
     NetCharDriver *s = chr->opaque;
     if (s->fd >= 0) {
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         closesocket(s->fd);
     }
     qemu_free(s);
@@ -2013,7 +2011,7 @@ static void tcp_chr_read(void *opaque)
         if (s->listen_fd >= 0) {
             qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
         }
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         closesocket(s->fd);
         s->fd = -1;
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
@@ -2096,7 +2094,7 @@ static void tcp_chr_accept(void *opaque)
     if (s->do_nodelay)
         socket_set_nodelay(fd);
     s->fd = fd;
-    qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(s->listen_fd);
     tcp_chr_connect(chr);
 }

@@ -2104,11 +2102,11 @@ static void tcp_chr_close(CharDriverState *chr)
 {
     TCPCharDriver *s = chr->opaque;
     if (s->fd >= 0) {
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->fd);
         closesocket(s->fd);
     }
     if (s->listen_fd >= 0) {
-        qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
+        qemu_remove_fd_handler(s->listen_fd);
         closesocket(s->listen_fd);
     }
     qemu_free(s);
diff --git a/qemu-char.h b/qemu-char.h
index 3bad12d..fcb770b 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -101,4 +101,5 @@ int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
                         IOHandler *fd_write,
                         void *opaque);
+int qemu_remove_fd_handler(int fd);
 #endif
diff --git a/usb-linux.c b/usb-linux.c
index a9c15c6..86d3595 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -957,7 +957,7 @@ static int usb_host_close(USBHostDevice *dev)
     if (dev->fd == -1)
         return -1;

-    qemu_set_fd_handler(dev->fd, NULL, NULL, NULL);
+    qemu_remove_fd_handler(dev->fd);
     dev->closing = 1;
     async_complete(dev);
     dev->closing = 0;
diff --git a/vl.c b/vl.c
index 3bf8b87..6cbdf14 100644
--- a/vl.c
+++ b/vl.c
@@ -2602,6 +2602,18 @@ typedef struct IOHandlerRecord {
 static QTAILQ_HEAD(, IOHandlerRecord) io_handlers =
     QTAILQ_HEAD_INITIALIZER(io_handlers);

+int qemu_remove_fd_handler(int fd)
+{
+    IOHandlerRecord *ioh;
+
+    QTAILQ_FOREACH(ioh, &io_handlers, next) {
+        if (ioh->fd == fd) {
+            ioh->deleted = 1;
+            break;
+        }
+    }
+    return 0;
+}

 int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
@@ -2611,12 +2623,7 @@ int qemu_set_fd_handler(int fd,
     IOHandlerRecord *ioh;

     if (!fd_read && !fd_write) {
-        QTAILQ_FOREACH(ioh, &io_handlers, next) {
-            if (ioh->fd == fd) {
-                ioh->deleted = 1;
-                break;
-            }
-        }
+        qemu_remove_fd_handler(fd);
     } else {
         QTAILQ_FOREACH(ioh, &io_handlers, next) {
             if (ioh->fd == fd)
diff --git a/vnc.c b/vnc.c
index 2cfb0eb..2a9fcb9 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1076,7 +1076,7 @@ static void vnc_disconnect_start(VncState *vs)
 {
     if (vs->csock == -1)
         return;
-    qemu_set_fd_handler(vs->csock, NULL, NULL, NULL);
+    qemu_remove_fd_handler(vs->csock);
     closesocket(vs->csock);
     vs->csock = -1;
 }
@@ -2475,7 +2475,7 @@ void vnc_display_close(DisplayState *ds)
         vs->display = NULL;
     }
     if (vs->lsock != -1) {
-        qemu_set_fd_handler(vs->lsock, NULL, NULL, NULL);
+        qemu_remove_fd_handler(vs->lsock);
         close(vs->lsock);
         vs->lsock = -1;
     }
-- 
1.6.6.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]