From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqbY6-0000UA-G1 for qemu-devel@nongnu.org; Tue, 18 Nov 2014 00:41:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqbXx-0005cI-3b for qemu-devel@nongnu.org; Tue, 18 Nov 2014 00:41:58 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:53704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqbXw-0005bP-OF for qemu-devel@nongnu.org; Tue, 18 Nov 2014 00:41:49 -0500 Date: Tue, 18 Nov 2014 14:54:09 +1100 From: David Gibson Message-ID: <20141118035409.GC2867@voom.redhat.com> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> <1412358473-31398-12-git-send-email-dgilbert@redhat.com> <20141103031045.GG8949@voom.redhat.com> <20141103185934.GD29967@work-vm> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="B4IIlcmfBL/1gGOG" Content-Disposition: inline In-Reply-To: <20141103185934.GD29967@work-vm> 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: "Dr. David Alan Gilbert" 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 --B4IIlcmfBL/1gGOG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 03, 2014 at 06:59:35PM +0000, Dr. David Alan Gilbert wrote: > * 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" > > >=20 > > > 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 blo= ck. > > >=20 > > > Signed-off-by: Dr. David Alan Gilbert > > > --- > > > qemu-file.c | 39 +++++++++++++++++++++++++++++++++++---- > > > 1 file changed, 35 insertions(+), 4 deletions(-) > > >=20 > > > 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 =3D opaque; > > > ssize_t len; > > > ssize_t size =3D iov_size(iov, iovcnt); > > > + ssize_t offset =3D 0; > > > + int err; > > > =20 > > > - len =3D iov_send(s->fd, iov, iovcnt, 0, size); > > > - if (len < size) { > > > - len =3D -socket_error(); > > > + while (size > 0) { > > > + len =3D iov_send(s->fd, iov, iovcnt, offset, size); > > > + > > > + if (len > 0) { > > > + size -=3D len; > > > + offset +=3D len; > > > + } > > > + > > > + if (size > 0) { > > > + err =3D socket_error(); > > > + > > > + if (err !=3D EAGAIN) { > > > + error_report("socket_writev_buffer: Got err=3D%d for= (%zd/%zd)", > > > + err, size, len); > > > + /* > > > + * If I've already sent some but only just got the e= rror, I > > > + * could return the amount validly sent so far and w= ait for the > > > + * next call to report the error, but I'd rather fla= g the error > > > + * immediately. > >=20 > > Is that safe? This gives the caller no means to detect a partially > > completed send. >=20 > 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. Right. Which seems like it could be pretty important. --=20 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 --B4IIlcmfBL/1gGOG Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJUasLhAAoJEGw4ysog2bOS8MMQAL/DJOfoua96QmcPzjA3XsKq 1X5ZQ9EWSv/cE3RLMufISZsy0KhEICafwYSfeTG8Nt+FMeiGrsnjTQMPp9qM+t23 CZWNWrAPWPSrApGYHZRyk4fDBIVKcTCs0Ej2yxL9zDilGHW6R+s7evNKMvMzrv4N T9chMEbJrd/XTK3cPEycQV/vYP/71T4Zk27ktOiT/rvFT4clsEUWYuxdgHPcEnQ3 imgN/98R3F83CaGHUCu2Xbgn3qRFWOt/liBZUpv4nCy/O6qHTNvnyUJmLWKPeMUr 40IyzOZ62oxMOOO5hz3cL31e+R9ZXgKTAjjwGQLCw13LO9n4FJoE8idcNnu8r+kN vluFKM3h9SpjYDPvTai0kmeYTPNSf57w9LHf+bjZH5cS8DrUwLxaVG2ECRxw1FiA w9YBoHZqBxUzWcwAXyTMLfkBVOXscQOLeZL1qpBIk9aCKJEsCnLdr9L3RUG/5Sw6 yaa4s2wtZBSxv7lXkiX1kziRLHkvm1pCTaTXuW93D8rIo211kjmZQNikAokXuf0P XwWE+hYVWLfWCsr81sRI/qzLbGmmVPDThAOdbLK5Ocen97yjxhWMny/U7DrAfngw z4tLWUoFg53ITX1GO2/zFrfu0G64OeedVK+YG1edo7XZKDUctlsju5EIe94tZgE7 i7oW3e/NIh1/cr/pfe1y =keUO -----END PGP SIGNATURE----- --B4IIlcmfBL/1gGOG--