qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: liu ping fan <qemulist@gmail.com>
Cc: mdroth <mdroth@linux.vnet.ibm.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC PATCH v5 05/14] net: port socket to GSource
Date: Mon, 29 Apr 2013 10:21:16 +0200	[thread overview]
Message-ID: <20130429082116.GD13488@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <CAJnKYQkQnNSMvA4vdU+GQgOC2_Bcx2XuuHLmijY2L0MM6+Psxg@mail.gmail.com>

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 <stefanha@redhat.com> 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

  reply	other threads:[~2013-04-29  8:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-26  2:47 [Qemu-devel] [RFC PATCH v5 00/14] port network layer onto glib Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 01/14] util: introduce gsource event abstraction Liu Ping Fan
2013-04-26  9:19   ` Stefan Hajnoczi
2013-04-27  2:11     ` liu ping fan
2013-04-29  8:00       ` Stefan Hajnoczi
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 02/14] net: introduce bind_ctx to NetClientInfo Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 03/14] net: port tap onto GSource Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 04/14] net: port vde " Liu Ping Fan
2013-04-26  9:25   ` Stefan Hajnoczi
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 05/14] net: port socket to GSource Liu Ping Fan
2013-04-26  9:48   ` Stefan Hajnoczi
2013-04-27  7:09     ` liu ping fan
2013-04-29  8:21       ` Stefan Hajnoczi [this message]
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 06/14] net: port tap-win32 onto GSource Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 07/14] net: hub use lock to protect ports list Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 08/14] net: introduce lock to protect NetQueue Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 09/14] net: introduce lock to protect NetClientState's peer's access Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 10/14] net: make netclient re-entrant with refcnt Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 11/14] slirp: make timeout local Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 12/14] slirp: make slirp event dispatch based on slirp instance, not global Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 13/14] slirp: handle race condition Liu Ping Fan
2013-04-26  2:47 ` [Qemu-devel] [RFC PATCH v5 14/14] slirp: use lock to protect the slirp_instances Liu Ping Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130429082116.GD13488@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=jan.kiszka@siemens.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).