* [Qemu-devel] [PATCH 1/9] aio: Introduce aio_set_fd_handler_pri
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 2/9] iohandler: Use aio code Fam Zheng
` (8 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
G_IO_PRI event is watched by slirp, add support of that to make future
refactoring possible.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
aio-posix.c | 19 +++++++++++++++++++
aio-win32.c | 10 ++++++++++
include/block/aio.h | 8 ++++++++
3 files changed, 37 insertions(+)
diff --git a/aio-posix.c b/aio-posix.c
index 4abec38..a633c6e 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -23,6 +23,7 @@ struct AioHandler
GPollFD pfd;
IOHandler *io_read;
IOHandler *io_write;
+ IOHandler *io_read_pri;
int deleted;
void *opaque;
QLIST_ENTRY(AioHandler) node;
@@ -47,6 +48,16 @@ void aio_set_fd_handler(AioContext *ctx,
IOHandler *io_write,
void *opaque)
{
+ return aio_set_fd_handler_pri(ctx, fd, io_read, io_write, NULL, opaque);
+}
+
+void aio_set_fd_handler_pri(AioContext *ctx,
+ int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ IOHandler *io_read_pri,
+ void *opaque)
+{
AioHandler *node;
node = find_aio_handler(ctx, fd);
@@ -81,10 +92,12 @@ void aio_set_fd_handler(AioContext *ctx,
/* Update handler with latest information */
node->io_read = io_read;
node->io_write = io_write;
+ node->io_read_pri = io_read_pri;
node->opaque = opaque;
node->pfd.events = (io_read ? G_IO_IN | G_IO_HUP | G_IO_ERR : 0);
node->pfd.events |= (io_write ? G_IO_OUT | G_IO_ERR : 0);
+ node->pfd.events |= (io_read_pri ? G_IO_PRI | G_IO_HUP | G_IO_ERR : 0);
}
aio_notify(ctx);
@@ -151,6 +164,12 @@ bool aio_dispatch(AioContext *ctx)
node->pfd.revents = 0;
if (!node->deleted &&
+ (revents & (G_IO_PRI | G_IO_HUP | G_IO_ERR)) &&
+ node->io_read_pri) {
+ node->io_read_pri(node->opaque);
+ progress = true;
+ }
+ if (!node->deleted &&
(revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
node->io_read) {
node->io_read(node->opaque);
diff --git a/aio-win32.c b/aio-win32.c
index 233d8f5..016cc19 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -37,6 +37,16 @@ void aio_set_fd_handler(AioContext *ctx,
IOHandler *io_write,
void *opaque)
{
+ return aio_set_fd_handler_pri(ctx, fd, io_read, io_write, NULL, opaque);
+}
+
+void aio_set_fd_handler_pri(AioContext *ctx,
+ int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ IOHandler *io_read_pri,
+ void *opaque)
+{
/* fd is a SOCKET in our case */
AioHandler *node;
diff --git a/include/block/aio.h b/include/block/aio.h
index b46103e..82502e1 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -253,6 +253,14 @@ void aio_set_fd_handler(AioContext *ctx,
IOHandler *io_write,
void *opaque);
+/* Like aio_set_fd_handler with an additional G_IO_PRI event handler. */
+void aio_set_fd_handler_pri(AioContext *ctx,
+ int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ IOHandler *io_read_pri,
+ void *opaque);
+
/* Register an event notifier and associated callbacks. Behaves very similarly
* to event_notifier_set_handler. Unlike event_notifier_set_handler, these callbacks
* will be invoked when using aio_poll().
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 2/9] iohandler: Use aio code
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 1/9] aio: Introduce aio_set_fd_handler_pri Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-16 13:57 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-10 8:59 ` [Qemu-devel] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h Fam Zheng
` (7 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
Create a global AioContext instance and let its GSource to handle the
events.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
include/qemu/main-loop.h | 10 +++-
iohandler.c | 124 ++++++++++-------------------------------------
main-loop.c | 5 +-
3 files changed, 37 insertions(+), 102 deletions(-)
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 0f4a0fd..05f8b34 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -203,6 +203,14 @@ void qemu_set_fd_handler(int fd,
IOHandler *fd_write,
void *opaque);
+/* Like qemu_set_fd_handler, while also watch for G_IO_PRI event. */
+void qemu_set_fd_handler_pri(int fd,
+ IOHandler *fd_read,
+ IOHandler *fd_write,
+ IOHandler *fd_read_pri,
+ void *opaque);
+
+GSource *iohandler_get_g_source(void);
#ifdef CONFIG_POSIX
/**
* qemu_add_child_watch: Register a child process for reaping.
@@ -255,8 +263,6 @@ void qemu_mutex_unlock_iothread(void);
/* internal interfaces */
void qemu_fd_register(int fd);
-void qemu_iohandler_fill(GArray *pollfds);
-void qemu_iohandler_poll(GArray *pollfds, int rc);
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
void qemu_bh_schedule_idle(QEMUBH *bh);
diff --git a/iohandler.c b/iohandler.c
index 826f713..f5d7704 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -32,111 +32,39 @@
#include <sys/wait.h>
#endif
-typedef struct IOHandlerRecord {
- IOHandler *fd_read;
- IOHandler *fd_write;
- void *opaque;
- QLIST_ENTRY(IOHandlerRecord) next;
- int fd;
- int pollfds_idx;
- bool deleted;
-} IOHandlerRecord;
+static AioContext *iohandler_ctx;
-static QLIST_HEAD(, IOHandlerRecord) io_handlers =
- QLIST_HEAD_INITIALIZER(io_handlers);
+static void iohandler_init(void)
+{
+ if (!iohandler_ctx) {
+ iohandler_ctx = aio_context_new(&error_abort);
+ }
+}
+
+GSource *iohandler_get_g_source(void)
+{
+ iohandler_init();
+ return aio_get_g_source(iohandler_ctx);
+}
+
+void qemu_set_fd_handler_pri(int fd,
+ IOHandler *fd_read,
+ IOHandler *fd_write,
+ IOHandler *fd_read_pri,
+ void *opaque)
+{
+ iohandler_init();
+ aio_set_fd_handler_pri(iohandler_ctx, fd, fd_read,
+ fd_write, fd_read_pri, opaque);
+}
void qemu_set_fd_handler(int fd,
IOHandler *fd_read,
IOHandler *fd_write,
void *opaque)
{
- IOHandlerRecord *ioh;
-
- assert(fd >= 0);
-
- if (!fd_read && !fd_write) {
- QLIST_FOREACH(ioh, &io_handlers, next) {
- if (ioh->fd == fd) {
- ioh->deleted = 1;
- break;
- }
- }
- } else {
- QLIST_FOREACH(ioh, &io_handlers, next) {
- if (ioh->fd == fd)
- goto found;
- }
- ioh = g_malloc0(sizeof(IOHandlerRecord));
- QLIST_INSERT_HEAD(&io_handlers, ioh, next);
- found:
- ioh->fd = fd;
- ioh->fd_read = fd_read;
- ioh->fd_write = fd_write;
- ioh->opaque = opaque;
- ioh->pollfds_idx = -1;
- ioh->deleted = 0;
- qemu_notify_event();
- }
-}
-
-void qemu_iohandler_fill(GArray *pollfds)
-{
- IOHandlerRecord *ioh;
-
- QLIST_FOREACH(ioh, &io_handlers, next) {
- int events = 0;
-
- if (ioh->deleted)
- continue;
- if (ioh->fd_read) {
- events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
- }
- if (ioh->fd_write) {
- events |= G_IO_OUT | G_IO_ERR;
- }
- if (events) {
- GPollFD pfd = {
- .fd = ioh->fd,
- .events = events,
- };
- ioh->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- } else {
- ioh->pollfds_idx = -1;
- }
- }
-}
-
-void qemu_iohandler_poll(GArray *pollfds, int ret)
-{
- if (ret > 0) {
- IOHandlerRecord *pioh, *ioh;
-
- QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
- int revents = 0;
-
- if (!ioh->deleted && ioh->pollfds_idx != -1) {
- GPollFD *pfd = &g_array_index(pollfds, GPollFD,
- ioh->pollfds_idx);
- revents = pfd->revents;
- }
-
- if (!ioh->deleted && ioh->fd_read &&
- (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) {
- ioh->fd_read(ioh->opaque);
- }
- if (!ioh->deleted && ioh->fd_write &&
- (revents & (G_IO_OUT | G_IO_ERR))) {
- ioh->fd_write(ioh->opaque);
- }
-
- /* Do this last in case read/write handlers marked it for deletion */
- if (ioh->deleted) {
- QLIST_REMOVE(ioh, next);
- g_free(ioh);
- }
- }
- }
+ iohandler_init();
+ aio_set_fd_handler(iohandler_ctx, fd, fd_read, fd_write, opaque);
}
/* reaping of zombies. right now we're not passing the status to
diff --git a/main-loop.c b/main-loop.c
index 82875a4..631caa0 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -152,6 +152,9 @@ int qemu_init_main_loop(Error **errp)
src = aio_get_g_source(qemu_aio_context);
g_source_attach(src, NULL);
g_source_unref(src);
+ src = iohandler_get_g_source();
+ g_source_attach(src, NULL);
+ g_source_unref(src);
return 0;
}
@@ -478,7 +481,6 @@ int main_loop_wait(int nonblocking)
#ifdef CONFIG_SLIRP
slirp_pollfds_fill(gpollfds, &timeout);
#endif
- qemu_iohandler_fill(gpollfds);
if (timeout == UINT32_MAX) {
timeout_ns = -1;
@@ -491,7 +493,6 @@ int main_loop_wait(int nonblocking)
&main_loop_tlg));
ret = os_host_main_loop_wait(timeout_ns);
- qemu_iohandler_poll(gpollfds, ret);
#ifdef CONFIG_SLIRP
slirp_pollfds_poll(gpollfds, (ret < 0));
#endif
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 2/9] iohandler: Use aio code
2015-06-10 8:59 ` [Qemu-devel] [PATCH 2/9] iohandler: Use aio code Fam Zheng
@ 2015-06-16 13:57 ` Stefan Hajnoczi
2015-06-19 1:05 ` Fam Zheng
0 siblings, 1 reply; 17+ messages in thread
From: Stefan Hajnoczi @ 2015-06-16 13:57 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 640 bytes --]
On Wed, Jun 10, 2015 at 04:59:44PM +0800, Fam Zheng wrote:
> diff --git a/iohandler.c b/iohandler.c
> index 826f713..f5d7704 100644
> --- a/iohandler.c
> +++ b/iohandler.c
> @@ -32,111 +32,39 @@
> #include <sys/wait.h>
> #endif
>
> -typedef struct IOHandlerRecord {
> - IOHandler *fd_read;
> - IOHandler *fd_write;
> - void *opaque;
> - QLIST_ENTRY(IOHandlerRecord) next;
> - int fd;
> - int pollfds_idx;
> - bool deleted;
> -} IOHandlerRecord;
> +static AioContext *iohandler_ctx;
Please include a comment explaining why this AioContext is needed in
addition to the global qemu_aio_context.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 2/9] iohandler: Use aio code
2015-06-16 13:57 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
@ 2015-06-19 1:05 ` Fam Zheng
0 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-19 1:05 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
On Tue, 06/16 14:57, Stefan Hajnoczi wrote:
> On Wed, Jun 10, 2015 at 04:59:44PM +0800, Fam Zheng wrote:
> > diff --git a/iohandler.c b/iohandler.c
> > index 826f713..f5d7704 100644
> > --- a/iohandler.c
> > +++ b/iohandler.c
> > @@ -32,111 +32,39 @@
> > #include <sys/wait.h>
> > #endif
> >
> > -typedef struct IOHandlerRecord {
> > - IOHandler *fd_read;
> > - IOHandler *fd_write;
> > - void *opaque;
> > - QLIST_ENTRY(IOHandlerRecord) next;
> > - int fd;
> > - int pollfds_idx;
> > - bool deleted;
> > -} IOHandlerRecord;
> > +static AioContext *iohandler_ctx;
>
> Please include a comment explaining why this AioContext is needed in
> addition to the global qemu_aio_context.
OK!
It's needed because iohandlers shouldn't be polled by aio_poll().
Fam
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 1/9] aio: Introduce aio_set_fd_handler_pri Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 2/9] iohandler: Use aio code Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-16 13:58 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-10 8:59 ` [Qemu-devel] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN" Fam Zheng
` (6 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
Signed-off-by: Fam Zheng <famz@redhat.com>
---
main-loop.c | 1 -
slirp/libslirp.h | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/main-loop.c b/main-loop.c
index 631caa0..18b7508 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -24,7 +24,6 @@
#include "qemu-common.h"
#include "qemu/timer.h"
-#include "qemu/sockets.h" // struct in_addr needed for libslirp.h
#include "sysemu/qtest.h"
#include "slirp/libslirp.h"
#include "qemu/main-loop.h"
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 5bdcbd5..7f329d9 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -2,6 +2,7 @@
#define _LIBSLIRP_H
#include "qemu-common.h"
+#include "qemu/sockets.h"
struct Slirp;
typedef struct Slirp Slirp;
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h
2015-06-10 8:59 ` [Qemu-devel] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h Fam Zheng
@ 2015-06-16 13:58 ` Stefan Hajnoczi
0 siblings, 0 replies; 17+ messages in thread
From: Stefan Hajnoczi @ 2015-06-16 13:58 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 264 bytes --]
On Wed, Jun 10, 2015 at 04:59:45PM +0800, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> main-loop.c | 1 -
> slirp/libslirp.h | 1 +
> 2 files changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN"
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (2 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 3/9] main-loop: Move include of "qemu/sockets.h" to libslirp.h Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-16 14:00 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-06-10 8:59 ` [Qemu-devel] [PATCH 5/9] slirp: Add "poll_events" to struct socket Fam Zheng
` (5 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
It has always been compiled out. Remove it before we refactor the rest
part of slirp poll.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/slirp.c | 40 ----------------------------------------
slirp/slirp_config.h | 4 ----
2 files changed, 44 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 35f819a..25cdca6 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -578,46 +578,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
* a window probe to get things going again
*/
}
-
- /*
- * Probe a still-connecting, non-blocking socket
- * to check if it's still alive
- */
-#ifdef PROBE_CONN
- if (so->so_state & SS_ISFCONNECTING) {
- ret = qemu_recv(so->s, &ret, 0, 0);
-
- if (ret < 0) {
- /* XXX */
- if (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINPROGRESS || errno == ENOTCONN) {
- continue; /* Still connecting, continue */
- }
-
- /* else failed */
- so->so_state &= SS_PERSISTENT_MASK;
- so->so_state |= SS_NOFDREF;
-
- /* tcp_input will take care of it */
- } else {
- ret = send(so->s, &ret, 0, 0);
- if (ret < 0) {
- /* XXX */
- if (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINPROGRESS || errno == ENOTCONN) {
- continue;
- }
- /* else failed */
- so->so_state &= SS_PERSISTENT_MASK;
- so->so_state |= SS_NOFDREF;
- } else {
- so->so_state &= ~SS_ISFCONNECTING;
- }
-
- }
- tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);
- } /* SS_ISFCONNECTING */
-#endif
}
/*
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 896d802..70563ae 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -2,10 +2,6 @@
* User definable configuration options
*/
-/* Define if you want the connection to be probed */
-/* XXX Not working yet, so ignore this for now */
-#undef PROBE_CONN
-
/* Define to 1 if you want KEEPALIVE timers */
#define DO_KEEPALIVE 0
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN"
2015-06-10 8:59 ` [Qemu-devel] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN" Fam Zheng
@ 2015-06-16 14:00 ` Stefan Hajnoczi
0 siblings, 0 replies; 17+ messages in thread
From: Stefan Hajnoczi @ 2015-06-16 14:00 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 411 bytes --]
On Wed, Jun 10, 2015 at 04:59:46PM +0800, Fam Zheng wrote:
> It has always been compiled out. Remove it before we refactor the rest
> part of slirp poll.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> slirp/slirp.c | 40 ----------------------------------------
> slirp/slirp_config.h | 4 ----
> 2 files changed, 44 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 5/9] slirp: Add "poll_events" to struct socket
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (3 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 4/9] slirp: Remove dead code for "PROBE_CONN" Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 6/9] slirp: Move icmp socket to iohandler Fam Zheng
` (4 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
The field stores the current interesting events.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/socket.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/slirp/socket.h b/slirp/socket.h
index 57e0407..0c49770 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -53,6 +53,7 @@ struct socket {
struct sbuf so_rcv; /* Receive buffer */
struct sbuf so_snd; /* Send buffer */
void * extra; /* Extra pointer */
+ int poll_events;
};
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 6/9] slirp: Move icmp socket to iohandler
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (4 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 5/9] slirp: Add "poll_events" to struct socket Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 7/9] slirp: Move udb " Fam Zheng
` (3 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
Where the fd was added, compare the events with so->poll_events and call
qemu_set_fd_handler() to update if it's changed. Where the fd was not added,
call qemu_set_fd_handler() to remove it. Update slirp->do_slowtimo with a
return value. For simplicity, G_IO_HUP and G_IO_ERR are unnecessary to be
explicitly stated here, because they're implied in qemu_set_fd_handler.
For poll part, iohandler will call the read handler when there is an event, so
the check in slirp_pollfds_poll() is removed.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/slirp.c | 83 ++++++++++++++++++++++++++++-------------------------------
1 file changed, 39 insertions(+), 44 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 25cdca6..f648e6c 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -286,6 +286,44 @@ static void slirp_update_timeout(uint32_t *timeout)
*timeout = t;
}
+static void slirp_icmp_read(void *opaque)
+{
+ struct socket *so = opaque;
+ icmp_receive(so);
+}
+
+static bool slirp_poll_update_icmp(struct socket *so)
+{
+ bool ret = false;
+ bool old, new;
+ /*
+ * See if it's timed out
+ */
+ if (so->so_expire) {
+ if (so->so_expire <= curtime) {
+ icmp_detach(so);
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ return ret;
+ } else {
+ ret = true; /* Let socket expire */
+ }
+ }
+
+ old = so->poll_events == G_IO_IN;
+ new = !!(so->so_state & SS_ISFCONNECTED);
+ if (old != new) {
+ /* Need update */
+ if (new) {
+ so->poll_events = G_IO_IN;
+ qemu_set_fd_handler(so->s, slirp_icmp_read, NULL, so);
+ } else {
+ so->poll_events = 0;
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ }
+ }
+ return ret;
+}
+
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
{
Slirp *slirp;
@@ -431,29 +469,7 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
for (so = slirp->icmp.so_next; so != &slirp->icmp;
so = so_next) {
so_next = so->so_next;
-
- so->pollfds_idx = -1;
-
- /*
- * See if it's timed out
- */
- if (so->so_expire) {
- if (so->so_expire <= curtime) {
- icmp_detach(so);
- continue;
- } else {
- slirp->do_slowtimo = true; /* Let socket expire */
- }
- }
-
- if (so->so_state & SS_ISFCONNECTED) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- }
+ slirp->do_slowtimo |= slirp_poll_update_icmp(so);
}
}
slirp_update_timeout(timeout);
@@ -602,27 +618,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
sorecvfrom(so);
}
}
-
- /*
- * Check incoming ICMP relies.
- */
- for (so = slirp->icmp.so_next; so != &slirp->icmp;
- so = so_next) {
- int revents;
-
- so_next = so->so_next;
-
- revents = 0;
- if (so->pollfds_idx != -1) {
- revents = g_array_index(pollfds, GPollFD,
- so->pollfds_idx).revents;
- }
-
- if (so->s != -1 &&
- (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) {
- icmp_receive(so);
- }
- }
}
if_start(slirp);
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 7/9] slirp: Move udb socket to iohandler
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (5 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 6/9] slirp: Move icmp socket to iohandler Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 8/9] slirp: Move tcb " Fam Zheng
` (2 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
This change is a replicate of the previous one.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/slirp.c | 95 ++++++++++++++++++++++++-----------------------------------
1 file changed, 39 insertions(+), 56 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index f648e6c..a031240 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -286,6 +286,44 @@ static void slirp_update_timeout(uint32_t *timeout)
*timeout = t;
}
+static void slirp_udb_read(void *opaque)
+{
+ struct socket *so = opaque;
+ sorecvfrom(so);
+}
+
+static bool slirp_poll_update_udb(struct socket *so)
+{
+ bool ret = false;
+ bool old, new;
+ /*
+ * See if it's timed out
+ */
+ if (so->so_expire) {
+ if (so->so_expire <= curtime) {
+ udp_detach(so);
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ return ret;
+ } else {
+ ret = true;
+ }
+ }
+
+ new = so->so_state & SS_ISFCONNECTED && so->so_queued <= 4;
+ old = so->poll_events == G_IO_IN;
+ if (old != new) {
+ /* Need update */
+ if (new) {
+ so->poll_events = G_IO_IN;
+ qemu_set_fd_handler(so->s, slirp_udb_read, NULL, so);
+ } else {
+ so->poll_events = 0;
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ }
+ }
+ return ret;
+}
+
static void slirp_icmp_read(void *opaque)
{
struct socket *so = opaque;
@@ -428,39 +466,7 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
for (so = slirp->udb.so_next; so != &slirp->udb;
so = so_next) {
so_next = so->so_next;
-
- so->pollfds_idx = -1;
-
- /*
- * See if it's timed out
- */
- if (so->so_expire) {
- if (so->so_expire <= curtime) {
- udp_detach(so);
- continue;
- } else {
- slirp->do_slowtimo = true; /* Let socket expire */
- }
- }
-
- /*
- * When UDP packets are received from over the
- * link, they're sendto()'d straight away, so
- * no need for setting for writing
- * Limit the number of packets queued by this session
- * to 4. Note that even though we try and limit this
- * to 4 packets, the session could have more queued
- * if the packets needed to be fragmented
- * (XXX <= 4 ?)
- */
- if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- }
+ slirp->do_slowtimo |= slirp_poll_update_udb(so);
}
/*
@@ -595,29 +601,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
*/
}
}
-
- /*
- * Now UDP sockets.
- * Incoming packets are sent straight away, they're not buffered.
- * Incoming UDP data isn't buffered either.
- */
- for (so = slirp->udb.so_next; so != &slirp->udb;
- so = so_next) {
- int revents;
-
- so_next = so->so_next;
-
- revents = 0;
- if (so->pollfds_idx != -1) {
- revents = g_array_index(pollfds, GPollFD,
- so->pollfds_idx).revents;
- }
-
- if (so->s != -1 &&
- (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) {
- sorecvfrom(so);
- }
- }
}
if_start(slirp);
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 8/9] slirp: Move tcb socket to iohandler
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (6 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 7/9] slirp: Move udb " Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-10 8:59 ` [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list Fam Zheng
2015-06-16 14:16 ` [Qemu-devel] [Qemu-block] [PATCH 0/9] slirp: iohandler: Rebase onto aio Stefan Hajnoczi
9 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
This change is a replicate of the previous two, just the calculation of polled
events is more delicate, and both read and write are polled.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
slirp/slirp.c | 310 ++++++++++++++++++++++++++--------------------------------
1 file changed, 140 insertions(+), 170 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index a031240..4cfa190 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -286,6 +286,143 @@ static void slirp_update_timeout(uint32_t *timeout)
*timeout = t;
}
+static void slirp_tcb_read_oob(void *opaque)
+{
+ struct socket *so = opaque;
+ sorecvoob(so);
+}
+
+static void slirp_tcb_read(void *opaque)
+{
+ int ret;
+ struct socket *so = opaque;
+
+ if (so->so_state & SS_NOFDREF) {
+ return;
+ }
+ /*
+ * Check for incoming connections
+ */
+ if (so->so_state & SS_FACCEPTCONN) {
+ tcp_connect(so);
+ } else {
+ ret = soread(so);
+
+ /* Output it if we read something */
+ if (ret > 0) {
+ tcp_output(sototcpcb(so));
+ }
+ }
+}
+
+static void slirp_tcb_write(void *opaque)
+{
+ int ret;
+ struct socket *so = opaque;
+
+ if (so->so_state & SS_NOFDREF) {
+ return;
+ }
+ /*
+ * Check for non-blocking, still-connecting sockets
+ */
+ if (so->so_state & SS_ISFCONNECTING) {
+ /* Connected */
+ so->so_state &= ~SS_ISFCONNECTING;
+
+ ret = send(so->s, (const void *) &ret, 0, 0);
+ if (ret < 0) {
+ /* XXXXX Must fix, zero bytes is a NOP */
+ if (errno == EAGAIN || errno == EWOULDBLOCK ||
+ errno == EINPROGRESS || errno == ENOTCONN) {
+ return;
+ }
+
+ /* else failed */
+ so->so_state &= SS_PERSISTENT_MASK;
+ so->so_state |= SS_NOFDREF;
+ }
+ /* else so->so_state &= ~SS_ISFCONNECTING; */
+
+ /*
+ * Continue tcp_input
+ */
+ tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);
+ /* continue; */
+ } else {
+ sowrite(so);
+ }
+ /*
+ * XXXXX If we wrote something (a lot), there
+ * could be a need for a window update.
+ * In the worst case, the remote will send
+ * a window probe to get things going again
+ */
+}
+
+static bool slirp_poll_update_tcb(struct socket *so)
+{
+ int events = 0;
+ Slirp *slirp = so->slirp;
+
+ /*
+ * See if we need a tcp_fasttimo
+ */
+ if (slirp->time_fasttimo == 0 &&
+ so->so_tcpcb->t_flags & TF_DELACK) {
+ slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */
+ }
+
+ /*
+ * NOFDREF can include still connecting to local-host,
+ * newly socreated() sockets etc. Don't want to select these.
+ */
+ if (so->so_state & SS_NOFDREF || so->s == -1) {
+ so->poll_events = 0;
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
+ return false;
+ }
+
+ if (so->so_state & SS_FACCEPTCONN) {
+ /*
+ * Set for reading sockets which are accepting
+ */
+ events = G_IO_IN;
+ } else if (so->so_state & SS_ISFCONNECTING) {
+ /*
+ * Set for writing sockets which are connecting
+ */
+ events = G_IO_OUT;
+ }
+
+ /*
+ * Set for writing if we are connected, can send more, and
+ * we have something to send
+ */
+ if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) {
+ events |= G_IO_OUT;
+ }
+
+ /*
+ * Set for reading (and urgent data) if we are connected, can
+ * receive more, and we have room for it XXX /2 ?
+ */
+ if (CONN_CANFRCV(so) &&
+ (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2))) {
+ events |= G_IO_IN | G_IO_PRI;
+ }
+
+ if (events != so->poll_events) {
+ so->poll_events = events;
+ qemu_set_fd_handler_pri(so->s,
+ events & G_IO_IN ? slirp_tcb_read : NULL,
+ events & G_IO_OUT ? slirp_tcb_write : NULL,
+ events & G_IO_PRI ? slirp_tcb_read_oob : NULL,
+ so);
+ }
+ return false;
+}
+
static void slirp_udb_read(void *opaque)
{
struct socket *so = opaque;
@@ -301,8 +438,8 @@ static bool slirp_poll_update_udb(struct socket *so)
*/
if (so->so_expire) {
if (so->so_expire <= curtime) {
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
udp_detach(so);
- qemu_set_fd_handler(so->s, NULL, NULL, NULL);
return ret;
} else {
ret = true;
@@ -339,8 +476,8 @@ static bool slirp_poll_update_icmp(struct socket *so)
*/
if (so->so_expire) {
if (so->so_expire <= curtime) {
+ qemu_set_fd_handler(so->s, NULL, NULL, NULL);
icmp_detach(so);
- qemu_set_fd_handler(so->s, NULL, NULL, NULL);
return ret;
} else {
ret = true; /* Let socket expire */
@@ -385,79 +522,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
for (so = slirp->tcb.so_next; so != &slirp->tcb;
so = so_next) {
- int events = 0;
-
so_next = so->so_next;
-
- so->pollfds_idx = -1;
-
- /*
- * See if we need a tcp_fasttimo
- */
- if (slirp->time_fasttimo == 0 &&
- so->so_tcpcb->t_flags & TF_DELACK) {
- slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */
- }
-
- /*
- * NOFDREF can include still connecting to local-host,
- * newly socreated() sockets etc. Don't want to select these.
- */
- if (so->so_state & SS_NOFDREF || so->s == -1) {
- continue;
- }
-
- /*
- * Set for reading sockets which are accepting
- */
- if (so->so_state & SS_FACCEPTCONN) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- continue;
- }
-
- /*
- * Set for writing sockets which are connecting
- */
- if (so->so_state & SS_ISFCONNECTING) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_OUT | G_IO_ERR,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- continue;
- }
-
- /*
- * Set for writing if we are connected, can send more, and
- * we have something to send
- */
- if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) {
- events |= G_IO_OUT | G_IO_ERR;
- }
-
- /*
- * Set for reading (and urgent data) if we are connected, can
- * receive more, and we have room for it XXX /2 ?
- */
- if (CONN_CANFRCV(so) &&
- (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2))) {
- events |= G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
- }
-
- if (events) {
- GPollFD pfd = {
- .fd = so->s,
- .events = events,
- };
- so->pollfds_idx = pollfds->len;
- g_array_append_val(pollfds, pfd);
- }
+ slirp->do_slowtimo |= slirp_poll_update_tcb(so);
}
/*
@@ -484,8 +550,6 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
void slirp_pollfds_poll(GArray *pollfds, int select_error)
{
Slirp *slirp;
- struct socket *so, *so_next;
- int ret;
if (QTAILQ_EMPTY(&slirp_instances)) {
return;
@@ -509,100 +573,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
slirp->last_slowtimo = curtime;
}
- /*
- * Check sockets
- */
- if (!select_error) {
- /*
- * Check TCP sockets
- */
- for (so = slirp->tcb.so_next; so != &slirp->tcb;
- so = so_next) {
- int revents;
-
- so_next = so->so_next;
-
- revents = 0;
- if (so->pollfds_idx != -1) {
- revents = g_array_index(pollfds, GPollFD,
- so->pollfds_idx).revents;
- }
-
- if (so->so_state & SS_NOFDREF || so->s == -1) {
- continue;
- }
-
- /*
- * Check for URG data
- * This will soread as well, so no need to
- * test for G_IO_IN below if this succeeds
- */
- if (revents & G_IO_PRI) {
- sorecvoob(so);
- }
- /*
- * Check sockets for reading
- */
- else if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) {
- /*
- * Check for incoming connections
- */
- if (so->so_state & SS_FACCEPTCONN) {
- tcp_connect(so);
- continue;
- } /* else */
- ret = soread(so);
-
- /* Output it if we read something */
- if (ret > 0) {
- tcp_output(sototcpcb(so));
- }
- }
-
- /*
- * Check sockets for writing
- */
- if (!(so->so_state & SS_NOFDREF) &&
- (revents & (G_IO_OUT | G_IO_ERR))) {
- /*
- * Check for non-blocking, still-connecting sockets
- */
- if (so->so_state & SS_ISFCONNECTING) {
- /* Connected */
- so->so_state &= ~SS_ISFCONNECTING;
-
- ret = send(so->s, (const void *) &ret, 0, 0);
- if (ret < 0) {
- /* XXXXX Must fix, zero bytes is a NOP */
- if (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINPROGRESS || errno == ENOTCONN) {
- continue;
- }
-
- /* else failed */
- so->so_state &= SS_PERSISTENT_MASK;
- so->so_state |= SS_NOFDREF;
- }
- /* else so->so_state &= ~SS_ISFCONNECTING; */
-
- /*
- * Continue tcp_input
- */
- tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);
- /* continue; */
- } else {
- ret = sowrite(so);
- }
- /*
- * XXXXX If we wrote something (a lot), there
- * could be a need for a window update.
- * In the worst case, the remote will send
- * a window probe to get things going again
- */
- }
- }
- }
-
if_start(slirp);
}
}
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (7 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 8/9] slirp: Move tcb " Fam Zheng
@ 2015-06-10 8:59 ` Fam Zheng
2015-06-16 14:15 ` Stefan Hajnoczi
2015-06-16 14:16 ` [Qemu-devel] [Qemu-block] [PATCH 0/9] slirp: iohandler: Rebase onto aio Stefan Hajnoczi
9 siblings, 1 reply; 17+ messages in thread
From: Fam Zheng @ 2015-06-10 8:59 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, qemu-block, Stefan Weil, Stefan Hajnoczi, Jan Kiszka,
Paolo Bonzini
Signed-off-by: Fam Zheng <famz@redhat.com>
---
main-loop.c | 4 ++--
slirp/libslirp.h | 4 ++--
slirp/slirp.c | 4 ++--
stubs/slirp.c | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/main-loop.c b/main-loop.c
index 18b7508..b3808ae 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -478,7 +478,7 @@ int main_loop_wait(int nonblocking)
g_array_set_size(gpollfds, 0); /* reset for new iteration */
/* XXX: separate device handlers from system ones */
#ifdef CONFIG_SLIRP
- slirp_pollfds_fill(gpollfds, &timeout);
+ slirp_poll_prepare(&timeout);
#endif
if (timeout == UINT32_MAX) {
@@ -493,7 +493,7 @@ int main_loop_wait(int nonblocking)
ret = os_host_main_loop_wait(timeout_ns);
#ifdef CONFIG_SLIRP
- slirp_pollfds_poll(gpollfds, (ret < 0));
+ slirp_poll();
#endif
qemu_clock_run_all_timers();
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 7f329d9..94032ba 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -17,9 +17,9 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
void *opaque);
void slirp_cleanup(Slirp *slirp);
-void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
+void slirp_poll_prepare(uint32_t *timeout);
-void slirp_pollfds_poll(GArray *pollfds, int select_error);
+void slirp_poll(void);
void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 4cfa190..bd80708 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -499,7 +499,7 @@ static bool slirp_poll_update_icmp(struct socket *so)
return ret;
}
-void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
+void slirp_poll_prepare(uint32_t *timeout)
{
Slirp *slirp;
struct socket *so, *so_next;
@@ -547,7 +547,7 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
slirp_update_timeout(timeout);
}
-void slirp_pollfds_poll(GArray *pollfds, int select_error)
+void slirp_poll(void)
{
Slirp *slirp;
diff --git a/stubs/slirp.c b/stubs/slirp.c
index bd0ac7f..6b6d211 100644
--- a/stubs/slirp.c
+++ b/stubs/slirp.c
@@ -1,11 +1,11 @@
#include "qemu-common.h"
#include "slirp/slirp.h"
-void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
+void slirp_poll_prepare(uint32_t *timeout)
{
}
-void slirp_pollfds_poll(GArray *pollfds, int select_error)
+void slirp_poll(void)
{
}
--
2.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list
2015-06-10 8:59 ` [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list Fam Zheng
@ 2015-06-16 14:15 ` Stefan Hajnoczi
2015-06-19 1:03 ` Fam Zheng
0 siblings, 1 reply; 17+ messages in thread
From: Stefan Hajnoczi @ 2015-06-16 14:15 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 1541 bytes --]
On Wed, Jun 10, 2015 at 04:59:51PM +0800, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> main-loop.c | 4 ++--
> slirp/libslirp.h | 4 ++--
> slirp/slirp.c | 4 ++--
> stubs/slirp.c | 4 ++--
> 4 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/main-loop.c b/main-loop.c
> index 18b7508..b3808ae 100644
> --- a/main-loop.c
> +++ b/main-loop.c
> @@ -478,7 +478,7 @@ int main_loop_wait(int nonblocking)
> g_array_set_size(gpollfds, 0); /* reset for new iteration */
> /* XXX: separate device handlers from system ones */
> #ifdef CONFIG_SLIRP
> - slirp_pollfds_fill(gpollfds, &timeout);
> + slirp_poll_prepare(&timeout);
> #endif
>
> if (timeout == UINT32_MAX) {
> @@ -493,7 +493,7 @@ int main_loop_wait(int nonblocking)
>
> ret = os_host_main_loop_wait(timeout_ns);
> #ifdef CONFIG_SLIRP
> - slirp_pollfds_poll(gpollfds, (ret < 0));
> + slirp_poll();
The final step is to remove slirp calls completely from
main_loop_wait(). slirp should use the qemu_set_fd_handler() and timer
APIs directly instead of requiring callbacks around ppoll().
That would probably even make the slirp code simpler since it currently
splits evented I/O into two phases:
1. Set slirp-internal state
2. Reflect slirp-internal state into iohandler and check timeouts after
ppoll()
If slirp calls the appropriate qemu_set_fd_handler() and timer APIs
*during* state transitions it won't have to use the two-step approach.
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list
2015-06-16 14:15 ` Stefan Hajnoczi
@ 2015-06-19 1:03 ` Fam Zheng
0 siblings, 0 replies; 17+ messages in thread
From: Fam Zheng @ 2015-06-19 1:03 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
On Tue, 06/16 15:15, Stefan Hajnoczi wrote:
> On Wed, Jun 10, 2015 at 04:59:51PM +0800, Fam Zheng wrote:
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > main-loop.c | 4 ++--
> > slirp/libslirp.h | 4 ++--
> > slirp/slirp.c | 4 ++--
> > stubs/slirp.c | 4 ++--
> > 4 files changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/main-loop.c b/main-loop.c
> > index 18b7508..b3808ae 100644
> > --- a/main-loop.c
> > +++ b/main-loop.c
> > @@ -478,7 +478,7 @@ int main_loop_wait(int nonblocking)
> > g_array_set_size(gpollfds, 0); /* reset for new iteration */
> > /* XXX: separate device handlers from system ones */
> > #ifdef CONFIG_SLIRP
> > - slirp_pollfds_fill(gpollfds, &timeout);
> > + slirp_poll_prepare(&timeout);
> > #endif
> >
> > if (timeout == UINT32_MAX) {
> > @@ -493,7 +493,7 @@ int main_loop_wait(int nonblocking)
> >
> > ret = os_host_main_loop_wait(timeout_ns);
> > #ifdef CONFIG_SLIRP
> > - slirp_pollfds_poll(gpollfds, (ret < 0));
> > + slirp_poll();
>
> The final step is to remove slirp calls completely from
> main_loop_wait(). slirp should use the qemu_set_fd_handler() and timer
> APIs directly instead of requiring callbacks around ppoll().
>
> That would probably even make the slirp code simpler since it currently
> splits evented I/O into two phases:
> 1. Set slirp-internal state
> 2. Reflect slirp-internal state into iohandler and check timeouts after
> ppoll()
>
> If slirp calls the appropriate qemu_set_fd_handler() and timer APIs
> *during* state transitions it won't have to use the two-step approach.
Yes, that's right, but it is a harder change that I want to leave for a
separate series.
Fam
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH 0/9] slirp: iohandler: Rebase onto aio
2015-06-10 8:59 [Qemu-devel] [PATCH 0/9] slirp: iohandler: Rebase onto aio Fam Zheng
` (8 preceding siblings ...)
2015-06-10 8:59 ` [Qemu-devel] [PATCH 9/9] slirp: Remove unused pollfds from the parameter list Fam Zheng
@ 2015-06-16 14:16 ` Stefan Hajnoczi
9 siblings, 0 replies; 17+ messages in thread
From: Stefan Hajnoczi @ 2015-06-16 14:16 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, qemu-block, Stefan Weil, qemu-devel, Stefan Hajnoczi,
Jan Kiszka, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]
On Wed, Jun 10, 2015 at 04:59:42PM +0800, Fam Zheng wrote:
> Currently iohandler.c and asyn.c has a lot in common, except that iohandler is
> hooked into main_loop_wait(), with qemu_iohandler_fill(). Likewise for slirp.
>
> It is much cleaner to drive slirp fds with iohandler, and implement
> iohandler with an AioContext. This series does these two things. It applies to
> Stefan's net-next tree which has the prerequisite that removes the obstacle
> "qemu_set_fd_handler2" for this convergence:
>
> http://comments.gmane.org/gmane.comp.emulators.qemu/341526
>
> Upon that this series makes a more consistent main loop structure, and will
> also benefits future work on event loop, such as introducing of epoll and
> possibly in the long run moving things to separate iothread (whose event loop
> is based on AioContext too).
>
>
> Fam Zheng (9):
> aio: Introduce aio_set_fd_handler_pri
> iohandler: Use aio code
> main-loop: Move include of "qemu/sockets.h" to libslirp.h
> slirp: Remove dead code for "PROBE_CONN"
> slirp: Add "poll_events" to struct socket
> slirp: Move icmp socket to iohandler
> slirp: Move udb socket to iohandler
> slirp: Move tcb socket to iohandler
> slirp: Remove unused pollfds from the parameter list
>
> aio-posix.c | 19 ++
> aio-win32.c | 10 +
> include/block/aio.h | 8 +
> include/qemu/main-loop.h | 10 +-
> iohandler.c | 124 +++--------
> main-loop.c | 10 +-
> slirp/libslirp.h | 5 +-
> slirp/slirp.c | 528 +++++++++++++++++++----------------------------
> slirp/slirp_config.h | 4 -
> slirp/socket.h | 1 +
> stubs/slirp.c | 4 +-
> 11 files changed, 300 insertions(+), 423 deletions(-)
Pinging Jan Kiszka for slirp changes.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread