From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULPO-00036J-OF for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TULPN-0005Z8-Kt for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:54 -0400 Received: from mail-da0-f45.google.com ([209.85.210.45]:37398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULPN-0005RD-EK for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:53 -0400 Received: by mail-da0-f45.google.com with SMTP id n15so1690046dad.4 for ; Fri, 02 Nov 2012 10:51:53 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 2 Nov 2012 18:51:04 +0100 Message-Id: <1351878665-32413-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1351878665-32413-1-git-send-email-pbonzini@redhat.com> References: <1351878665-32413-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 11/12] migration: handle EAGAIN while reading QEMUFile List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.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 --- savevm.c | 30 ++++++++++++++++++++++++------ 1 file modificato, 24 inserzioni(+), 6 rimozioni(-) diff --git a/savevm.c b/savevm.c index cdad3ad..5d04d59 100644 --- a/savevm.c +++ b/savevm.c @@ -200,13 +200,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 (socket_error() == EAGAIN) { + assert(qemu_in_coroutine()); + qemu_coroutine_yield(); + } else if (socket_error() != EINTR) { + break; + } + } - if (len == -1) + if (len == -1) { len = -socket_error(); - + } return len; } @@ -237,10 +246,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.1