From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVATH-00029b-AZ for qemu-devel@nongnu.org; Mon, 09 Mar 2015 23:04:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVAT4-0003of-OQ for qemu-devel@nongnu.org; Mon, 09 Mar 2015 23:04:39 -0400 Received: from ozlabs.org ([103.22.144.67]:40541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVAT4-0003oM-Bj for qemu-devel@nongnu.org; Mon, 09 Mar 2015 23:04:26 -0400 Date: Tue, 10 Mar 2015 13:56:27 +1100 From: David Gibson Message-ID: <20150310025627.GI30335@voom.fritz.box> References: <1424883128-9841-1-git-send-email-dgilbert@redhat.com> <1424883128-9841-9-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0XMZdl/q8hSSmFeD" Content-Disposition: inline In-Reply-To: <1424883128-9841-9-git-send-email-dgilbert@redhat.com> Subject: Re: [Qemu-devel] [PATCH v5 08/45] 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, quintela@redhat.com, qemu-devel@nongnu.org, amit.shah@redhat.com, pbonzini@redhat.com, yanghy@cn.fujitsu.com --0XMZdl/q8hSSmFeD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 25, 2015 at 04:51:31PM +0000, 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. It's not clear to me from this description exactly where the situation is that you need to write to the non-blocking socket. Is it on the source or the destination? If the source, why are you writing to the return path? If the destination, why are you marking the outgoing return path as non-blocking? > Signed-off-by: Dr. David Alan Gilbert > --- > migration/qemu-file-unix.c | 41 ++++++++++++++++++++++++++++++++++++----- > 1 file changed, 36 insertions(+), 5 deletions(-) >=20 > diff --git a/migration/qemu-file-unix.c b/migration/qemu-file-unix.c > index 50291cf..218dbd0 100644 > --- a/migration/qemu-file-unix.c > +++ b/migration/qemu-file-unix.c > @@ -39,12 +39,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(); > - } > - return len; > + 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. > + */ > + 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 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 --0XMZdl/q8hSSmFeD Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU/l1bAAoJEGw4ysog2bOSVwcP/j9rzqc8IJlR1CTWF5FnaVp8 tFy6VNVYeJcZcAkBON9/hthjRD3ZtZnYmVAmRU5mXgIu6oa1+4gpgq7eY07yBYQE uOUruj9qdIzrZfj/mSqIfAFNXzkrAiSm7HSep1110Bs+hmknmWu97rBExBYXmGY9 Uya1ja685YbiWyabK7mb8mcSz+Q36/VCRn/36G+2zql3sKTg9SqeduRw1bUQrVyM nAuS37ysclYL7lsh5gjKkl5yYk/r6pTln/1D1rIx+yXd1xaipIArJkHTYllSPZQS LJilQVnYMk/wMCriHv6BXLm4ZHGcZ8TLfbe5HP6AIJNGadkjIRrDfLPOdsBTkONa fdd7r8mKHdSQDObdSRKowUQCBNEv8VXbwjPHaw6284ezwARhPLHb37CqNaFDjfAl ddmcovw79HsP0PLqn6P3P90pSGqVI51WdDUQAvAp3z/nFXQn0SyPTGpdMg3T2/KS Ykxs/L9UHZ1F1Eg3pDJy0rwqnWqIPZfkDRSyMpUvqBKV7y4yt/7dEISGCAlELJ33 pF9sBTjsQ0ux77tozXrdbklzo9audw7KCUy5yGQVjRfaouXe6rxpCXa8CvGjUis+ Ba9XprQyFcP3RAvMmDKGsBaG8d8d9Mjqe7Swj8dKqfAyAASx4FyTQs1dTfqoEHYK yoK9gkKqSJE5fbfVS5LV =Z6dx -----END PGP SIGNATURE----- --0XMZdl/q8hSSmFeD--