From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlMr9-0002zx-Ob for qemu-devel@nongnu.org; Mon, 03 Nov 2014 14:00:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlMr5-00044N-Im for qemu-devel@nongnu.org; Mon, 03 Nov 2014 13:59:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlMr5-00044A-C2 for qemu-devel@nongnu.org; Mon, 03 Nov 2014 13:59:55 -0500 Date: Mon, 3 Nov 2014 18:59:35 +0000 From: "Dr. David Alan Gilbert" Message-ID: <20141103185934.GD29967@work-vm> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> <1412358473-31398-12-git-send-email-dgilbert@redhat.com> <20141103031045.GG8949@voom.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141103031045.GG8949@voom.redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 11/47] Return path: socket_writev_buffer: Block even on non-blocking fd's List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com, cristian.klein@cs.umu.se, qemu-devel@nongnu.org, amit.shah@redhat.com, yanghy@cn.fujitsu.com * David Gibson (david@gibson.dropbear.id.au) wrote: > On Fri, Oct 03, 2014 at 06:47:17PM +0100, Dr. David Alan Gilbert (git) wrote: > > From: "Dr. David Alan Gilbert" > > > > The return path uses a non-blocking fd so as not to block waiting > > for the (possibly broken) destination to finish returning a message, > > however we still want outbound data to behave in the same way and block. > > > > Signed-off-by: Dr. David Alan Gilbert > > --- > > qemu-file.c | 39 +++++++++++++++++++++++++++++++++++---- > > 1 file changed, 35 insertions(+), 4 deletions(-) > > > > diff --git a/qemu-file.c b/qemu-file.c > > index 7393415..57eabd8 100644 > > --- a/qemu-file.c > > +++ b/qemu-file.c > > @@ -85,12 +85,43 @@ static ssize_t socket_writev_buffer(void *opaque, struct iovec *iov, int iovcnt, > > QEMUFileSocket *s = opaque; > > ssize_t len; > > ssize_t size = iov_size(iov, iovcnt); > > + ssize_t offset = 0; > > + int err; > > > > - len = iov_send(s->fd, iov, iovcnt, 0, size); > > - if (len < size) { > > - len = -socket_error(); > > + while (size > 0) { > > + len = iov_send(s->fd, iov, iovcnt, offset, size); > > + > > + if (len > 0) { > > + size -= len; > > + offset += len; > > + } > > + > > + if (size > 0) { > > + err = socket_error(); > > + > > + if (err != EAGAIN) { > > + error_report("socket_writev_buffer: Got err=%d for (%zd/%zd)", > > + err, size, len); > > + /* > > + * If I've already sent some but only just got the error, I > > + * could return the amount validly sent so far and wait for the > > + * next call to report the error, but I'd rather flag the error > > + * immediately. > > Is that safe? This gives the caller no means to detect a partially > completed send. Well I'm returning the -err, so the caller knows something has gone wrong - it just doesn't know whether it managed to send some part of the data before the failure. Dave > > > + */ > > + return -err; > > + } > > + > > + /* Emulate blocking */ > > + GPollFD pfd; > > + > > + pfd.fd = s->fd; > > + pfd.events = G_IO_OUT | G_IO_ERR; > > + pfd.revents = 0; > > + g_poll(&pfd, 1 /* 1 fd */, -1 /* no timeout */); > > + } > > } > > - return len; > > + > > + return offset; > > } > > > > static int socket_get_fd(void *opaque) > > -- > David Gibson | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ > | _way_ _around_! > http://www.ozlabs.org/~dgibson -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK