All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] yield_until_fd_readable: make it work with any AioContect
@ 2019-10-21  8:50 Dietmar Maurer
  2019-10-23 14:22 ` Stefan Hajnoczi
  0 siblings, 1 reply; 3+ messages in thread
From: Dietmar Maurer @ 2019-10-21  8:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Dietmar Maurer, stefanha

Simply use qemu_get_current_aio_context().

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---

Changelog for v3:

- use (IOHandler *) instead of ((void (*)(void *))
- coding style: fix max line length

Changelog for v2:

- use correct read handler in aio_set_fd_handler (instead of write handler)

 util/qemu-coroutine-io.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c
index 44a8969a69..dbbe817464 100644
--- a/util/qemu-coroutine-io.c
+++ b/util/qemu-coroutine-io.c
@@ -66,25 +66,12 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send)
     return qemu_co_sendv_recvv(sockfd, &iov, 1, 0, bytes, do_send);
 }
 
-typedef struct {
-    Coroutine *co;
-    int fd;
-} FDYieldUntilData;
-
-static void fd_coroutine_enter(void *opaque)
-{
-    FDYieldUntilData *data = opaque;
-    qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
-    qemu_coroutine_enter(data->co);
-}
-
 void coroutine_fn yield_until_fd_readable(int fd)
 {
-    FDYieldUntilData data;
-
     assert(qemu_in_coroutine());
-    data.co = qemu_coroutine_self();
-    data.fd = fd;
-    qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
+    AioContext *ctx = qemu_get_current_aio_context();
+    aio_set_fd_handler(ctx, fd, false, (IOHandler *)qemu_coroutine_enter,
+                       NULL, NULL, qemu_coroutine_self());
     qemu_coroutine_yield();
+    aio_set_fd_handler(ctx, fd, false, NULL, NULL, NULL, NULL);
 }
-- 
2.20.1



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

* Re: [PATCH v3] yield_until_fd_readable: make it work with any AioContect
  2019-10-21  8:50 [PATCH v3] yield_until_fd_readable: make it work with any AioContect Dietmar Maurer
@ 2019-10-23 14:22 ` Stefan Hajnoczi
  2019-10-24  4:58   ` Dietmar Maurer
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2019-10-23 14:22 UTC (permalink / raw)
  To: Dietmar Maurer; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

On Mon, Oct 21, 2019 at 10:50:55AM +0200, Dietmar Maurer wrote:
> -static void fd_coroutine_enter(void *opaque)
> -{
> -    FDYieldUntilData *data = opaque;
> -    qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
> -    qemu_coroutine_enter(data->co);
> -}
> -
>  void coroutine_fn yield_until_fd_readable(int fd)
>  {
> -    FDYieldUntilData data;
> -
>      assert(qemu_in_coroutine());
> -    data.co = qemu_coroutine_self();
> -    data.fd = fd;
> -    qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
> +    AioContext *ctx = qemu_get_current_aio_context();
> +    aio_set_fd_handler(ctx, fd, false, (IOHandler *)qemu_coroutine_enter,
> +                       NULL, NULL, qemu_coroutine_self());

This cast is unsafe.  If qemu_coroutine_enter()'s prototype is changed
there will be no compiler warning that the prototypes are now
incompatible.

Please keep fd_coroutine_enter() so the code is type-safe.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3] yield_until_fd_readable: make it work with any AioContect
  2019-10-23 14:22 ` Stefan Hajnoczi
@ 2019-10-24  4:58   ` Dietmar Maurer
  0 siblings, 0 replies; 3+ messages in thread
From: Dietmar Maurer @ 2019-10-24  4:58 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

> > +    aio_set_fd_handler(ctx, fd, false, (IOHandler *)qemu_coroutine_enter,
> > +                       NULL, NULL, qemu_coroutine_self());
> 
> This cast is unsafe.  If qemu_coroutine_enter()'s prototype is changed
> there will be no compiler warning that the prototypes are now
> incompatible.
> 
> Please keep fd_coroutine_enter() so the code is type-safe.

OK. Sent v4 with suggested changes.



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

end of thread, other threads:[~2019-10-24  5:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21  8:50 [PATCH v3] yield_until_fd_readable: make it work with any AioContect Dietmar Maurer
2019-10-23 14:22 ` Stefan Hajnoczi
2019-10-24  4:58   ` Dietmar Maurer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.