Blame SOURCES/kvm-io-Yield-rather-than-wait-when-already-in-coroutine.patch

4a2fec
From 280e240cfa8e633dd062791b1d0d62fe0e642d46 Mon Sep 17 00:00:00 2001
4a2fec
From: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
Date: Sat, 2 Dec 2017 12:19:38 +0100
4a2fec
Subject: [PATCH 12/36] io: Yield rather than wait when already in coroutine
4a2fec
4a2fec
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
Message-id: <20171202121953.13317-3-pbonzini@redhat.com>
4a2fec
Patchwork-id: 78076
4a2fec
O-Subject: [RHEL7.4 qemu-kvm-rhev PATCH 02/17] io: Yield rather than wait when already in coroutine
4a2fec
Bugzilla: 1464908
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
4a2fec
From: Eric Blake <eblake@redhat.com>
4a2fec
4a2fec
The new qio_channel_{read,write}{,v}_all functions are documented
4a2fec
as yielding until data is available.  When used on a blocking
4a2fec
channel, this yield is done via qio_channel_wait() which spawns
4a2fec
a nested event loop under the hood (so it is that secondary loop
4a2fec
which yields as needed); but if we are already in a coroutine (at
4a2fec
which point QIO_CHANNEL_ERR_BLOCK is only possible if we are a
4a2fec
non-blocking channel), we want to yield the current coroutine
4a2fec
instead of spawning a nested event loop.
4a2fec
4a2fec
Signed-off-by: Eric Blake <eblake@redhat.com>
4a2fec
Message-Id: <20170905191114.5959-2-eblake@redhat.com>
4a2fec
Acked-by: Daniel P. Berrange <berrange@redhat.com>
4a2fec
[commit message updated]
4a2fec
Signed-off-by: Eric Blake <eblake@redhat.com>
4a2fec
(cherry picked from commit 9ffb8270205a274a18ee4f8a735e2fccaf957246)
4a2fec
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 io/channel.c | 12 ++++++++++--
4a2fec
 1 file changed, 10 insertions(+), 2 deletions(-)
4a2fec
4a2fec
diff --git a/io/channel.c b/io/channel.c
4a2fec
index 5e8c2f0..9e62794 100644
4a2fec
--- a/io/channel.c
4a2fec
+++ b/io/channel.c
4a2fec
@@ -105,7 +105,11 @@ int qio_channel_readv_all(QIOChannel *ioc,
4a2fec
         ssize_t len;
4a2fec
         len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
4a2fec
         if (len == QIO_CHANNEL_ERR_BLOCK) {
4a2fec
-            qio_channel_wait(ioc, G_IO_IN);
4a2fec
+            if (qemu_in_coroutine()) {
4a2fec
+                qio_channel_yield(ioc, G_IO_IN);
4a2fec
+            } else {
4a2fec
+                qio_channel_wait(ioc, G_IO_IN);
4a2fec
+            }
4a2fec
             continue;
4a2fec
         } else if (len < 0) {
4a2fec
             goto cleanup;
4a2fec
@@ -143,7 +147,11 @@ int qio_channel_writev_all(QIOChannel *ioc,
4a2fec
         ssize_t len;
4a2fec
         len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
4a2fec
         if (len == QIO_CHANNEL_ERR_BLOCK) {
4a2fec
-            qio_channel_wait(ioc, G_IO_OUT);
4a2fec
+            if (qemu_in_coroutine()) {
4a2fec
+                qio_channel_yield(ioc, G_IO_OUT);
4a2fec
+            } else {
4a2fec
+                qio_channel_wait(ioc, G_IO_OUT);
4a2fec
+            }
4a2fec
             continue;
4a2fec
         }
4a2fec
         if (len < 0) {
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec