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

in this v2 series:
- a pony for malc:
   23 files changed, 133 insertions(+), 215 deletions(-)
- a pony for Anthony
   fd_read_poll is no more.

- tap/qemu-char* poll users are gone.  I just folded the poll function on top of
  the read one.  Anyone knows of a different reason that legacy for having a poll
  function?  Only difference should be that we are calling select with more
  descriptors.

- rename qemu_clear_fd_handler() to qemu_remove_fd_handler()
  It removes it from a list, don't clear anything.

- now that pull function is gone, and remove of handler is a diffrent
  function, only one NULL is used by function -> no more
  qemu_set_fd_{read,write,poll}_handler, just old qemu_set_fd_handler.

Monitor works, and tap works.  I don't know if there is any performance difference at all.
Could anyone that has a setup to meassure it test it?

Later, Juan.

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


Juan Quintela (14):
  Convert io handlers to QLIST
  remove useless cast
  rename IOCanRWHandler to IOCanReadHandler
  bt: remove bt_host_read_poll()
  Handle deleted IOHandlers in a single buffer
  tap: insert tap_can_send() into tap_send()
  qemu-char:stdio insert poll call into read one
  qemu-char:tcp insert poll call into read one
  qemu-char:fd insert poll call into read one
  qemu-char:pty insert poll call into read one
  qemu-char:udp insert poll call into read one
  Remove qemu_set_fd_handler2()
  Remove now unused fd_read_poll and all its only left user
  Add qemu_remove_fd_handler()

 aio.c               |    2 +-
 audio/alsaaudio.c   |    4 +-
 audio/ossaudio.c    |    6 +-
 bt-host.c           |    9 +----
 hw/xen_backend.c    |    4 +-
 migration-exec.c    |    7 +--
 migration-fd.c      |    5 +-
 migration-tcp.c     |   10 ++--
 migration-unix.c    |   10 ++--
 migration.c         |    8 ++--
 net/socket.c        |    6 +-
 net/tap.c           |   27 ++++--------
 net/vde.c           |    2 +-
 qemu-aio.h          |    4 +-
 qemu-char.c         |  112 ++++++++++++++++----------------------------------
 qemu-char.h         |   11 +----
 qemu-common.h       |    2 +-
 qemu-tool.c         |    9 ++--
 usb-linux.c         |    2 +-
 vl.c                |   92 +++++++++++++++++-------------------------
 vnc-auth-sasl.c     |    2 +-
 vnc-auth-vencrypt.c |    2 +-
 vnc.c               |   12 +++---
 23 files changed, 133 insertions(+), 215 deletions(-)

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

* [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 11:57   ` malc
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 02/14] remove useless cast Juan Quintela
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 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] 21+ messages in thread

* [Qemu-devel] [PATCH 02/14] remove useless cast
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 03/14] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

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

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

diff --git a/migration-exec.c b/migration-exec.c
index 6ff8449..5435827 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -141,8 +141,7 @@ int exec_start_incoming_migration(const char *command)
     }

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

     return 0;
 }
diff --git a/migration-fd.c b/migration-fd.c
index 9cf52ce..0abd372 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_handler2(fd, NULL, fd_accept_incoming_migration, NULL,
-			 (void *)(unsigned long)f);
+    qemu_set_fd_handler2(fd, NULL, fd_accept_incoming_migration, NULL, f);

     return 0;
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 03/14] rename IOCanRWHandler to IOCanReadHandler
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 02/14] remove useless cast Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 04/14] bt: remove bt_host_read_poll() Juan Quintela
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 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   |    7 +++----
 qemu-common.h |    2 +-
 qemu-tool.c   |    2 +-
 vl.c          |    4 ++--
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 86c7c5a..6ea4e8c 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 bcc0766..3a9427b 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);
@@ -98,7 +98,7 @@ extern int term_escape_char;
 /* async I/O support */

 int qemu_set_fd_handler2(int fd,
-                         IOCanRWHandler *fd_read_poll,
+                         IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,
                          IOHandler *fd_write,
                          void *opaque);
@@ -106,5 +106,4 @@ int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
                         IOHandler *fd_write,
                         void *opaque);
-
 #endif
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/qemu-tool.c b/qemu-tool.c
index 18b48af..45e6df9 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -91,7 +91,7 @@ void qemu_bh_delete(QEMUBH *bh)
 }

 int qemu_set_fd_handler2(int fd,
-                         IOCanRWHandler *fd_read_poll,
+                         IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,
                          IOHandler *fd_write,
                          void *opaque)
diff --git a/vl.c b/vl.c
index 83ff652..354ea31 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;
@@ -2607,7 +2607,7 @@ static QTAILQ_HEAD(, IOHandlerRecord) io_handlers =
 /* 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)
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 04/14] bt: remove bt_host_read_poll()
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (2 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 03/14] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 05/14] Handle deleted IOHandlers in a single pass Juan Quintela
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 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..33b2761 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_handler(s->fd, bt_host_read, NULL, s);

     return &s->hci;
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 05/14] Handle deleted IOHandlers in a single pass
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (3 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 04/14] bt: remove bt_host_read_poll() Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 06/14] tap: insert tap_can_send() into tap_send() Juan Quintela
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

Previous code 1st call normal functions and then remove deleted
handlers in the following pass.  Calllapse the two walks.

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

diff --git a/vl.c b/vl.c
index 354ea31..c2ae185 100644
--- a/vl.c
+++ b/vl.c
@@ -3846,20 +3846,17 @@ void main_loop_wait(int timeout)
     if (ret > 0) {
         IOHandlerRecord *pioh;

-        QTAILQ_FOREACH(ioh, &io_handlers, next) {
-            if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
-                ioh->fd_read(ioh->opaque);
-            }
-            if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
-                ioh->fd_write(ioh->opaque);
-            }
-        }
-
-	/* remove deleted IO handlers */
         QTAILQ_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
             if (ioh->deleted) {
                 QTAILQ_REMOVE(&io_handlers, ioh, next);
                 qemu_free(ioh);
+                continue;
+            }
+            if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
+                ioh->fd_read(ioh->opaque);
+            }
+            if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
+                ioh->fd_write(ioh->opaque);
             }
         }
     }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 06/14] tap: insert tap_can_send() into tap_send()
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (4 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 05/14] Handle deleted IOHandlers in a single pass Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 07/14] qemu-char:stdio insert poll call into read one Juan Quintela
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 net/tap.c |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index 7a7320c..3ab65a3 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -61,17 +61,15 @@ typedef struct TAPState {

 static int launch_script(const char *setup_script, const char *ifname, int fd);

-static int tap_can_send(void *opaque);
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);

 static void tap_update_fd_handler(TAPState *s)
 {
-    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);
+    qemu_set_fd_handler(s->fd,
+                        s->read_poll  ? tap_send     : NULL,
+                        s->write_poll ? tap_writable : NULL,
+                        s);
 }

 static void tap_read_poll(TAPState *s, int enable)
@@ -165,13 +163,6 @@ static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
     return tap_write_packet(s, iov, 1);
 }

-static int tap_can_send(void *opaque)
-{
-    TAPState *s = opaque;
-
-    return qemu_can_send_packet(&s->nc);
-}
-
 #ifndef __sun__
 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 {
@@ -188,12 +179,10 @@ static void tap_send_completed(VLANClientState *nc, ssize_t len)
 static void tap_send(void *opaque)
 {
     TAPState *s = opaque;
-    int size;

-    do {
+    while (qemu_can_send_packet(&s->nc) > 0) {
         uint8_t *buf = s->buf;
-
-        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
+        int size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
         if (size <= 0) {
             break;
         }
@@ -206,8 +195,10 @@ static void tap_send(void *opaque)
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, 0);
+        } else if (size < 0) {
+            return;
         }
-    } while (size > 0 && qemu_can_send_packet(&s->nc));
+    }
 }

 int tap_has_ufo(VLANClientState *nc)
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 07/14] qemu-char:stdio insert poll call into read one
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (5 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 06/14] tap: insert tap_can_send() into tap_send() Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 08/14] qemu-char:tcp " Juan Quintela
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 6ea4e8c..93b3ea4 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -664,8 +664,10 @@ static CharDriverState *qemu_chr_open_pipe(QemuOpts *opts)
 static uint8_t term_fifo[TERM_FIFO_MAX_SIZE];
 static int term_fifo_size;

-static int stdio_read_poll(void *opaque)
+static void stdio_read(void *opaque)
 {
+    int size;
+    uint8_t buf[1];
     CharDriverState *chr = opaque;

     /* try to flush the queue if needed */
@@ -673,19 +675,9 @@ static int stdio_read_poll(void *opaque)
         qemu_chr_read(chr, term_fifo, 1);
         term_fifo_size = 0;
     }
-    /* see if we can absorb more chars */
-    if (term_fifo_size == 0)
-        return 1;
-    else
-        return 0;
-}
-
-static void stdio_read(void *opaque)
-{
-    int size;
-    uint8_t buf[1];
-    CharDriverState *chr = opaque;
-
+    if (term_fifo_size != 0) {
+        return;
+    }
     size = read(0, buf, 1);
     if (size == 0) {
         /* stdin has been closed. Remove it from the active list.  */
@@ -757,7 +749,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_handler(0, stdio_read, NULL, chr);
     stdio_nb_clients++;
     term_init(opts);

-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 08/14] qemu-char:tcp insert poll call into read one
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (6 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 07/14] qemu-char:stdio insert poll call into read one Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 09/14] qemu-char:fd " Juan Quintela
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 93b3ea4..063da94 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1899,16 +1899,6 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     }
 }

-static int tcp_chr_read_poll(void *opaque)
-{
-    CharDriverState *chr = opaque;
-    TCPCharDriver *s = chr->opaque;
-    if (!s->connected)
-        return 0;
-    s->max_size = qemu_chr_can_read(chr);
-    return s->max_size;
-}
-
 #define IAC 255
 #define IAC_BREAK 243
 static void tcp_chr_process_IAC_bytes(CharDriverState *chr,
@@ -2030,7 +2020,10 @@ static void tcp_chr_read(void *opaque)
     uint8_t buf[READ_BUF_LEN];
     int len, size;

-    if (!s->connected || s->max_size <= 0)
+    if (!s->connected)
+        return;
+    s->max_size = qemu_chr_can_read(chr);
+    if (s->max_size <= 0)
         return;
     len = sizeof(buf);
     if (len > s->max_size)
@@ -2064,8 +2057,7 @@ 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_handler(s->fd, tcp_chr_read, NULL, chr);
     qemu_chr_generic_open(chr);
 }

-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 09/14] qemu-char:fd insert poll call into read one
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (7 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 08/14] qemu-char:tcp " Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 10/14] qemu-char:pty " Juan Quintela
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 063da94..875f254 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -536,15 +536,6 @@ static int fd_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     return send_all(s->fd_out, buf, len);
 }

-static int fd_chr_read_poll(void *opaque)
-{
-    CharDriverState *chr = opaque;
-    FDCharDriver *s = chr->opaque;
-
-    s->max_size = qemu_chr_can_read(chr);
-    return s->max_size;
-}
-
 static void fd_chr_read(void *opaque)
 {
     CharDriverState *chr = opaque;
@@ -552,6 +543,9 @@ static void fd_chr_read(void *opaque)
     int size, len;
     uint8_t buf[READ_BUF_LEN];

+    s->max_size = qemu_chr_can_read(chr);
+    if (s->max_size <= 0)
+        return;
     len = sizeof(buf);
     if (len > s->max_size)
         len = s->max_size;
@@ -576,8 +570,7 @@ 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_handler(s->fd_in, fd_chr_read, NULL, chr);
         }
     }
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 10/14] qemu-char:pty insert poll call into read one
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (8 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 09/14] qemu-char:fd " Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 11/14] qemu-char:udp " Juan Quintela
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   16 +++++-----------
 1 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 875f254..bc294af 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -833,15 +833,6 @@ static int pty_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     return send_all(s->fd, buf, len);
 }

-static int pty_chr_read_poll(void *opaque)
-{
-    CharDriverState *chr = opaque;
-    PtyCharDriver *s = chr->opaque;
-
-    s->read_bytes = qemu_chr_can_read(chr);
-    return s->read_bytes;
-}
-
 static void pty_chr_read(void *opaque)
 {
     CharDriverState *chr = opaque;
@@ -849,6 +840,10 @@ static void pty_chr_read(void *opaque)
     int size, len;
     uint8_t buf[READ_BUF_LEN];

+    s->read_bytes = qemu_chr_can_read(chr);
+
+    if (s->read_bytes <= 0)
+        return;
     len = sizeof(buf);
     if (len > s->read_bytes)
         len = s->read_bytes;
@@ -870,8 +865,7 @@ 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_handler(s->fd, pty_chr_read, NULL, chr);
     s->polling = 1;
     /*
      * Short timeout here: just need wait long enougth that qemu makes
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 11/14] qemu-char:udp insert poll call into read one
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (9 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 10/14] qemu-char:pty " Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 12/14] Remove qemu_set_fd_handler2() Juan Quintela
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-char.c |   13 ++-----------
 1 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index bc294af..9098d79 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1767,7 +1767,7 @@ static int udp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     return send(s->fd, (const void *)buf, len, 0);
 }

-static int udp_chr_read_poll(void *opaque)
+static void udp_chr_read(void *opaque)
 {
     CharDriverState *chr = opaque;
     NetCharDriver *s = chr->opaque;
@@ -1782,14 +1782,6 @@ static int udp_chr_read_poll(void *opaque)
         s->bufptr++;
         s->max_size = qemu_chr_can_read(chr);
     }
-    return s->max_size;
-}
-
-static void udp_chr_read(void *opaque)
-{
-    CharDriverState *chr = opaque;
-    NetCharDriver *s = chr->opaque;
-
     if (s->max_size == 0)
         return;
     s->bufcnt = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
@@ -1810,8 +1802,7 @@ 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_handler(s->fd, udp_chr_read, NULL, chr);
     }
 }

-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 12/14] Remove qemu_set_fd_handler2()
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (10 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 11/14] qemu-char:udp " Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 13/14] Remove now unused fd_read_poll and all its only left user Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler() Juan Quintela
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

Now that there are no more poll_read users, we can remove it.  Convert all
users to qemu_set_fd_handler().

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 aio.c               |    2 +-
 migration-exec.c    |    6 +++---
 migration-fd.c      |    4 ++--
 migration-tcp.c     |   10 +++++-----
 migration-unix.c    |   10 +++++-----
 migration.c         |    8 ++++----
 qemu-aio.h          |    4 ++--
 qemu-char.c         |   12 ++++++------
 qemu-char.h         |    5 -----
 qemu-tool.c         |    9 ++++-----
 vl.c                |   24 ++++++------------------
 vnc-auth-sasl.c     |    2 +-
 vnc-auth-vencrypt.c |    2 +-
 vnc.c               |   12 ++++++------
 14 files changed, 46 insertions(+), 64 deletions(-)

diff --git a/aio.c b/aio.c
index f164a47..16105b3 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_handler(fd, io_read, io_write, opaque);

     return 0;
 }
diff --git a/migration-exec.c b/migration-exec.c
index 5435827..c971145 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_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(qemu_stdio_fd(f), NULL, NULL, NULL);
     qemu_fclose(f);
 }

@@ -140,8 +140,8 @@ int exec_start_incoming_migration(const char *command)
         return -errno;
     }

-    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL,
-			 exec_accept_incoming_migration, NULL, f);
+    qemu_set_fd_handler(qemu_stdio_fd(f),
+                        exec_accept_incoming_migration, NULL, f);

     return 0;
 }
diff --git a/migration-fd.c b/migration-fd.c
index 0abd372..93e1c4e 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_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(qemu_stdio_fd(f), NULL, NULL, NULL);
     qemu_fclose(f);
 }

@@ -136,7 +136,7 @@ int fd_start_incoming_migration(const char *infd)
         return -errno;
     }

-    qemu_set_fd_handler2(fd, NULL, fd_accept_incoming_migration, NULL, f);
+    qemu_set_fd_handler(fd, fd_accept_incoming_migration, NULL, f);

     return 0;
 }
diff --git a/migration-tcp.c b/migration-tcp.c
index 95ce722..80ebbc5 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_set_fd_handler(s->fd, NULL, NULL, NULL);

     if (val == 0)
         migrate_fd_connect(s);
@@ -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_handler(s->fd, NULL, tcp_wait_for_connect, s);
     } while (ret == -EINTR);

     if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
@@ -176,7 +176,7 @@ static void tcp_accept_incoming_migration(void *opaque)
 out_fopen:
     qemu_fclose(f);
 out:
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(s, NULL, NULL, NULL);
     close(s);
     close(c);
 }
@@ -205,8 +205,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_handler(s, tcp_accept_incoming_migration, NULL,
+                        (void *)(unsigned long)s);

     return 0;

diff --git a/migration-unix.c b/migration-unix.c
index 49de1b9..891b3a7 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_set_fd_handler(s->fd, NULL, NULL, NULL);

     if (val == 0)
         migrate_fd_connect(s);
@@ -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_handler(s->fd, NULL, unix_wait_for_connect, s);
     } while (ret == -EINTR);

     if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
@@ -182,7 +182,7 @@ static void unix_accept_incoming_migration(void *opaque)
 out_fopen:
     qemu_fclose(f);
 out:
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(s, NULL, NULL, NULL);
     close(s);
     close(c);
 }
@@ -214,8 +214,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_handler(sock, unix_accept_incoming_migration, NULL,
+                        (void *)(unsigned long)sock);

     return 0;

diff --git a/migration.c b/migration.c
index 05f6cc5..2da715c 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_set_fd_handler(s->fd, NULL, NULL, NULL);

     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_set_fd_handler(s->fd, NULL, NULL, NULL);
     qemu_file_put_notify(s->file);
 }

@@ -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_handler(s->fd, NULL, migrate_fd_put_notify, s);

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

-    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
     return s->close(s);
 }
diff --git a/qemu-aio.h b/qemu-aio.h
index 3bdd749..0630cbe 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_handler.  Unlike qemu_set_fd_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_handler.
  */
 int qemu_aio_set_fd_handler(int fd,
                             IOHandler *io_read,
diff --git a/qemu-char.c b/qemu-char.c
index 9098d79..3635f4e 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -554,7 +554,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_set_fd_handler(s->fd_in, NULL, NULL, NULL);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -582,7 +582,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_set_fd_handler(s->fd_in, NULL, NULL, NULL);
         }
     }

@@ -674,7 +674,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_set_fd_handler(0, NULL, NULL, NULL);
         qemu_chr_event(chr, CHR_EVENT_CLOSED);
         return;
     }
@@ -730,7 +730,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_set_fd_handler(0, NULL, NULL, NULL);
     fd_chr_close(chr);
 }

@@ -883,7 +883,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_set_fd_handler(s->fd, NULL, NULL, NULL);
         s->connected = 0;
         s->polling = 0;
         /* (re-)connect poll interval for idle guests: once per second.
@@ -919,7 +919,7 @@ static void pty_chr_close(struct CharDriverState *chr)
 {
     PtyCharDriver *s = chr->opaque;

-    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
     close(s->fd);
     qemu_del_timer(s->timer);
     qemu_free_timer(s->timer);
diff --git a/qemu-char.h b/qemu-char.h
index 3a9427b..3bad12d 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -97,11 +97,6 @@ extern int term_escape_char;

 /* async I/O support */

-int qemu_set_fd_handler2(int fd,
-                         IOCanReadHandler *fd_read_poll,
-                         IOHandler *fd_read,
-                         IOHandler *fd_write,
-                         void *opaque);
 int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
                         IOHandler *fd_write,
diff --git a/qemu-tool.c b/qemu-tool.c
index 45e6df9..873763e 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,
-                         IOCanReadHandler *fd_read_poll,
-                         IOHandler *fd_read,
-                         IOHandler *fd_write,
-                         void *opaque)
+int qemu_set_fd_handler(int fd,
+                        IOHandler *fd_read,
+                        IOHandler *fd_write,
+                        void *opaque)
 {
     return 0;
 }
diff --git a/vl.c b/vl.c
index c2ae185..a961710 100644
--- a/vl.c
+++ b/vl.c
@@ -2604,13 +2604,10 @@ 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(). */
-int qemu_set_fd_handler2(int fd,
-                         IOCanReadHandler *fd_read_poll,
-                         IOHandler *fd_read,
-                         IOHandler *fd_write,
-                         void *opaque)
+int qemu_set_fd_handler(int fd,
+                        IOHandler *fd_read,
+                        IOHandler *fd_write,
+                        void *opaque)
 {
     IOHandlerRecord *ioh;

@@ -2630,7 +2627,6 @@ int qemu_set_fd_handler2(int fd,
         QTAILQ_INSERT_TAIL(&io_handlers, ioh, next);
     found:
         ioh->fd = fd;
-        ioh->fd_read_poll = fd_read_poll;
         ioh->fd_read = fd_read;
         ioh->fd_write = fd_write;
         ioh->opaque = opaque;
@@ -2639,14 +2635,6 @@ int qemu_set_fd_handler2(int fd,
     return 0;
 }

-int qemu_set_fd_handler(int fd,
-                        IOHandler *fd_read,
-                        IOHandler *fd_write,
-                        void *opaque)
-{
-    return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
-}
-
 #ifdef _WIN32
 /***********************************************************/
 /* Polling handling */
@@ -3252,8 +3240,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_handler(fds[0], qemu_event_read, NULL,
+                        (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..1e4f77f 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_handler(vs->csock, vnc_client_read, NULL, vs);
     }

     return ret;
diff --git a/vnc-auth-vencrypt.c b/vnc-auth-vencrypt.c
index 07c1691..a5d2b44 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_handler(vs->csock, vnc_client_read, vnc_client_write, vs);

     start_auth_vencrypt_subauth(vs);

diff --git a/vnc.c b/vnc.c
index 01353a9..2cfb0eb 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_set_fd_handler(vs->csock, NULL, NULL, NULL);
     closesocket(vs->csock);
     vs->csock = -1;
 }
@@ -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_handler(vs->csock, vnc_client_read, NULL, vs);
     }

     return ret;
@@ -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_handler(vs->csock, vnc_client_read, vnc_client_write, vs);
     }

     buffer_append(&vs->output, data, len);
@@ -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_handler(vs->csock, vnc_client_read, NULL, vs);

     vnc_client_cache_addr(vs);
     vnc_qmp_event(vs, QEVENT_VNC_CONNECTED);
@@ -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_set_fd_handler(vs->lsock, NULL, NULL, NULL);
         close(vs->lsock);
         vs->lsock = -1;
     }
@@ -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_handler(vs->lsock, vnc_listen_read, NULL, vs);
 }
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 13/14] Remove now unused fd_read_poll and all its only left user
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (11 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 12/14] Remove qemu_set_fd_handler2() Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler() Juan Quintela
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel


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

diff --git a/vl.c b/vl.c
index a961710..3bf8b87 100644
--- a/vl.c
+++ b/vl.c
@@ -2590,7 +2590,6 @@ void pcmcia_info(Monitor *mon)

 typedef struct IOHandlerRecord {
     int fd;
-    IOCanReadHandler *fd_read_poll;
     IOHandler *fd_read;
     IOHandler *fd_write;
     int deleted;
@@ -3809,9 +3808,7 @@ void main_loop_wait(int timeout)
     QTAILQ_FOREACH(ioh, &io_handlers, next) {
         if (ioh->deleted)
             continue;
-        if (ioh->fd_read &&
-            (!ioh->fd_read_poll ||
-             ioh->fd_read_poll(ioh->opaque) != 0)) {
+        if (ioh->fd_read) {
             FD_SET(ioh->fd, &rfds);
             if (ioh->fd > nfds)
                 nfds = ioh->fd;
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler()
  2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
                   ` (12 preceding siblings ...)
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 13/14] Remove now unused fd_read_poll and all its only left user Juan Quintela
@ 2010-03-10 10:03 ` Juan Quintela
  13 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 10:03 UTC (permalink / raw)
  To: qemu-devel

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

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

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

* Re: [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 10:03 ` [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST Juan Quintela
@ 2010-03-10 11:57   ` malc
  2010-03-10 12:06     ` [Qemu-devel] " Juan Quintela
  0 siblings, 1 reply; 21+ messages in thread
From: malc @ 2010-03-10 11:57 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Wed, 10 Mar 2010, Juan Quintela wrote:

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

The old code inserted at the head, didn't it?

>      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;
> +            }
>          }
>      }
> 
> 

-- 
mailto:av1474@comtv.ru

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

* [Qemu-devel] Re: [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 11:57   ` malc
@ 2010-03-10 12:06     ` Juan Quintela
  2010-03-10 12:08       ` malc
  0 siblings, 1 reply; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 12:06 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Wed, 10 Mar 2010, Juan Quintela wrote:

>> -        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);
>
> The old code inserted at the head, didn't it?

Sorry, you are right, it shouldn't matter too much, but it is a change.

Later, Juan.

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

* [Qemu-devel] Re: [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 12:06     ` [Qemu-devel] " Juan Quintela
@ 2010-03-10 12:08       ` malc
  2010-03-10 12:20         ` Juan Quintela
  0 siblings, 1 reply; 21+ messages in thread
From: malc @ 2010-03-10 12:08 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Wed, 10 Mar 2010, Juan Quintela wrote:

> malc <av1474@comtv.ru> wrote:
> > On Wed, 10 Mar 2010, Juan Quintela wrote:
> 
> >> -        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);
> >
> > The old code inserted at the head, didn't it?
> 
> Sorry, you are right, it shouldn't matter too much, but it is a change.

If it did, why queue instead of list?

> 
> Later, Juan.
> 

-- 
mailto:av1474@comtv.ru

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

* [Qemu-devel] Re: [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 12:08       ` malc
@ 2010-03-10 12:20         ` Juan Quintela
  2010-03-10 12:54           ` malc
  0 siblings, 1 reply; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 12:20 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Wed, 10 Mar 2010, Juan Quintela wrote:
>
>> malc <av1474@comtv.ru> wrote:
>> > On Wed, 10 Mar 2010, Juan Quintela wrote:
>> 
>> >> -        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);
>> >
>> > The old code inserted at the head, didn't it?
>> 
>> Sorry, you are right, it shouldn't matter too much, but it is a change.
>
> If it did, why queue instead of list?

Arbitrary.  Example conversion nearer was QTAIL.

Use is:
- insert at the beggining
- search for removal
- loop all list

insert/searchs should be less than loops.  I am more
interested/intrigued if setting more fd's in the select call could
change behaviour.

Changing to QLIST is search/replace, no big deal.

>> 
>> Later, Juan.
>> 

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

* [Qemu-devel] Re: [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 12:20         ` Juan Quintela
@ 2010-03-10 12:54           ` malc
  2010-03-10 13:03             ` Juan Quintela
  0 siblings, 1 reply; 21+ messages in thread
From: malc @ 2010-03-10 12:54 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Wed, 10 Mar 2010, Juan Quintela wrote:

> malc <av1474@comtv.ru> wrote:
> > On Wed, 10 Mar 2010, Juan Quintela wrote:
> >
> >> malc <av1474@comtv.ru> wrote:
> >> > On Wed, 10 Mar 2010, Juan Quintela wrote:
> >> 
> >> >> -        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);
> >> >
> >> > The old code inserted at the head, didn't it?
> >> 
> >> Sorry, you are right, it shouldn't matter too much, but it is a change.
> >
> > If it did, why queue instead of list?
> 
> Arbitrary.  Example conversion nearer was QTAIL.

Please do `man 3 queue'. Specifically the comparison between the tail
queues and lists.

> 
> Use is:
> - insert at the beggining
> - search for removal
> - loop all list
> 
> insert/searchs should be less than loops.  I am more
> interested/intrigued if setting more fd's in the select call could
> change behaviour.
> 
> Changing to QLIST is search/replace, no big deal.
> 
> >> 
> >> Later, Juan.
> >> 
> 

-- 
mailto:av1474@comtv.ru

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

* [Qemu-devel] Re: [PATCH 01/14] Convert io handlers to QLIST
  2010-03-10 12:54           ` malc
@ 2010-03-10 13:03             ` Juan Quintela
  0 siblings, 0 replies; 21+ messages in thread
From: Juan Quintela @ 2010-03-10 13:03 UTC (permalink / raw)
  To: malc; +Cc: qemu-devel

malc <av1474@comtv.ru> wrote:
> On Wed, 10 Mar 2010, Juan Quintela wrote:
>
>> malc <av1474@comtv.ru> wrote:
>> > On Wed, 10 Mar 2010, Juan Quintela wrote:
>> >
>> >> malc <av1474@comtv.ru> wrote:
>> >> > On Wed, 10 Mar 2010, Juan Quintela wrote:
>> >> 
>> >> >> -        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);
>> >> >
>> >> > The old code inserted at the head, didn't it?
>> >> 
>> >> Sorry, you are right, it shouldn't matter too much, but it is a change.
>> >
>> > If it did, why queue instead of list?
>> 
>> Arbitrary.  Example conversion nearer was QTAIL.
>
> Please do `man 3 queue'. Specifically the comparison between the tail
> queues and lists.

Thanks very much for the info.  Didn't knew that page.

You win.  Will change to QLISTS.  Waiting for more comments.

Later, Juan.

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

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

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 10:03 [Qemu-devel] [PATCH v2 00/14] Clear fd handlers Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST Juan Quintela
2010-03-10 11:57   ` malc
2010-03-10 12:06     ` [Qemu-devel] " Juan Quintela
2010-03-10 12:08       ` malc
2010-03-10 12:20         ` Juan Quintela
2010-03-10 12:54           ` malc
2010-03-10 13:03             ` Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 02/14] remove useless cast Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 03/14] rename IOCanRWHandler to IOCanReadHandler Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 04/14] bt: remove bt_host_read_poll() Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 05/14] Handle deleted IOHandlers in a single pass Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 06/14] tap: insert tap_can_send() into tap_send() Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 07/14] qemu-char:stdio insert poll call into read one Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 08/14] qemu-char:tcp " Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 09/14] qemu-char:fd " Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 10/14] qemu-char:pty " Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 11/14] qemu-char:udp " Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 12/14] Remove qemu_set_fd_handler2() Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 13/14] Remove now unused fd_read_poll and all its only left user Juan Quintela
2010-03-10 10:03 ` [Qemu-devel] [PATCH 14/14] Add qemu_remove_fd_handler() 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).