qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 3/5] io: Yield rather than wait when already in coroutine
Date: Wed,  6 Sep 2017 10:21:09 -0500	[thread overview]
Message-ID: <20170906152111.16958-4-eblake@redhat.com> (raw)
In-Reply-To: <20170906152111.16958-1-eblake@redhat.com>

The new qio_channel_{read,write}{,v}_all functions are documented
as yielding until data is available.  When used on a blocking
channel, this yield is done via qio_channel_wait() which spawns
a nested event loop under the hood (so it is that secondary loop
which yields as needed); but if we are already in a coroutine (at
which point QIO_CHANNEL_ERR_BLOCK is only possible if we are a
non-blocking channel), we want to yield the current coroutine
instead of spawning a nested event loop.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20170905191114.5959-2-eblake@redhat.com>
Acked-by: Daniel P. Berrange <berrange@redhat.com>
[commit message updated]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 io/channel.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/io/channel.c b/io/channel.c
index 5e8c2f0a91..9e62794cab 100644
--- a/io/channel.c
+++ b/io/channel.c
@@ -105,7 +105,11 @@ int qio_channel_readv_all(QIOChannel *ioc,
         ssize_t len;
         len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
         if (len == QIO_CHANNEL_ERR_BLOCK) {
-            qio_channel_wait(ioc, G_IO_IN);
+            if (qemu_in_coroutine()) {
+                qio_channel_yield(ioc, G_IO_IN);
+            } else {
+                qio_channel_wait(ioc, G_IO_IN);
+            }
             continue;
         } else if (len < 0) {
             goto cleanup;
@@ -143,7 +147,11 @@ int qio_channel_writev_all(QIOChannel *ioc,
         ssize_t len;
         len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
         if (len == QIO_CHANNEL_ERR_BLOCK) {
-            qio_channel_wait(ioc, G_IO_OUT);
+            if (qemu_in_coroutine()) {
+                qio_channel_yield(ioc, G_IO_OUT);
+            } else {
+                qio_channel_wait(ioc, G_IO_OUT);
+            }
             continue;
         }
         if (len < 0) {
-- 
2.13.5

  parent reply	other threads:[~2017-09-06 15:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-06 15:21 [Qemu-devel] [PULL 0/5] NBD patches for 2017-09-06 Eric Blake
2017-09-06 15:21 ` [Qemu-devel] [PULL 1/5] iotests: rewrite 192 to use _launch_qemu to fix LUKS support Eric Blake
2017-09-06 15:21 ` [Qemu-devel] [PULL 2/5] iotests: blacklist 194 with the luks driver Eric Blake
2017-09-06 15:21 ` Eric Blake [this message]
2017-09-06 15:21 ` [Qemu-devel] [PULL 4/5] io: Add new qio_channel_read{, v}_all_eof functions Eric Blake
2017-09-06 15:21 ` [Qemu-devel] [PULL 5/5] nbd: Use new qio_channel_*_all() functions Eric Blake
2017-09-07 12:26 ` [Qemu-devel] [PULL 0/5] NBD patches for 2017-09-06 Peter Maydell
2017-09-07 13:48   ` Eric Blake
2017-09-07 13:53     ` Daniel P. Berrange
2017-09-07 17:56       ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170906152111.16958-4-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).