Received: from eggs.gnu.org ([208.118.235.92]:46889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWjKw-0007Lj-5q for qemu-devel@nongnu.org; Mon, 29 Apr 2013 04:21:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UWjKs-0001fH-LS for qemu-devel@nongnu.org; Mon, 29 Apr 2013 04:21:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWjKs-0001f9-9h for qemu-devel@nongnu.org; Mon, 29 Apr 2013 04:21:22 -0400 Date: Mon, 29 Apr 2013 10:21:16 +0200 From: Stefan Hajnoczi Message-ID: <20130429082116.GD13488@stefanha-thinkpad.redhat.com> References: <1366944455-14239-1-git-send-email-qemulist@gmail.com> <1366944455-14239-6-git-send-email-qemulist@gmail.com> <20130426094822.GE17609@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [RFC PATCH v5 05/14] net: port socket to GSource List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: mdroth , Jan Kiszka , qemu-devel@nongnu.org, Anthony Liguori , Paolo Bonzini On Sat, Apr 27, 2013 at 03:09:10PM +0800, liu ping fan wrote: > On Fri, Apr 26, 2013 at 5:48 PM, Stefan Hajnoczi wrote: > > On Fri, Apr 26, 2013 at 10:47:26AM +0800, Liu Ping Fan wrote: > >> @@ -141,6 +134,59 @@ static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, > >> return ret; > >> } > >> > >> +static gushort socket_connecting_readable(void *opaque) > >> +{ > >> + return G_IO_IN; > >> +} > >> + > >> +static gushort socket_listen_readable(void *opaque) > >> +{ > >> + /* listen only handle in-req, no err */ > >> + return G_IO_IN; > > > > From the accept(2) man page: > > > > "Linux accept() (and accept4()) passes already-pending network errors on > > the new socket as an error code from accept()." > > > > So we must handle errors from accept(2), please use G_IO_IN | G_IO_HUP | > > G_IO_ERR. > > > Here, we handle listen(2), not accept(2) Look again, the handler invokes accept(2). listen(2) was called to put the socket into the listening state but now we are monitoring for accept. > >> +static gushort socket_establish_readable(void *opaque) > >> +{ > >> + NetSocketState *s = opaque; > >> + > >> + /* rely on net_socket_send to handle err */ > >> + if (s->read_poll && net_socket_can_send(s)) { > >> + return G_IO_IN|G_IO_HUP|G_IO_ERR; > >> + } > >> + return G_IO_HUP|G_IO_ERR; > >> +} > > > > This new function always monitors G_IO_HUP | G_IO_ERR. The old code > > only monitored it when read_poll == true and net_socket_can_send() == > > true. > > > > Please preserve semantics. > > > But the only the code in net_socket_send() will handle the err > condition. See the code behind "/* end of connection */". And I think > it is safely to handle err, even when the peer is not ready to > receive. > > >> +static gushort socket_establish_writable(void *opaque) > >> +{ > >> + NetSocketState *s = opaque; > >> + > >> + if (s->write_poll) { > >> + return G_IO_OUT; > > > > Errors/hang up? > > > As explained above, net_socket_writable() does not handle the err > condition. But maybe we need the qemu_flush_queued_packets() in it? net_socket_receive() does handle send(2) errors but it does so differently from net_socket_send(). It fails the packet and resets ->send_index. The change you made doesn't really solve this because an error could still happen right when QEMU calls send(2) and therefore not be processed by net_socket_send(). Changing the send/receive error handling is something that could be done carefully in a separate patch. But please preserve semantics in conversion patches - it makes them easy to review and merge. As explained above, I'm not convinced that the change you made is useful. Stefan