Skip to contentSkip to conversation

Clear fd handlers

PATCH Superseded Juan Quintela 3 participants 14 messages Mar 9, 2010 – Mar 10, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#7 lore raw

PATCH 6/9 bt: remove bt_host_read_poll()

In reply to Juan Quintela

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

---
 bt-host.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
bt-host.c +1 -8
index 964ac11..dcd302b 100644
@@ -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;
 }
Signature · 1 line
1.6.6.1
#8 lore raw

PATCH 7/9 Introduce qemu_set_fd_poll_handler()

In reply to Juan Quintela

Patch consist:

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

---
 qemu-char.c |   18 +++++++++---------
 qemu-char.h |    4 ++++
 vl.c        |   16 ++++++++++++++++
 3 files changed, 29 insertions(+), 9 deletions(-)
qemu-char.c +9 -9
index 43d0758..4822209 100644
@@ -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);
 }
 
qemu-char.h +4 -0
index 8d7da54..ffc6cb6 100644
@@ -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
vl.c +16 -0
index c061732..2cb35dc 100644
@@ -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 */
Signature · 1 line
1.6.6.1
#10 lore raw

PATCH 9/9 rename IOCanRWHandler to IOCanReadHandler

In reply to Juan Quintela

It was always only used for reads

---
 qemu-char.c   |    4 ++--
 qemu-char.h   |    8 ++++----
 qemu-common.h |    2 +-
 vl.c          |    6 +++---
 4 files changed, 10 insertions(+), 10 deletions(-)
qemu-char.c +2 -2
index 4822209..5d8043a 100644
@@ -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];
qemu-char.h +4 -4
index ffc6cb6..9519332 100644
@@ -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);
 
qemu-common.h +1 -1
index 805be1a..42bfbcd 100644
@@ -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 {
vl.c +3 -3
index 2cb35dc..d774d39 100644
@@ -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)
 {
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/9 Convert io handlers to QLIST

In reply to Juan Quintela
---
 vl.c |   35 ++++++++++++++---------------------
 1 files changed, 14 insertions(+), 21 deletions(-)
vl.c +14 -21
index 10d8e34..83ff652 100644
@@ -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;
+            }
         }
     }
 
Signature · 1 line
1.6.6.1
#6 lore raw

[Qemu-devel] Re: [PATCH 5/9] Introduce qemu_set_fd_rw_handler()

In reply to Juan Quintela
Quoted 6 lines · Juan Quintela

Patch consist:

aio.c +0 -0
index f164a47..4185233 100644

aio.c int qemu_aio_set_fd_handler(int fd, · line 99

Quoted 8 lines
aio.c +1 -1
@@ -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.

#3 lore raw

PATCH 3/9 Introduce qemu_set_fd_read_handler()

In reply to Juan Quintela

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

---
 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(-)
audio/alsaaudio.c +2 -2
index 4259d9c..2455ee4 100644
@@ -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) {
audio/ossaudio.c +1 -1
index 97e0f1b..4c91a46 100644
@@ -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)
bt-vhci.c +1 -1
index 679c5e0..2352f1f 100644
@@ -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);
 }
hw/baum.c +1 -1
index 18633f4..c856939 100644
@@ -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);
 
hw/xen_backend.c +3 -3
index 2eec0c6..a86e92f 100644
@@ -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;
 }
 
migration-exec.c +3 -3
index 7e2ac0e..76518a6 100644
@@ -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;
 }
migration-fd.c +2 -2
index 056ac3e..8a4c2b8 100644
@@ -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;
 }
migration-tcp.c +2 -2
index d542804..66f126f 100644
@@ -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;
 
migration-unix.c +2 -2
index 44427f8..fe9a820 100644
@@ -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;
 
net/socket.c +3 -3
index b7a21f8..5772202 100644
@@ -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;
 }
 
net/vde.c +1 -1
index fc75e8f..a99dcdf 100644
@@ -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;
 }
qemu-char.c +2 -2
index a87e4e7..43d0758 100644
@@ -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;
 
qemu-char.h +4 -0
index 23305a8..70e4bf9 100644
@@ -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
vl.c +13 -2
index 2d364bb..c855167 100644
@@ -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;
vnc-auth-sasl.c +1 -1
index acaac0c..5b2dd47 100644
@@ -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;
vnc-auth-vencrypt.c +1 -1
index 07c1691..2999c2d 100644
@@ -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;
vnc.c +3 -3
index d15a984..2634dc8 100644
@@ -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);
 }
Signature · 1 line
1.6.6.1
#0 lore raw

cover Clear fd handlers

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(-)
#9 lore raw

PATCH 8/9 remove useless cast

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

---
 migration-exec.c |    2 +-
 migration-fd.c   |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
migration-exec.c +1 -1
index 76518a6..fddbd70 100644
@@ -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;
 }
migration-fd.c +1 -2
index 8a4c2b8..e683a82 100644
@@ -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;
 }
Signature · 1 line
1.6.6.1
#2 lore raw

PATCH 2/9 Introduce qemu_clear_fd_handler()

In reply to Juan Quintela

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

---
 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(-)
audio/alsaaudio.c +2 -2
index 88344ff..4259d9c 100644
@@ -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;
audio/ossaudio.c +3 -3
index 42bffae..97e0f1b 100644
@@ -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;
     }
hw/xen_backend.c +2 -2
index a2e408f..2eec0c6 100644
@@ -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;
migration-exec.c +1 -1
index 3edc026..7e2ac0e 100644
@@ -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();
 
migration-fd.c +1 -1
index 0cc74ad..056ac3e 100644
@@ -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();
 
migration-tcp.c +2 -2
index e7f307c..d542804 100644
@@ -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();
migration-unix.c +2 -2
index b7aab38..44427f8 100644
@@ -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:
migration.c +3 -3
index 05f6cc5..787147a 100644
@@ -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);
 }
net/socket.c +3 -3
index 442a9c7..b7a21f8 100644
@@ -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);
 }
 
net/vde.c +1 -1
index 0b46fa6..fc75e8f 100644
@@ -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);
 }
 
qemu-char.c +11 -11
index 86c7c5a..a87e4e7 100644
@@ -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);
qemu-char.h +1 -0
index bcc0766..23305a8 100644
@@ -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,
usb-linux.c +1 -1
index a9c15c6..b7ac3e9 100644
@@ -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;
vl.c +13 -6
index 83ff652..2d364bb 100644
@@ -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)
vnc.c +2 -2
index 01353a9..d15a984 100644
@@ -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;
     }
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 5/9 Introduce qemu_set_fd_rw_handler()

In reply to Juan Quintela

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

---
 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(-)
aio.c +1 -1
index f164a47..4185233 100644
@@ -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;
 }
qemu-aio.h +2 -2
index 3bdd749..1d2b423 100644
@@ -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,
qemu-char.h +4 -4
index 76cacd9..8d7da54 100644
@@ -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);
qemu-tool.c +4 -5
index 18b48af..25d644f 100644
@@ -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;
 }
vl.c +12 -4
index 6e75347..c061732 100644
@@ -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);
 }
 
vnc-auth-vencrypt.c +1 -1
index 7b3fd57..22f5980 100644
@@ -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);
 
vnc.c +1 -1
index 2634dc8..c945cb9 100644
@@ -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);
Signature · 1 line
1.6.6.1
#4 lore raw

PATCH 4/9 Introduce qemu_set_fd_write_handler()

In reply to Juan Quintela

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

---
 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(-)
audio/alsaaudio.c +2 -2
index 2455ee4..894f02b 100644
@@ -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",
audio/ossaudio.c +1 -1
index 4c91a46..4d0cd36 100644
@@ -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)
migration-tcp.c +1 -1
index 66f126f..c141322 100644
@@ -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) {
migration-unix.c +1 -1
index fe9a820..b50ccb2 100644
@@ -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) {
migration.c +1 -1
index 787147a..c310e4b 100644
@@ -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;
 }
net/socket.c +1 -1
index 5772202..e746b19 100644
@@ -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;
 }
qemu-char.h +3 -1
index 70e4bf9..76cacd9 100644
@@ -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
usb-linux.c +1 -1
index b7ac3e9..9c871ce 100644
@@ -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;
vl.c +11 -0
index c855167..6e75347 100644
@@ -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 */
vnc-auth-vencrypt.c +1 -1
index 2999c2d..7b3fd57 100644
@@ -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));
Signature · 1 line
1.6.6.1
#11 lore raw
In reply to Juan Quintela
Quoted 70 lines · Juan Quintela

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 ++++++++---
Quoted 8 lines
 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?

Signature · 1 line
mailto:[email protected]
#12 lore raw
Quoted 82 lines · malc
Quoted 70 lines · Juan Quintela

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 ++++++++---
Quoted 9 lines
  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(-)
Quoted 2 lines

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

#13 lore raw
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · malc
Quoted 1 line · Juan Quintela

- convert io_handlers to one QLIST

This part removes lines :)

Quoted 2 lines
Quoted 2 lines
Quoted 2 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.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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

Cleanup. same lines.

Quoted 1 line
Quoted 1 line
Quoted 1 line

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

cleanup. same lines.

Quoted 10 lines
Quoted 10 lines
Quoted 10 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);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 2 lines

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.