qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: quintela@redhat.com
Subject: [Qemu-devel] [PATCH 8/9] migration: handle EAGAIN while reading QEMUFile
Date: Fri, 21 Sep 2012 19:05:05 +0200	[thread overview]
Message-ID: <1348247106-27936-9-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1348247106-27936-1-git-send-email-pbonzini@redhat.com>

This will never happen right now (the assertion would fail).  The
next patch will set the socket or pipe in non-blocking mode, thus
enabling this part of the code.

Coroutines can just stop whenever they want with qemu_coroutine_yield.
As soon as select tells the main loop that the migration stream is
readable, the coroutine is re-entered directly in qemu_get_buffer,
where it will read more data and pass it to the loading routines.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 savevm.c | 30 ++++++++++++++++++++++++------
 1 file modificato, 24 inserzioni(+), 6 rimozioni(-)

diff --git a/savevm.c b/savevm.c
index 949c38c..90e0cfb 100644
--- a/savevm.c
+++ b/savevm.c
@@ -199,13 +199,22 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
     QEMUFileSocket *s = opaque;
     ssize_t len;
 
-    do {
+    for (;;) {
         len = qemu_recv(s->fd, buf, size, 0);
-    } while (len == -1 && socket_error() == EINTR);
+        if (len != -1) {
+            break;
+        }
+        if (errno == EAGAIN) {
+            assert(qemu_in_coroutine());
+            qemu_coroutine_yield();
+        } else if (errno != EINTR) {
+            break;
+        }
+    }
 
-    if (len == -1)
+    if (len == -1) {
         len = -socket_error();
-
+    }
     return len;
 }
 
@@ -236,10 +245,19 @@ static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
     FILE *fp = s->stdio_file;
     int bytes;
 
-    do {
+    for (;;) {
         clearerr(fp);
         bytes = fread(buf, 1, size, fp);
-    } while ((bytes == 0) && ferror(fp) && (errno == EINTR));
+        if (bytes != 0 || !ferror(fp)) {
+            break;
+        }
+        if (errno == EAGAIN) {
+            assert(qemu_in_coroutine());
+            qemu_coroutine_yield();
+        } else if (errno != EINTR) {
+            break;
+        }
+    }
     return bytes;
 }
 
-- 
1.7.12

  parent reply	other threads:[~2012-09-21 17:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 17:04 [Qemu-devel] [PATCH 0/9] Incoming migration coroutine Paolo Bonzini
2012-09-21 17:04 ` [Qemu-devel] [PATCH 1/9] migration: unify stdio-based QEMUFile operations Paolo Bonzini
2012-09-21 17:04 ` [Qemu-devel] [PATCH 2/9] migration: consolidate QEMUFile methods in a single QEMUFileOps struct Paolo Bonzini
2012-09-21 17:05 ` [Qemu-devel] [PATCH 3/9] migration: add qemu_get_fd Paolo Bonzini
2012-09-21 17:05 ` [Qemu-devel] [PATCH 4/9] migration: replace qemu_stdio_fd with qemu_get_fd Paolo Bonzini
2012-09-21 17:05 ` [Qemu-devel] [PATCH 5/9] migration: clean up server sockets and handlers before invoking process_incoming_migration Paolo Bonzini
2012-09-21 17:05 ` [Qemu-devel] [PATCH 6/9] migration: close socket QEMUFile from socket_close Paolo Bonzini
2012-09-21 17:05 ` [Qemu-devel] [PATCH 7/9] migration: move qemu_fclose to process_incoming_migration Paolo Bonzini
2012-09-21 17:05 ` Paolo Bonzini [this message]
2012-09-21 17:05 ` [Qemu-devel] [PATCH 9/9] migration: move process_incoming_migration to a coroutine Paolo Bonzini

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=1348247106-27936-9-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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).