From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xl8Tv-0002Mz-LY for qemu-devel@nongnu.org; Sun, 02 Nov 2014 22:39:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xl8Tr-0007NG-S5 for qemu-devel@nongnu.org; Sun, 02 Nov 2014 22:39:03 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:35826) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xl8Tr-0007Md-G0 for qemu-devel@nongnu.org; Sun, 02 Nov 2014 22:38:59 -0500 Date: Mon, 3 Nov 2014 14:10:45 +1100 From: David Gibson Message-ID: <20141103031045.GG8949@voom.redhat.com> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> <1412358473-31398-12-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="nqkreNcslJAfgyzk" Content-Disposition: inline In-Reply-To: <1412358473-31398-12-git-send-email-dgilbert@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: "Dr. David Alan Gilbert (git)" 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 --nqkreNcslJAfgyzk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 03, 2014 at 06:47:17PM +0100, Dr. David Alan Gilbert (git) wrot= e: > 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 block. >=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, str= uct 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 (%z= d/%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 th= e error > + * immediately. Is that safe? This gives the caller no means to detect a partially completed send. > + */ > + return -err; > + } > + > + /* Emulate blocking */ > + GPollFD pfd; > + > + pfd.fd =3D s->fd; > + pfd.events =3D G_IO_OUT | G_IO_ERR; > + pfd.revents =3D 0; > + g_poll(&pfd, 1 /* 1 fd */, -1 /* no timeout */); > + } > } > - return len; > + > + return offset; > } > =20 > static int socket_get_fd(void *opaque) --=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 --nqkreNcslJAfgyzk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJUVvI1AAoJEGw4ysog2bOSEHwP/3lxl8jnvpfylk4p3RR5hhk4 JTN5qQkPAfPltK6ikUmJoGQoea8d2l+56rj+fEzY0VsPfMwHvILBLM1i6w6ZVtV2 9RzaLHnWm3kdYCGFQ2MYoc/B/p2nevLKQvslRCuMqqnVEtBWHwzNmwv2FcMDrq/w ItYLB11DHRRNnJSvY9V/yUN0RLh+kVZZWOzOVBizGhHPWu6rzsxzUhPCpxLbuPjA YXRCwLxCmbfmN/ChrKa8gRF6D58XZYtxZE7hyHGH1ahzQbMaogx5LNG8PuPc5na4 O3Oidzhe0OGNfp1ATeULU2WDcdklRZd1/DPWU3oy0xibgn0WMkHu4deyQq0jTJCE iB/NmrMaYup4YJd6edddix7XD9iF0bVFHXzpvO6xGmXwyNke555GyOWAnS0bzDGh 8HWmGUdp0Ffz2V3otZyXP86adlB1AHLrVnkFV/ylPH5zVcHWZxIB4xgQeGEPNidn wGpNn9Gsrd8h4lnkKVmKTOrmvCOFQg4Y0wXnzIZDhx/8RULLA2rW57Obv0zDATbP ppIGlZYD5ABDaShybwDTpT79oPdRtVEyR7bM204TSaZKaeEy7ehPnAwaY/D608x9 Xyfetcf2oM2QYdbmgS8q+k3geaZSmBgqLYo0AEurysmUaeU/zSh9YBrHMFlg0u7j pBeNWJn0655W2lWtbkog =J/ZP -----END PGP SIGNATURE----- --nqkreNcslJAfgyzk--