qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/9] Clear fd handlers
@ 2010-03-09 22:25 Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 1/9] Convert io handlers to QLIST Juan Quintela
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel

Hi

This series :
- convert io_handlers to one QLIST
- once there, qemu_set_fd_handlers2() has lots of arguments that are a lot of times NULL.
  Introduce a set of functions to not have to pass NULL values.
 - qemu_clear_fd_handlers(): remove it
 - qemu_set_fd_read_handler(): only read
 - qemu_set_fd_write_handler(): only write
 - qemu_set_fd_rw_handler(): read/write
 - qemu_set_fd_poll_handler(): it was only used for reads and in qemu-char.c.

- once there fix bt that don't need poll at all (having a poll function that always return true
  is the equivalent of not having one).
- remove cast to (void *)(unsigned long) for things that already were pointers
- IOCanRWHandler is only used for reads -> rename it (almost no users).

ToDo:
- to remove the export of qemu_set_fd_handlers2() we need a solution for tap.
  Tap is the only user in qemu that uses poll, read and write, and it changes in very imaginative
  ways:
    qemu_set_fd_handler2(s->fd,
                         s->read_poll  ? tap_can_send : NULL,
                         s->read_poll  ? tap_send     : NULL,
                         s->write_poll ? tap_writable : NULL,
                         s);

  No ideas about how to transform this into something that don't use NULL's in any of its fields
  other than a row of if's.

- removal of poll function. comment of qemu_set_fd_handler2()
  /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */

  But qemu-char.c is a complex beast, and would preffer to 1st get this patches in, and then
  work on the other stuff.

- obvious optimization now is to have the FD_SET() for write/read already filled, but I
  haven't done any meassurement.

Comments?

Juan Quintela (9):
  Convert io handlers to QLIST
  Introduce qemu_clear_fd_handler()
  Introduce qemu_set_fd_read_handler()
  Introduce qemu_set_fd_write_handler()
  Introduce qemu_set_fd_rw_handler()
  bt: remove bt_host_read_poll()
  Introduce qemu_set_fd_poll_handler()
  remove useless cast
  rename IOCanRWHandler to IOCanReadHandler

 aio.c               |    2 +-
 audio/alsaaudio.c   |   12 +++---
 audio/ossaudio.c    |   10 ++--
 bt-host.c           |    9 +----
 bt-vhci.c           |    2 +-
 hw/baum.c           |    2 +-
 hw/xen_backend.c    |   10 ++--
 migration-exec.c    |    8 ++--
 migration-fd.c      |    5 +-
 migration-tcp.c     |   10 ++--
 migration-unix.c    |   10 ++--
 migration.c         |    8 ++--
 net/socket.c        |   14 +++---
 net/vde.c           |    4 +-
 qemu-aio.h          |    4 +-
 qemu-char.c         |   48 +++++++++++-----------
 qemu-char.h         |   25 ++++++++---
 qemu-common.h       |    2 +-
 qemu-tool.c         |    9 ++--
 usb-linux.c         |    4 +-
 vl.c                |  114 +++++++++++++++++++++++++++++++++++---------------
 vnc-auth-sasl.c     |    2 +-
 vnc-auth-vencrypt.c |    6 +-
 vnc.c               |   12 +++---
 24 files changed, 190 insertions(+), 142 deletions(-)

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

* [Qemu-devel] [PATCH 1/9] Convert io handlers to QLIST
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
@ 2010-03-09 22:25 ` Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 2/9] Introduce qemu_clear_fd_handler() Juan Quintela
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 vl.c |   35 ++++++++++++++---------------------
 1 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/vl.c b/vl.c
index 10d8e34..83ff652 100644
--- a/vl.c
+++ b/vl.c
@@ -2597,10 +2597,12 @@ typedef struct IOHandlerRecord {
     void *opaque;
     /* temporary data */
     struct pollfd *ufd;
-    struct IOHandlerRecord *next;
+    QTAILQ_ENTRY(IOHandlerRecord) next;
 } IOHandlerRecord;

-static IOHandlerRecord *first_io_handler;
+static QTAILQ_HEAD(, IOHandlerRecord) io_handlers =
+    QTAILQ_HEAD_INITIALIZER(io_handlers);
+

 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */
@@ -2610,28 +2612,22 @@ int qemu_set_fd_handler2(int fd,
                          IOHandler *fd_write,
                          void *opaque)
 {
-    IOHandlerRecord **pioh, *ioh;
+    IOHandlerRecord *ioh;

     if (!fd_read && !fd_write) {
-        pioh = &first_io_handler;
-        for(;;) {
-            ioh = *pioh;
-            if (ioh == NULL)
-                break;
+        QTAILQ_FOREACH(ioh, &io_handlers, next) {
             if (ioh->fd == fd) {
                 ioh->deleted = 1;
                 break;
             }
-            pioh = &ioh->next;
         }
     } else {
-        for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
+        QTAILQ_FOREACH(ioh, &io_handlers, next) {
             if (ioh->fd == fd)
                 goto found;
         }
         ioh = qemu_mallocz(sizeof(IOHandlerRecord));
-        ioh->next = first_io_handler;
-        first_io_handler = ioh;
+        QTAILQ_INSERT_TAIL(&io_handlers, ioh, next);
     found:
         ioh->fd = fd;
         ioh->fd_read_poll = fd_read_poll;
@@ -3822,7 +3818,7 @@ 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) {
+    QTAILQ_FOREACH(ioh, &io_handlers, next) {
         if (ioh->deleted)
             continue;
         if (ioh->fd_read &&
@@ -3848,9 +3844,9 @@ void main_loop_wait(int timeout)
     ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
     qemu_mutex_lock_iothread();
     if (ret > 0) {
-        IOHandlerRecord **pioh;
+        IOHandlerRecord *pioh;

-        for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
+        QTAILQ_FOREACH(ioh, &io_handlers, next) {
             if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
                 ioh->fd_read(ioh->opaque);
             }
@@ -3860,14 +3856,11 @@ void main_loop_wait(int timeout)
         }

 	/* remove deleted IO handlers */
-	pioh = &first_io_handler;
-	while (*pioh) {
-            ioh = *pioh;
+        QTAILQ_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
             if (ioh->deleted) {
-                *pioh = ioh->next;
+                QTAILQ_REMOVE(&io_handlers, ioh, next);
                 qemu_free(ioh);
-            } else
-                pioh = &ioh->next;
+            }
         }
     }

-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 2/9] Introduce qemu_clear_fd_handler()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 1/9] Convert io handlers to QLIST Juan Quintela
@ 2010-03-09 22:25 ` Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 3/9] Introduce qemu_set_fd_read_handler() Juan Quintela
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel

Patch consist:

s/qemu_set_fd_handler2(fd, NULL, NULL, NULL, NULL)/qemu_clear_fd_handler(fd)/
s/qemu_set_fd_handler(fd, NULL, NULL, NULL)/qemu_clear_fd_handler(fd)/

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 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       |   22 +++++++++++-----------
 qemu-char.h       |    1 +
 usb-linux.c       |    2 +-
 vl.c              |   19 +++++++++++++------
 vnc.c             |    4 ++--
 15 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 88344ff..4259d9c 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_clear_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_clear_fd_handler (pfds[i].fd);
             }
             qemu_free (pfds);
             return -1;
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 42bffae..97e0f1b 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_clear_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_clear_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_clear_fd_handler (oss->fd);
         }
         break;
     }
diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index a2e408f..2eec0c6 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_clear_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 3edc026..7e2ac0e 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -121,7 +121,7 @@ static void exec_accept_incoming_migration(void *opaque)
     qemu_announce_self();
     DPRINTF("successfully loaded vm state\n");
     /* we've successfully migrated, close the fd */
-    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(qemu_stdio_fd(f));
     if (autostart)
         vm_start();

diff --git a/migration-fd.c b/migration-fd.c
index 0cc74ad..056ac3e 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -114,7 +114,7 @@ static void fd_accept_incoming_migration(void *opaque)
     qemu_announce_self();
     DPRINTF("successfully loaded vm state\n");
     /* we've successfully migrated, close the fd */
-    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(qemu_stdio_fd(f));
     if (autostart)
         vm_start();

diff --git a/migration-tcp.c b/migration-tcp.c
index e7f307c..d542804 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_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s->fd);

     if (val == 0)
         migrate_fd_connect(s);
@@ -171,7 +171,7 @@ static void tcp_accept_incoming_migration(void *opaque)
     DPRINTF("successfully loaded vm state\n");

     /* we've successfully migrated, close the server socket */
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s);
     close(s);
     if (autostart)
         vm_start();
diff --git a/migration-unix.c b/migration-unix.c
index b7aab38..44427f8 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_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s->fd);

     if (val == 0)
         migrate_fd_connect(s);
@@ -177,7 +177,7 @@ static void unix_accept_incoming_migration(void *opaque)
     DPRINTF("successfully loaded vm state\n");

     /* we've successfully migrated, close the server socket */
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s);
     close(s);

 out_fopen:
diff --git a/migration.c b/migration.c
index 05f6cc5..787147a 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_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_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_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_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_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s->fd);
     return s->close(s);
 }
diff --git a/net/socket.c b/net/socket.c
index 442a9c7..b7a21f8 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_clear_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_clear_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_clear_fd_handler(s->fd);
     close(s->fd);
 }

diff --git a/net/vde.c b/net/vde.c
index 0b46fa6..fc75e8f 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_clear_fd_handler(vde_datafd(s->vde));
     vde_close(s->vde);
 }

diff --git a/qemu-char.c b/qemu-char.c
index 86c7c5a..a87e4e7 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -560,7 +560,7 @@ static void fd_chr_read(void *opaque)
     size = read(s->fd_in, buf, len);
     if (size == 0) {
         /* FD has been closed. Remove it from the active list.  */
-        qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL);
+        qemu_clear_fd_handler(s->fd_in);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -589,7 +589,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_handler2(s->fd_in, NULL, NULL, NULL, NULL);
+            qemu_clear_fd_handler(s->fd_in);
         }
     }

@@ -689,7 +689,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_handler2(0, NULL, NULL, NULL, NULL);
+        qemu_clear_fd_handler(0);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -745,7 +745,7 @@ static void qemu_chr_close_stdio(struct CharDriverState *chr)
 {
     term_exit();
     stdio_nb_clients--;
-    qemu_set_fd_handler2(0, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(0);
     fd_chr_close(chr);
 }

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

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

-    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_clear_fd_handler(s->fd);
     close(s->fd);
     qemu_del_timer(s->timer);
     qemu_free_timer(s->timer);
@@ -1840,7 +1840,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_clear_fd_handler(s->fd);
         closesocket(s->fd);
     }
     qemu_free(s);
@@ -2050,7 +2050,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_clear_fd_handler(s->fd);
         closesocket(s->fd);
         s->fd = -1;
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
@@ -2134,7 +2134,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_clear_fd_handler(s->listen_fd);
     tcp_chr_connect(chr);
 }

@@ -2142,11 +2142,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_clear_fd_handler(s->fd);
         closesocket(s->fd);
     }
     if (s->listen_fd >= 0) {
-        qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
+        qemu_clear_fd_handler(s->listen_fd);
         closesocket(s->listen_fd);
     }
     qemu_free(s);
diff --git a/qemu-char.h b/qemu-char.h
index bcc0766..23305a8 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -97,6 +97,7 @@ extern int term_escape_char;

 /* async I/O support */

+int qemu_clear_fd_handler(int fd);
 int qemu_set_fd_handler2(int fd,
                          IOCanRWHandler *fd_read_poll,
                          IOHandler *fd_read,
diff --git a/usb-linux.c b/usb-linux.c
index a9c15c6..b7ac3e9 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_clear_fd_handler(dev->fd);
     dev->closing = 1;
     async_complete(dev);
     dev->closing = 0;
diff --git a/vl.c b/vl.c
index 83ff652..2d364bb 100644
--- a/vl.c
+++ b/vl.c
@@ -2603,6 +2603,18 @@ typedef struct IOHandlerRecord {
 static QTAILQ_HEAD(, IOHandlerRecord) io_handlers =
     QTAILQ_HEAD_INITIALIZER(io_handlers);

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

 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */
@@ -2615,12 +2627,7 @@ int qemu_set_fd_handler2(int fd,
     IOHandlerRecord *ioh;

     if (!fd_read && !fd_write) {
-        QTAILQ_FOREACH(ioh, &io_handlers, next) {
-            if (ioh->fd == fd) {
-                ioh->deleted = 1;
-                break;
-            }
-        }
+        qemu_clear_fd_handler(fd);
     } else {
         QTAILQ_FOREACH(ioh, &io_handlers, next) {
             if (ioh->fd == fd)
diff --git a/vnc.c b/vnc.c
index 01353a9..d15a984 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_handler2(vs->csock, NULL, NULL, NULL, NULL);
+    qemu_clear_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_handler2(vs->lsock, NULL, NULL, NULL, NULL);
+        qemu_clear_fd_handler(vs->lsock);
         close(vs->lsock);
         vs->lsock = -1;
     }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 3/9] Introduce qemu_set_fd_read_handler()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 1/9] Convert io handlers to QLIST Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 2/9] Introduce qemu_clear_fd_handler() Juan Quintela
@ 2010-03-09 22:25 ` Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 4/9] Introduce qemu_set_fd_write_handler() Juan Quintela
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel

Patch consist:

s/qemu_set_fd_handler(fd, read, NULL, o)/
  qemu_set_fd_read_handler(fd, read, o)/

s/qemu_set_fd_handler2(fd, NULL, read, NULL, o)/
  qemu_set_fd_read_handler(fd, read, o)/

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 audio/alsaaudio.c   |    4 ++--
 audio/ossaudio.c    |    2 +-
 bt-vhci.c           |    2 +-
 hw/baum.c           |    2 +-
 hw/xen_backend.c    |    6 +++---
 migration-exec.c    |    6 +++---
 migration-fd.c      |    4 ++--
 migration-tcp.c     |    4 ++--
 migration-unix.c    |    4 ++--
 net/socket.c        |    6 +++---
 net/vde.c           |    2 +-
 qemu-char.c         |    4 ++--
 qemu-char.h         |    4 ++++
 vl.c                |   15 +++++++++++++--
 vnc-auth-sasl.c     |    2 +-
 vnc-auth-vencrypt.c |    2 +-
 vnc.c               |    6 +++---
 17 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 4259d9c..2455ee4 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -266,8 +266,8 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)

     for (i = 0; i < count; ++i) {
         if (pfds[i].events & POLLIN) {
-            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,
-                                       NULL, hlp);
+            err = qemu_set_fd_read_handler (pfds[i].fd, alsa_poll_handler,
+                                            hlp);
         }
         if (pfds[i].events & POLLOUT) {
             if (conf.verbose) {
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 97e0f1b..4c91a46 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -153,7 +153,7 @@ static int oss_poll_in (HWVoiceIn *hw)
 {
     OSSVoiceIn *oss = (OSSVoiceIn *) hw;

-    return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
+    return qemu_set_fd_read_handler (oss->fd, oss_helper_poll_in, NULL);
 }

 static int oss_write (SWVoiceOut *sw, void *buf, int len)
diff --git a/bt-vhci.c b/bt-vhci.c
index 679c5e0..2352f1f 100644
--- a/bt-vhci.c
+++ b/bt-vhci.c
@@ -164,5 +164,5 @@ void bt_vhci_init(struct HCIInfo *info)
     s->info->evt_recv = vhci_out_hci_packet_event;
     s->info->acl_recv = vhci_out_hci_packet_acl;

-    qemu_set_fd_handler(s->fd, vhci_read, NULL, s);
+    qemu_set_fd_read_handler(s->fd, vhci_read, s);
 }
diff --git a/hw/baum.c b/hw/baum.c
index 18633f4..c856939 100644
--- a/hw/baum.c
+++ b/hw/baum.c
@@ -612,7 +612,7 @@ CharDriverState *chr_baum_init(QemuOpts *opts)
         goto fail;
     }

-    qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
+    qemu_set_fd_read_handler(baum->brlapi_fd, baum_chr_read, baum);

     qemu_chr_generic_open(chr);

diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index 2eec0c6..a86e92f 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -624,7 +624,7 @@ int xen_be_init(void)
 	return -1;
     }

-    if (qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL) < 0)
+    if (qemu_set_fd_read_handler(xs_fileno(xenstore), xenstore_update, NULL) < 0)
 	goto err;

     xen_xc = xc_interface_open();
@@ -658,8 +658,8 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
 	return -1;
     }
     xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
-    qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev),
-			xen_be_evtchn_event, NULL, xendev);
+    qemu_set_fd_read_handler(xc_evtchn_fd(xendev->evtchndev),
+                             xen_be_evtchn_event, xendev);
     return 0;
 }

diff --git a/migration-exec.c b/migration-exec.c
index 7e2ac0e..76518a6 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -140,9 +140,9 @@ int exec_start_incoming_migration(const char *command)
         return -errno;
     }

-    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL,
-			 exec_accept_incoming_migration, NULL,
-			 (void *)(unsigned long)f);
+    qemu_set_fd_read_handler(qemu_stdio_fd(f),
+                             exec_accept_incoming_migration,
+                             (void *)(unsigned long)f);

     return 0;
 }
diff --git a/migration-fd.c b/migration-fd.c
index 056ac3e..8a4c2b8 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -136,8 +136,8 @@ int fd_start_incoming_migration(const char *infd)
         return -errno;
     }

-    qemu_set_fd_handler2(fd, NULL, fd_accept_incoming_migration, NULL,
-			 (void *)(unsigned long)f);
+    qemu_set_fd_read_handler(fd, fd_accept_incoming_migration,
+                             (void *)(unsigned long)f);

     return 0;
 }
diff --git a/migration-tcp.c b/migration-tcp.c
index d542804..66f126f 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -206,8 +206,8 @@ int tcp_start_incoming_migration(const char *host_port)
     if (listen(s, 1) == -1)
         goto err;

-    qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
-                         (void *)(unsigned long)s);
+    qemu_set_fd_read_handler(s, tcp_accept_incoming_migration,
+                             (void *)(unsigned long)s);

     return 0;

diff --git a/migration-unix.c b/migration-unix.c
index 44427f8..fe9a820 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -213,8 +213,8 @@ int unix_start_incoming_migration(const char *path)
         goto err;
     }

-    qemu_set_fd_handler2(sock, NULL, unix_accept_incoming_migration, NULL,
-			 (void *)(unsigned long)sock);
+    qemu_set_fd_read_handler(sock, unix_accept_incoming_migration,
+                             (void *)(unsigned long)sock);

     return 0;

diff --git a/net/socket.c b/net/socket.c
index b7a21f8..5772202 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -276,7 +276,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,

     s->fd = fd;

-    qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
+    qemu_set_fd_read_handler(s->fd, net_socket_send_dgram, s);

     /* mcast: save bound address as dst */
     if (is_connected) s->dgram_dst=saddr;
@@ -287,7 +287,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
 static void net_socket_connect(void *opaque)
 {
     NetSocketState *s = opaque;
-    qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
+    qemu_set_fd_read_handler(s->fd, net_socket_send, s);
 }

 static NetClientInfo net_socket_info = {
@@ -411,7 +411,7 @@ static int net_socket_listen_init(VLANState *vlan,
     s->model = qemu_strdup(model);
     s->name = name ? qemu_strdup(name) : NULL;
     s->fd = fd;
-    qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
+    qemu_set_fd_read_handler(fd, net_socket_accept, s);
     return 0;
 }

diff --git a/net/vde.c b/net/vde.c
index fc75e8f..a99dcdf 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -106,7 +106,7 @@ static int net_vde_init(VLANState *vlan, const char *model,

     s->vde = vde;

-    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
+    qemu_set_fd_read_handler(vde_datafd(s->vde), vde_to_qemu, s);

     return 0;
 }
diff --git a/qemu-char.c b/qemu-char.c
index a87e4e7..43d0758 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2048,7 +2048,7 @@ static void tcp_chr_read(void *opaque)
         /* connection closed */
         s->connected = 0;
         if (s->listen_fd >= 0) {
-            qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
+            qemu_set_fd_read_handler(s->listen_fd, tcp_chr_accept, chr);
         }
         qemu_clear_fd_handler(s->fd);
         closesocket(s->fd);
@@ -2208,7 +2208,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)

     if (is_listen) {
         s->listen_fd = fd;
-        qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
+        qemu_set_fd_read_handler(s->listen_fd, tcp_chr_accept, chr);
         if (is_telnet)
             s->do_telnetopt = 1;

diff --git a/qemu-char.h b/qemu-char.h
index 23305a8..70e4bf9 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -107,5 +107,9 @@ int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
                         IOHandler *fd_write,
                         void *opaque);
+int qemu_set_fd_read_handler(int fd,
+                             IOHandler *fd_read,
+                             void *opaque);
+

 #endif
diff --git a/vl.c b/vl.c
index 2d364bb..c855167 100644
--- a/vl.c
+++ b/vl.c
@@ -2654,6 +2654,17 @@ int qemu_set_fd_handler(int fd,
     return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }

+int qemu_set_fd_read_handler(int fd,
+                             IOHandler *fd_read,
+                             void *opaque)
+{
+    if(fd_read == NULL) {
+        fprintf(stderr, "qemu_set_fd_read_handler: NULL read handler\n");
+        exit(1);
+    }
+    return qemu_set_fd_handler2(fd, NULL, fd_read, NULL, opaque);
+}
+
 #ifdef _WIN32
 /***********************************************************/
 /* Polling handling */
@@ -3259,8 +3270,8 @@ static int qemu_event_init(void)
     if (err < 0)
         goto fail;

-    qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
-                         (void *)(unsigned long)fds[0]);
+    qemu_set_fd_read_handler(fds[0], qemu_event_read,
+                             (void *)(unsigned long)fds[0]);

     io_thread_fd = fds[1];
     return 0;
diff --git a/vnc-auth-sasl.c b/vnc-auth-sasl.c
index acaac0c..5b2dd47 100644
--- a/vnc-auth-sasl.c
+++ b/vnc-auth-sasl.c
@@ -83,7 +83,7 @@ long vnc_client_write_sasl(VncState *vs)
      * SASL encoded output
      */
     if (vs->output.offset == 0) {
-        qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+        qemu_set_fd_read_handler(vs->csock, vnc_client_read, vs);
     }

     return ret;
diff --git a/vnc-auth-vencrypt.c b/vnc-auth-vencrypt.c
index 07c1691..2999c2d 100644
--- a/vnc-auth-vencrypt.c
+++ b/vnc-auth-vencrypt.c
@@ -71,7 +71,7 @@ static int vnc_start_vencrypt_handshake(struct VncState *vs) {
        if (!gnutls_error_is_fatal(ret)) {
            VNC_DEBUG("Handshake interrupted (blocking)\n");
            if (!gnutls_record_get_direction(vs->tls.session))
-               qemu_set_fd_handler(vs->csock, vnc_tls_handshake_io, NULL, vs);
+               qemu_set_fd_read_handler(vs->csock, vnc_tls_handshake_io, vs);
            else
                qemu_set_fd_handler(vs->csock, NULL, vnc_tls_handshake_io, vs);
            return 0;
diff --git a/vnc.c b/vnc.c
index d15a984..2634dc8 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1218,7 +1218,7 @@ static long vnc_client_write_plain(VncState *vs)
     vs->output.offset -= ret;

     if (vs->output.offset == 0) {
-        qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+        qemu_set_fd_read_handler(vs->csock, vnc_client_read, vs);
     }

     return ret;
@@ -2389,7 +2389,7 @@ static void vnc_connect(VncDisplay *vd, int csock)
     VNC_DEBUG("New client on socket %d\n", csock);
     dcl->idle = 0;
     socket_set_nonblock(vs->csock);
-    qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+    qemu_set_fd_read_handler(vs->csock, vnc_client_read, vs);

     vnc_client_cache_addr(vs);
     vnc_qmp_event(vs, QEVENT_VNC_CONNECTED);
@@ -2730,5 +2730,5 @@ int vnc_display_open(DisplayState *ds, const char *display)
             vs->display = dpy;
         }
     }
-    return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
+    return qemu_set_fd_read_handler(vs->lsock, vnc_listen_read, vs);
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 4/9] Introduce qemu_set_fd_write_handler()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (2 preceding siblings ...)
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 3/9] Introduce qemu_set_fd_read_handler() Juan Quintela
@ 2010-03-09 22:25 ` Juan Quintela
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 5/9] Introduce qemu_set_fd_rw_handler() Juan Quintela
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel

Patch consist:

    s/qemu_set_fd_handler(fd, NULL, write, o)/
      qemu_set_fd_write_handler(fd, write, o)/

    s/qemu_set_fd_handler2(fd, NULL, NULL, write, o)/
      qemu_set_fd_write_handler(fd, write, o)/

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 audio/alsaaudio.c   |    4 ++--
 audio/ossaudio.c    |    2 +-
 migration-tcp.c     |    2 +-
 migration-unix.c    |    2 +-
 migration.c         |    2 +-
 net/socket.c        |    2 +-
 qemu-char.h         |    4 +++-
 usb-linux.c         |    2 +-
 vl.c                |   11 +++++++++++
 vnc-auth-vencrypt.c |    2 +-
 10 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 2455ee4..894f02b 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -273,8 +273,8 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
             if (conf.verbose) {
                 dolog ("POLLOUT %d %d\n", i, pfds[i].fd);
             }
-            err = qemu_set_fd_handler (pfds[i].fd, NULL,
-                                       alsa_poll_handler, hlp);
+            err = qemu_set_fd_write_handler (pfds[i].fd, alsa_poll_handler,
+                                             hlp);
         }
         if (conf.verbose) {
             dolog ("Set handler events=%#x index=%d fd=%d err=%d\n",
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 4c91a46..4d0cd36 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -146,7 +146,7 @@ static int oss_poll_out (HWVoiceOut *hw)
 {
     OSSVoiceOut *oss = (OSSVoiceOut *) hw;

-    return qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
+    return qemu_set_fd_write_handler (oss->fd, oss_helper_poll_out, NULL);
 }

 static int oss_poll_in (HWVoiceIn *hw)
diff --git a/migration-tcp.c b/migration-tcp.c
index 66f126f..c141322 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -123,7 +123,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
             ret = -(s->get_error(s));

         if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
-            qemu_set_fd_handler2(s->fd, NULL, NULL, tcp_wait_for_connect, s);
+            qemu_set_fd_write_handler(s->fd, tcp_wait_for_connect, s);
     } while (ret == -EINTR);

     if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
diff --git a/migration-unix.c b/migration-unix.c
index fe9a820..b50ccb2 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -118,7 +118,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
 	    ret = -(s->get_error(s));

         if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
-	    qemu_set_fd_handler2(s->fd, NULL, NULL, unix_wait_for_connect, s);
+	    qemu_set_fd_write_handler(s->fd, unix_wait_for_connect, s);
     } while (ret == -EINTR);

     if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
diff --git a/migration.c b/migration.c
index 787147a..c310e4b 100644
--- a/migration.c
+++ b/migration.c
@@ -332,7 +332,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
         ret = -(s->get_error(s));

     if (ret == -EAGAIN)
-        qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
+        qemu_set_fd_write_handler(s->fd, migrate_fd_put_notify, s);

     return ret;
 }
diff --git a/net/socket.c b/net/socket.c
index 5772202..e746b19 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -316,7 +316,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
     if (is_connected) {
         net_socket_connect(s);
     } else {
-        qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
+        qemu_set_fd_write_handler(s->fd, net_socket_connect, s);
     }
     return s;
 }
diff --git a/qemu-char.h b/qemu-char.h
index 70e4bf9..76cacd9 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -110,6 +110,8 @@ int qemu_set_fd_handler(int fd,
 int qemu_set_fd_read_handler(int fd,
                              IOHandler *fd_read,
                              void *opaque);
-
+int qemu_set_fd_write_handler(int fd,
+                              IOHandler *fd_read,
+                              void *opaque);

 #endif
diff --git a/usb-linux.c b/usb-linux.c
index b7ac3e9..9c871ce 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -940,7 +940,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
                 prod_name);

     /* USB devio uses 'write' flag to check for async completions */
-    qemu_set_fd_handler(dev->fd, NULL, async_complete, dev);
+    qemu_set_fd_write_handler(dev->fd, async_complete, dev);

     usb_device_attach(&dev->dev);
     return 0;
diff --git a/vl.c b/vl.c
index c855167..6e75347 100644
--- a/vl.c
+++ b/vl.c
@@ -2665,6 +2665,17 @@ int qemu_set_fd_read_handler(int fd,
     return qemu_set_fd_handler2(fd, NULL, fd_read, NULL, opaque);
 }

+int qemu_set_fd_write_handler(int fd,
+                              IOHandler *fd_write,
+                              void *opaque)
+{
+    if(fd_write == NULL) {
+        fprintf(stderr, "qemu_set_fd_write_handler: NULL write handler\n");
+        exit(1);
+    }
+    return qemu_set_fd_handler2(fd, NULL, NULL, fd_write, opaque);
+}
+
 #ifdef _WIN32
 /***********************************************************/
 /* Polling handling */
diff --git a/vnc-auth-vencrypt.c b/vnc-auth-vencrypt.c
index 2999c2d..7b3fd57 100644
--- a/vnc-auth-vencrypt.c
+++ b/vnc-auth-vencrypt.c
@@ -73,7 +73,7 @@ static int vnc_start_vencrypt_handshake(struct VncState *vs) {
            if (!gnutls_record_get_direction(vs->tls.session))
                qemu_set_fd_read_handler(vs->csock, vnc_tls_handshake_io, vs);
            else
-               qemu_set_fd_handler(vs->csock, NULL, vnc_tls_handshake_io, vs);
+               qemu_set_fd_write_handler(vs->csock, vnc_tls_handshake_io, vs);
            return 0;
        }
        VNC_DEBUG("Handshake failed %s\n", gnutls_strerror(ret));
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 5/9] Introduce qemu_set_fd_rw_handler()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (3 preceding siblings ...)
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 4/9] Introduce qemu_set_fd_write_handler() Juan Quintela
@ 2010-03-09 22:25 ` Juan Quintela
  2010-03-09 22:41   ` [Qemu-devel] " Juan Quintela
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 6/9] bt: remove bt_host_read_poll() Juan Quintela
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:25 UTC (permalink / raw)
  To: qemu-devel

Patch consist:

s/qemu_set_fd_handler(fd, read, write, o)/
  qemu_set_fd_rw_handler(fd, read, write, o)/

s/qemu_set_fd_handler2(fd, NULL, read, write, o)/
  qemu_set_fd_rw_handler(fd, read, write, o)/

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 aio.c               |    2 +-
 qemu-aio.h          |    4 ++--
 qemu-char.h         |    8 ++++----
 qemu-tool.c         |    9 ++++-----
 vl.c                |   16 ++++++++++++----
 vnc-auth-vencrypt.c |    2 +-
 vnc.c               |    2 +-
 7 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/aio.c b/aio.c
index f164a47..4185233 100644
--- a/aio.c
+++ b/aio.c
@@ -93,7 +93,7 @@ int qemu_aio_set_fd_handler(int fd,
         node->opaque = opaque;
     }

-    qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
+    qemu_set_fd_rw_handler(fd, io_read, io_write, opaque);

     return 0;
 }
diff --git a/qemu-aio.h b/qemu-aio.h
index 3bdd749..1d2b423 100644
--- a/qemu-aio.h
+++ b/qemu-aio.h
@@ -43,11 +43,11 @@ void qemu_aio_wait(void);
 int qemu_aio_process_queue(void);

 /* Register a file descriptor and associated callbacks.  Behaves very similarly
- * to qemu_set_fd_handler2.  Unlike qemu_set_fd_handler2, these callbacks will
+ * to qemu_set_fd_rw_handler.  Unlike qemu_set_fd_rw_handler, these callbacks will
  * be invoked when using either qemu_aio_wait() or qemu_aio_flush().
  *
  * Code that invokes AIO completion functions should rely on this function
- * instead of qemu_set_fd_handler[2].
+ * instead of qemu_set_fd_rw_handler.
  */
 int qemu_aio_set_fd_handler(int fd,
                             IOHandler *io_read,
diff --git a/qemu-char.h b/qemu-char.h
index 76cacd9..8d7da54 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -103,10 +103,10 @@ int qemu_set_fd_handler2(int fd,
                          IOHandler *fd_read,
                          IOHandler *fd_write,
                          void *opaque);
-int qemu_set_fd_handler(int fd,
-                        IOHandler *fd_read,
-                        IOHandler *fd_write,
-                        void *opaque);
+int qemu_set_fd_rw_handler(int fd,
+                           IOHandler *fd_read,
+                           IOHandler *fd_write,
+                           void *opaque);
 int qemu_set_fd_read_handler(int fd,
                              IOHandler *fd_read,
                              void *opaque);
diff --git a/qemu-tool.c b/qemu-tool.c
index 18b48af..25d644f 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -90,11 +90,10 @@ void qemu_bh_delete(QEMUBH *bh)
     qemu_free(bh);
 }

-int qemu_set_fd_handler2(int fd,
-                         IOCanRWHandler *fd_read_poll,
-                         IOHandler *fd_read,
-                         IOHandler *fd_write,
-                         void *opaque)
+int qemu_set_fd_rw_handler(int fd,
+                           IOHandler *fd_read,
+                           IOHandler *fd_write,
+                           void *opaque)
 {
     return 0;
 }
diff --git a/vl.c b/vl.c
index 6e75347..c061732 100644
--- a/vl.c
+++ b/vl.c
@@ -2646,11 +2646,19 @@ int qemu_set_fd_handler2(int fd,
     return 0;
 }

-int qemu_set_fd_handler(int fd,
-                        IOHandler *fd_read,
-                        IOHandler *fd_write,
-                        void *opaque)
+int qemu_set_fd_rw_handler(int fd,
+                           IOHandler *fd_read,
+                           IOHandler *fd_write,
+                           void *opaque)
 {
+    if(fd_read == NULL) {
+        fprintf(stderr, "qemu_set_fd_rw_handler: NULL read handler\n");
+        exit(1);
+    }
+    if(fd_write == NULL) {
+        fprintf(stderr, "qemu_set_fd_rw_handler: NULL write handler\n");
+        exit(1);
+    }
     return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }

diff --git a/vnc-auth-vencrypt.c b/vnc-auth-vencrypt.c
index 7b3fd57..22f5980 100644
--- a/vnc-auth-vencrypt.c
+++ b/vnc-auth-vencrypt.c
@@ -93,7 +93,7 @@ static int vnc_start_vencrypt_handshake(struct VncState *vs) {

     VNC_DEBUG("Handshake done, switching to TLS data mode\n");
     vs->tls.wiremode = VNC_WIREMODE_TLS;
-    qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
+    qemu_set_fd_rw_handler(vs->csock, vnc_client_read, vnc_client_write, vs);

     start_auth_vencrypt_subauth(vs);

diff --git a/vnc.c b/vnc.c
index 2634dc8..c945cb9 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1356,7 +1356,7 @@ void vnc_write(VncState *vs, const void *data, size_t len)
     buffer_reserve(&vs->output, len);

     if (vs->csock != -1 && buffer_empty(&vs->output)) {
-        qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
+        qemu_set_fd_rw_handler(vs->csock, vnc_client_read, vnc_client_write, vs);
     }

     buffer_append(&vs->output, data, len);
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 6/9] bt: remove bt_host_read_poll()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (4 preceding siblings ...)
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 5/9] Introduce qemu_set_fd_rw_handler() Juan Quintela
@ 2010-03-09 22:26 ` Juan Quintela
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 7/9] Introduce qemu_set_fd_poll_handler() Juan Quintela
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:26 UTC (permalink / raw)
  To: qemu-devel

It allways returned true, that is the equivalent of not having the
callback.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 bt-host.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/bt-host.c b/bt-host.c
index 964ac11..dcd302b 100644
--- a/bt-host.c
+++ b/bt-host.c
@@ -80,13 +80,6 @@ static void bt_host_sco(struct HCIInfo *hci, const uint8_t *data, int len)
     bt_host_send(hci, HCI_SCODATA_PKT, data, len);
 }

-static int bt_host_read_poll(void *opaque)
-{
-    struct bt_host_hci_s *s = (struct bt_host_hci_s *) opaque;
-
-    return !!s->hci.evt_recv;
-}
-
 static void bt_host_read(void *opaque)
 {
     struct bt_host_hci_s *s = (struct bt_host_hci_s *) opaque;
@@ -192,7 +185,7 @@ struct HCIInfo *bt_host_hci(const char *id)
     s->hci.acl_send = bt_host_acl;
     s->hci.bdaddr_set = bt_host_bdaddr_set;

-    qemu_set_fd_handler2(s->fd, bt_host_read_poll, bt_host_read, NULL, s);
+    qemu_set_fd_read_handler(s->fd, bt_host_read, s);

     return &s->hci;
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 7/9] Introduce qemu_set_fd_poll_handler()
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (5 preceding siblings ...)
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 6/9] bt: remove bt_host_read_poll() Juan Quintela
@ 2010-03-09 22:26 ` Juan Quintela
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 8/9] remove useless cast Juan Quintela
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:26 UTC (permalink / raw)
  To: qemu-devel

Patch consist:

     s/qemu_set_fd_handler2(fd, poll, read, NULL, o)/
      qemu_set_fd_poll_handler(fd, poll, read, o)/

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   18 +++++++++---------
 qemu-char.h |    4 ++++
 vl.c        |   16 ++++++++++++++++
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 43d0758..4822209 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -576,8 +576,8 @@ static void fd_chr_update_read_handler(CharDriverState *chr)
     if (s->fd_in >= 0) {
         if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
         } else {
-            qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll,
-                                 fd_chr_read, NULL, chr);
+            qemu_set_fd_poll_handler(s->fd_in, fd_chr_read_poll,
+                                     fd_chr_read, chr);
         }
     }
 }
@@ -757,7 +757,7 @@ static CharDriverState *qemu_chr_open_stdio(QemuOpts *opts)
         return NULL;
     chr = qemu_chr_open_fd(0, 1);
     chr->chr_close = qemu_chr_close_stdio;
-    qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr);
+    qemu_set_fd_poll_handler(0, stdio_read_poll, stdio_read, chr);
     stdio_nb_clients++;
     term_init(opts);

@@ -885,8 +885,8 @@ static void pty_chr_update_read_handler(CharDriverState *chr)
 {
     PtyCharDriver *s = chr->opaque;

-    qemu_set_fd_handler2(s->fd, pty_chr_read_poll,
-                         pty_chr_read, NULL, chr);
+    qemu_set_fd_poll_handler(s->fd, pty_chr_read_poll,
+                             pty_chr_read, chr);
     s->polling = 1;
     /*
      * Short timeout here: just need wait long enougth that qemu makes
@@ -1831,8 +1831,8 @@ static void udp_chr_update_read_handler(CharDriverState *chr)
     NetCharDriver *s = chr->opaque;

     if (s->fd >= 0) {
-        qemu_set_fd_handler2(s->fd, udp_chr_read_poll,
-                             udp_chr_read, NULL, chr);
+        qemu_set_fd_poll_handler(s->fd, udp_chr_read_poll,
+                                 udp_chr_read, chr);
     }
 }

@@ -2072,8 +2072,8 @@ static void tcp_chr_connect(void *opaque)
     TCPCharDriver *s = chr->opaque;

     s->connected = 1;
-    qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
-                         tcp_chr_read, NULL, chr);
+    qemu_set_fd_poll_handler(s->fd, tcp_chr_read_poll,
+                             tcp_chr_read, chr);
     qemu_chr_generic_open(chr);
 }

diff --git a/qemu-char.h b/qemu-char.h
index 8d7da54..ffc6cb6 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -113,5 +113,9 @@ int qemu_set_fd_read_handler(int fd,
 int qemu_set_fd_write_handler(int fd,
                               IOHandler *fd_read,
                               void *opaque);
+int qemu_set_fd_poll_handler(int fd,
+                             IOCanRWHandler *fd_read_poll,
+                             IOHandler *fd_read,
+                             void *opaque);

 #endif
diff --git a/vl.c b/vl.c
index c061732..2cb35dc 100644
--- a/vl.c
+++ b/vl.c
@@ -2684,6 +2684,22 @@ int qemu_set_fd_write_handler(int fd,
     return qemu_set_fd_handler2(fd, NULL, NULL, fd_write, opaque);
 }

+int qemu_set_fd_poll_handler(int fd,
+                             IOCanRWHandler *fd_read_poll,
+                             IOHandler *fd_read,
+                             void *opaque)
+{
+    if(fd_read_poll == NULL) {
+        fprintf(stderr, "qemu_set_fd_poll_handler: NULL poll handler\n");
+        exit(1);
+    }
+    if(fd_read == NULL) {
+        fprintf(stderr, "qemu_set_fd_poll_handler: NULL read handler\n");
+        exit(1);
+    }
+    return qemu_set_fd_handler2(fd, fd_read_poll, fd_read, NULL, opaque);
+}
+
 #ifdef _WIN32
 /***********************************************************/
 /* Polling handling */
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 8/9] remove useless cast
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (6 preceding siblings ...)
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 7/9] Introduce qemu_set_fd_poll_handler() Juan Quintela
@ 2010-03-09 22:26 ` Juan Quintela
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 9/9] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
  2010-03-09 23:53 ` [Qemu-devel] [PATCH 0/9] Clear fd handlers malc
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:26 UTC (permalink / raw)
  To: qemu-devel

values are alread pointers, no need to cast them to void *

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration-exec.c |    2 +-
 migration-fd.c   |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 76518a6..fddbd70 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -142,7 +142,7 @@ int exec_start_incoming_migration(const char *command)

     qemu_set_fd_read_handler(qemu_stdio_fd(f),
                              exec_accept_incoming_migration,
-                             (void *)(unsigned long)f);
+                             f);

     return 0;
 }
diff --git a/migration-fd.c b/migration-fd.c
index 8a4c2b8..e683a82 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -136,8 +136,7 @@ int fd_start_incoming_migration(const char *infd)
         return -errno;
     }

-    qemu_set_fd_read_handler(fd, fd_accept_incoming_migration,
-                             (void *)(unsigned long)f);
+    qemu_set_fd_read_handler(fd, fd_accept_incoming_migration, f);

     return 0;
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 9/9] rename IOCanRWHandler to IOCanReadHandler
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (7 preceding siblings ...)
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 8/9] remove useless cast Juan Quintela
@ 2010-03-09 22:26 ` Juan Quintela
  2010-03-09 23:53 ` [Qemu-devel] [PATCH 0/9] Clear fd handlers malc
  9 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:26 UTC (permalink / raw)
  To: qemu-devel

It was always only used for reads

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c   |    4 ++--
 qemu-char.h   |    8 ++++----
 qemu-common.h |    2 +-
 vl.c          |    6 +++---
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 4822209..5d8043a 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -182,7 +182,7 @@ void qemu_chr_send_event(CharDriverState *s, int event)
 }

 void qemu_chr_add_handlers(CharDriverState *s,
-                           IOCanRWHandler *fd_can_read,
+                           IOCanReadHandler *fd_can_read,
                            IOReadHandler *fd_read,
                            IOEventHandler *fd_event,
                            void *opaque)
@@ -214,7 +214,7 @@ static CharDriverState *qemu_chr_open_null(QemuOpts *opts)
 #define MUX_BUFFER_SIZE 32	/* Must be a power of 2.  */
 #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1)
 typedef struct {
-    IOCanRWHandler *chr_can_read[MAX_MUX];
+    IOCanReadHandler *chr_can_read[MAX_MUX];
     IOReadHandler *chr_read[MAX_MUX];
     IOEventHandler *chr_event[MAX_MUX];
     void *ext_opaque[MAX_MUX];
diff --git a/qemu-char.h b/qemu-char.h
index ffc6cb6..9519332 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -57,7 +57,7 @@ struct CharDriverState {
     int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
     int (*get_msgfd)(struct CharDriverState *s);
     IOEventHandler *chr_event;
-    IOCanRWHandler *chr_can_read;
+    IOCanReadHandler *chr_can_read;
     IOReadHandler *chr_read;
     void *handler_opaque;
     void (*chr_send_event)(struct CharDriverState *chr, int event);
@@ -79,7 +79,7 @@ void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
 void qemu_chr_send_event(CharDriverState *s, int event);
 void qemu_chr_add_handlers(CharDriverState *s,
-                           IOCanRWHandler *fd_can_read,
+                           IOCanReadHandler *fd_can_read,
                            IOReadHandler *fd_read,
                            IOEventHandler *fd_event,
                            void *opaque);
@@ -99,7 +99,7 @@ extern int term_escape_char;

 int qemu_clear_fd_handler(int fd);
 int qemu_set_fd_handler2(int fd,
-                         IOCanRWHandler *fd_read_poll,
+                         IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,
                          IOHandler *fd_write,
                          void *opaque);
@@ -114,7 +114,7 @@ int qemu_set_fd_write_handler(int fd,
                               IOHandler *fd_read,
                               void *opaque);
 int qemu_set_fd_poll_handler(int fd,
-                             IOCanRWHandler *fd_read_poll,
+                             IOCanReadHandler *fd_read_poll,
                              IOHandler *fd_read,
                              void *opaque);

diff --git a/qemu-common.h b/qemu-common.h
index 805be1a..42bfbcd 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -183,7 +183,7 @@ void QEMU_NORETURN hw_error(const char *fmt, ...)

 /* IO callbacks.  */
 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
-typedef int IOCanRWHandler(void *opaque);
+typedef int IOCanReadHandler(void *opaque);
 typedef void IOHandler(void *opaque);

 struct ParallelIOArg {
diff --git a/vl.c b/vl.c
index 2cb35dc..d774d39 100644
--- a/vl.c
+++ b/vl.c
@@ -2590,7 +2590,7 @@ void pcmcia_info(Monitor *mon)

 typedef struct IOHandlerRecord {
     int fd;
-    IOCanRWHandler *fd_read_poll;
+    IOCanReadHandler *fd_read_poll;
     IOHandler *fd_read;
     IOHandler *fd_write;
     int deleted;
@@ -2619,7 +2619,7 @@ int qemu_clear_fd_handler(int fd)
 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */
 int qemu_set_fd_handler2(int fd,
-                         IOCanRWHandler *fd_read_poll,
+                         IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,
                          IOHandler *fd_write,
                          void *opaque)
@@ -2685,7 +2685,7 @@ int qemu_set_fd_write_handler(int fd,
 }

 int qemu_set_fd_poll_handler(int fd,
-                             IOCanRWHandler *fd_read_poll,
+                             IOCanReadHandler *fd_read_poll,
                              IOHandler *fd_read,
                              void *opaque)
 {
-- 
1.6.6.1

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

* [Qemu-devel] Re: [PATCH 5/9] Introduce qemu_set_fd_rw_handler()
  2010-03-09 22:25 ` [Qemu-devel] [PATCH 5/9] Introduce qemu_set_fd_rw_handler() Juan Quintela
@ 2010-03-09 22:41   ` Juan Quintela
  0 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-09 22:41 UTC (permalink / raw)
  To: qemu-devel

Juan Quintela <quintela@redhat.com> wrote:
> Patch consist:
> diff --git a/aio.c b/aio.c
> index f164a47..4185233 100644
> --- a/aio.c
> +++ b/aio.c
> @@ -93,7 +93,7 @@ int qemu_aio_set_fd_handler(int fd,
>          node->opaque = opaque;
>      }
>
> -    qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
> +    qemu_set_fd_rw_handler(fd, io_read, io_write, opaque);
>
>      return 0;
>  }

NACK myself.  Sorry, this one can't be changed, aio_set_fd_handler() is
still called with NULL's.

Sorry, please review rest.

Later, Juan.

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

* Re: [Qemu-devel] [PATCH 0/9] Clear fd handlers
  2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
                   ` (8 preceding siblings ...)
  2010-03-09 22:26 ` [Qemu-devel] [PATCH 9/9] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
@ 2010-03-09 23:53 ` malc
  2010-03-09 23:58   ` Anthony Liguori
  9 siblings, 1 reply; 14+ messages in thread
From: malc @ 2010-03-09 23:53 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Tue, 9 Mar 2010, Juan Quintela wrote:

> Hi
> 
> This series :
> - convert io_handlers to one QLIST
> - once there, qemu_set_fd_handlers2() has lots of arguments that are a lot of times NULL.
>   Introduce a set of functions to not have to pass NULL values.
>  - qemu_clear_fd_handlers(): remove it
>  - qemu_set_fd_read_handler(): only read
>  - qemu_set_fd_write_handler(): only write
>  - qemu_set_fd_rw_handler(): read/write
>  - qemu_set_fd_poll_handler(): it was only used for reads and in qemu-char.c.
> 
> - once there fix bt that don't need poll at all (having a poll function that always return true
>   is the equivalent of not having one).
> - remove cast to (void *)(unsigned long) for things that already were pointers
> - IOCanRWHandler is only used for reads -> rename it (almost no users).
> 
> ToDo:
> - to remove the export of qemu_set_fd_handlers2() we need a solution for tap.
>   Tap is the only user in qemu that uses poll, read and write, and it changes in very imaginative
>   ways:
>     qemu_set_fd_handler2(s->fd,
>                          s->read_poll  ? tap_can_send : NULL,
>                          s->read_poll  ? tap_send     : NULL,
>                          s->write_poll ? tap_writable : NULL,
>                          s);
> 
>   No ideas about how to transform this into something that don't use NULL's in any of its fields
>   other than a row of if's.
> 
> - removal of poll function. comment of qemu_set_fd_handler2()
>   /* XXX: fd_read_poll should be suppressed, but an API change is
>     necessary in the character devices to suppress fd_can_read(). */
> 
>   But qemu-char.c is a complex beast, and would preffer to 1st get this patches in, and then
>   work on the other stuff.
> 
> - obvious optimization now is to have the FD_SET() for write/read already filled, but I
>   haven't done any meassurement.
> 
> Comments?
> 
> Juan Quintela (9):
>   Convert io handlers to QLIST
>   Introduce qemu_clear_fd_handler()
>   Introduce qemu_set_fd_read_handler()
>   Introduce qemu_set_fd_write_handler()
>   Introduce qemu_set_fd_rw_handler()
>   bt: remove bt_host_read_poll()
>   Introduce qemu_set_fd_poll_handler()
>   remove useless cast
>   rename IOCanRWHandler to IOCanReadHandler
> 
>  aio.c               |    2 +-
>  audio/alsaaudio.c   |   12 +++---
>  audio/ossaudio.c    |   10 ++--
>  bt-host.c           |    9 +----
>  bt-vhci.c           |    2 +-
>  hw/baum.c           |    2 +-
>  hw/xen_backend.c    |   10 ++--
>  migration-exec.c    |    8 ++--
>  migration-fd.c      |    5 +-
>  migration-tcp.c     |   10 ++--
>  migration-unix.c    |   10 ++--
>  migration.c         |    8 ++--
>  net/socket.c        |   14 +++---
>  net/vde.c           |    4 +-
>  qemu-aio.h          |    4 +-
>  qemu-char.c         |   48 +++++++++++-----------
>  qemu-char.h         |   25 ++++++++---
>  qemu-common.h       |    2 +-
>  qemu-tool.c         |    9 ++--
>  usb-linux.c         |    4 +-
>  vl.c                |  114 +++++++++++++++++++++++++++++++++++---------------
>  vnc-auth-sasl.c     |    2 +-
>  vnc-auth-vencrypt.c |    6 +-
>  vnc.c               |   12 +++---
>  24 files changed, 190 insertions(+), 142 deletions(-)

What's the point if it ends up adding 48 lines of code?

-- 
mailto:av1474@comtv.ru

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

* Re: [Qemu-devel] [PATCH 0/9] Clear fd handlers
  2010-03-09 23:53 ` [Qemu-devel] [PATCH 0/9] Clear fd handlers malc
@ 2010-03-09 23:58   ` Anthony Liguori
  2010-03-10  0:12     ` [Qemu-devel] " Juan Quintela
  0 siblings, 1 reply; 14+ messages in thread
From: Anthony Liguori @ 2010-03-09 23:58 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel, Juan Quintela

On 03/09/2010 05:53 PM, malc wrote:
> On Tue, 9 Mar 2010, Juan Quintela wrote:
>
>    
>> Hi
>>
>> This series :
>> - convert io_handlers to one QLIST
>> - once there, qemu_set_fd_handlers2() has lots of arguments that are a lot of times NULL.
>>    Introduce a set of functions to not have to pass NULL values.
>>   - qemu_clear_fd_handlers(): remove it
>>   - qemu_set_fd_read_handler(): only read
>>   - qemu_set_fd_write_handler(): only write
>>   - qemu_set_fd_rw_handler(): read/write
>>   - qemu_set_fd_poll_handler(): it was only used for reads and in qemu-char.c.
>>
>> - once there fix bt that don't need poll at all (having a poll function that always return true
>>    is the equivalent of not having one).
>> - remove cast to (void *)(unsigned long) for things that already were pointers
>> - IOCanRWHandler is only used for reads ->  rename it (almost no users).
>>
>> ToDo:
>> - to remove the export of qemu_set_fd_handlers2() we need a solution for tap.
>>    Tap is the only user in qemu that uses poll, read and write, and it changes in very imaginative
>>    ways:
>>      qemu_set_fd_handler2(s->fd,
>>                           s->read_poll  ? tap_can_send : NULL,
>>                           s->read_poll  ? tap_send     : NULL,
>>                           s->write_poll ? tap_writable : NULL,
>>                           s);
>>
>>    No ideas about how to transform this into something that don't use NULL's in any of its fields
>>    other than a row of if's.
>>
>> - removal of poll function. comment of qemu_set_fd_handler2()
>>    /* XXX: fd_read_poll should be suppressed, but an API change is
>>      necessary in the character devices to suppress fd_can_read(). */
>>
>>    But qemu-char.c is a complex beast, and would preffer to 1st get this patches in, and then
>>    work on the other stuff.
>>
>> - obvious optimization now is to have the FD_SET() for write/read already filled, but I
>>    haven't done any meassurement.
>>
>> Comments?
>>
>> Juan Quintela (9):
>>    Convert io handlers to QLIST
>>    Introduce qemu_clear_fd_handler()
>>    Introduce qemu_set_fd_read_handler()
>>    Introduce qemu_set_fd_write_handler()
>>    Introduce qemu_set_fd_rw_handler()
>>    bt: remove bt_host_read_poll()
>>    Introduce qemu_set_fd_poll_handler()
>>    remove useless cast
>>    rename IOCanRWHandler to IOCanReadHandler
>>
>>   aio.c               |    2 +-
>>   audio/alsaaudio.c   |   12 +++---
>>   audio/ossaudio.c    |   10 ++--
>>   bt-host.c           |    9 +----
>>   bt-vhci.c           |    2 +-
>>   hw/baum.c           |    2 +-
>>   hw/xen_backend.c    |   10 ++--
>>   migration-exec.c    |    8 ++--
>>   migration-fd.c      |    5 +-
>>   migration-tcp.c     |   10 ++--
>>   migration-unix.c    |   10 ++--
>>   migration.c         |    8 ++--
>>   net/socket.c        |   14 +++---
>>   net/vde.c           |    4 +-
>>   qemu-aio.h          |    4 +-
>>   qemu-char.c         |   48 +++++++++++-----------
>>   qemu-char.h         |   25 ++++++++---
>>   qemu-common.h       |    2 +-
>>   qemu-tool.c         |    9 ++--
>>   usb-linux.c         |    4 +-
>>   vl.c                |  114 +++++++++++++++++++++++++++++++++++---------------
>>   vnc-auth-sasl.c     |    2 +-
>>   vnc-auth-vencrypt.c |    6 +-
>>   vnc.c               |   12 +++---
>>   24 files changed, 190 insertions(+), 142 deletions(-)
>>      
> What's the point if it ends up adding 48 lines of code?
>    

Yeah, I think this would be more interesting if it eliminated the 
can_read handlers altogether.

Regards,

Anthony Liguori

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

* [Qemu-devel] Re: [PATCH 0/9] Clear fd handlers
  2010-03-09 23:58   ` Anthony Liguori
@ 2010-03-10  0:12     ` Juan Quintela
  0 siblings, 0 replies; 14+ messages in thread
From: Juan Quintela @ 2010-03-10  0:12 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 03/09/2010 05:53 PM, malc wrote:
>> On Tue, 9 Mar 2010, Juan Quintela wrote:
>>> - convert io_handlers to one QLIST

This part removes lines :)

>>> - once there fix bt that don't need poll at all (having a poll function that always return true
>>>    is the equivalent of not having one).

This one also removes lines.

>>> - remove cast to (void *)(unsigned long) for things that already
>>> were pointers

Cleanup. same lines.

>>> - IOCanRWHandler is only used for reads ->  rename it (almost no users).

cleanup. same lines.

>>> ToDo:
>>> - to remove the export of qemu_set_fd_handlers2() we need a solution for tap.
>>>    Tap is the only user in qemu that uses poll, read and write, and it changes in very imaginative
>>>    ways:
>>>      qemu_set_fd_handler2(s->fd,
>>>                           s->read_poll  ? tap_can_send : NULL,
>>>                           s->read_poll  ? tap_send     : NULL,
>>>                           s->write_poll ? tap_writable : NULL,
>>>                           s);
>>>
>>>    No ideas about how to transform this into something that don't use NULL's in any of its fields
>>>    other than a row of if's.

for removing the poll function.  I need some help here.

>>>
>>> - removal of poll function. comment of qemu_set_fd_handler2()
>>>    /* XXX: fd_read_poll should be suppressed, but an API change is
>>>      necessary in the character devices to suppress fd_can_read(). */
>>>
>>>    But qemu-char.c is a complex beast, and would preffer to 1st get this patches in, and then
>>>    work on the other stuff.

on that one looking at it, but it has at least two indirections.  Only 4
users left here.  Will try to look at it.

>>>
>> What's the point if it ends up adding 48 lines of code?
>>

readability? I got confused continously with:

qemu_set_fd_handler2(s->fd, NULL, foo, NULL, state);
qemu_set_fd_handler2(s->fd, NULL, NULL, bar, state);

And not all functions name make clear than foo means read and bar means write.

> Yeah, I think this would be more interesting if it eliminated the
> can_read handlers altogether.

Fully, agree. Indirections of qemu-char.c are "interesting".  tap is
only user of poll, read and write and the only one that adds/remove
functions continously.

Was waiting for tips, hints, past ideas about how to remove that fd_can funtions.

Regards, Juan.

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

end of thread, other threads:[~2010-03-10  0:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-09 22:25 [Qemu-devel] [PATCH 0/9] Clear fd handlers Juan Quintela
2010-03-09 22:25 ` [Qemu-devel] [PATCH 1/9] Convert io handlers to QLIST Juan Quintela
2010-03-09 22:25 ` [Qemu-devel] [PATCH 2/9] Introduce qemu_clear_fd_handler() Juan Quintela
2010-03-09 22:25 ` [Qemu-devel] [PATCH 3/9] Introduce qemu_set_fd_read_handler() Juan Quintela
2010-03-09 22:25 ` [Qemu-devel] [PATCH 4/9] Introduce qemu_set_fd_write_handler() Juan Quintela
2010-03-09 22:25 ` [Qemu-devel] [PATCH 5/9] Introduce qemu_set_fd_rw_handler() Juan Quintela
2010-03-09 22:41   ` [Qemu-devel] " Juan Quintela
2010-03-09 22:26 ` [Qemu-devel] [PATCH 6/9] bt: remove bt_host_read_poll() Juan Quintela
2010-03-09 22:26 ` [Qemu-devel] [PATCH 7/9] Introduce qemu_set_fd_poll_handler() Juan Quintela
2010-03-09 22:26 ` [Qemu-devel] [PATCH 8/9] remove useless cast Juan Quintela
2010-03-09 22:26 ` [Qemu-devel] [PATCH 9/9] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
2010-03-09 23:53 ` [Qemu-devel] [PATCH 0/9] Clear fd handlers malc
2010-03-09 23:58   ` Anthony Liguori
2010-03-10  0:12     ` [Qemu-devel] " Juan Quintela

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).