From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSPgh-0005ri-SX for qemu-devel@nongnu.org; Sun, 28 Oct 2012 06:01:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TSPgg-0007Ay-Kz for qemu-devel@nongnu.org; Sun, 28 Oct 2012 06:01:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSPgg-0007Au-BL for qemu-devel@nongnu.org; Sun, 28 Oct 2012 06:01:46 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9SA1jjV025824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 28 Oct 2012 06:01:45 -0400 Message-ID: <508D0285.7010709@redhat.com> Date: Sun, 28 Oct 2012 12:01:41 +0200 From: Orit Wasserman MIME-Version: 1.0 References: <1350555758-29988-1-git-send-email-pbonzini@redhat.com> <1350555758-29988-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1350555758-29988-12-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 11/12] migration: handle EAGAIN while reading QEMUFile List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, quintela@redhat.com On 10/18/2012 12:22 PM, Paolo Bonzini wrote: > 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 ae5e617..783bb3c 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) { socket_error() > + assert(qemu_in_coroutine()); > + qemu_coroutine_yield(); > + } else if (errno != EINTR) { socket_error() > + 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; > } > >