qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>,
	pbonzini@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 1/4] net/socket: Convert the non-blocking connection mechanism to QIOchannel
Date: Thu, 27 Apr 2017 17:22:27 +0100	[thread overview]
Message-ID: <20170427162227.GC30599@redhat.com> (raw)
In-Reply-To: <87y3ulu8k9.fsf@dusky.pond.sub.org>

On Thu, Apr 27, 2017 at 06:19:50PM +0200, Markus Armbruster wrote:
> Markus Armbruster <armbru@redhat.com> writes:
> 
> > Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
> >
> >> Currently, socket connection in net is realized by an old
> >> mechanism which is non-blocking.
> >>
> >> That old mechanism may cause net blocks on DNS lookups and
> >> QEmu has already replaced it with QIOchannel in many features,
> >> such as migration.
> >>
> >> Convert it to QIOchannel for net as well.
> >>
> >> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
> >> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
> >> ---
> >> The test steps like this:
> >>
> >>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
> >>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
> >>
> >> No exception.
> >>
> >>  net/socket.c | 30 +++++++++++++++++++-----------
> >>  1 file changed, 19 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/net/socket.c b/net/socket.c
> >> index b8c931e..52f9dce 100644
> >> --- a/net/socket.c
> >> +++ b/net/socket.c
> >> @@ -33,6 +33,7 @@
> >>  #include "qemu/sockets.h"
> >>  #include "qemu/iov.h"
> >>  #include "qemu/main-loop.h"
> >> +#include "io/channel-socket.h"
> >>  
> >>  typedef struct NetSocketState {
> >>      NetClientState nc;
> >> @@ -525,16 +526,22 @@ typedef struct {
> >>      char *name;
> >>  } socket_connect_data;
> >>  
> >> -static void socket_connect_data_free(socket_connect_data *c)
> >> +static void socket_connect_data_free(void *opaque)
> >>  {
> >> +    socket_connect_data *c = opaque;
> >
> > Blank line between declarations and statements, please.
> >
> >> +    if (!c) {
> >> +        return;
> >> +    }
> >> +
> >>      qapi_free_SocketAddress(c->saddr);
> >>      g_free(c->model);
> >>      g_free(c->name);
> >>      g_free(c);
> >>  }
> >>  
> >> -static void net_socket_connected(int fd, Error *err, void *opaque)
> >> +static void net_socket_connected(QIOTask *task, void *opaque)
> >>  {
> >> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
> >>      socket_connect_data *c = opaque;
> >>      NetSocketState *s;
> >>      char *addr_str = NULL;
> >> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
> >>      addr_str = socket_address_to_string(c->saddr, &local_error);
> >>      if (addr_str == NULL) {
> >>          error_report_err(local_error);
> >> -        closesocket(fd);
> >> +        closesocket(sioc->fd);
> >>          goto end;
> >>      }
> >>  
> >> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
> >> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
> >>      if (!s) {
> >> -        closesocket(fd);
> >> +        closesocket(sioc->fd);
> 
> Actually, net_socket_fd_init() closes sioc->fd when it fails.  Closing
> it again in the caller is wrong.  None of the other callers does it.
> Please drop this line in a separate patch, before this one.

NB, technically the 'fd' is still owned by the 'sioc' object, so nothing
should close it. If we weren't already leaking the 'sioc' object we would
have a double close here....

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2017-04-27 16:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26  8:04 [Qemu-devel] [PATCH v2 0/4] Convert non-blocking connect and fix its error reporting Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 1/4] net/socket: Convert the non-blocking connection mechanism to QIOchannel Mao Zhongyi
2017-04-27 15:46   ` Markus Armbruster
2017-04-27 16:19     ` Markus Armbruster
2017-04-27 16:22       ` Daniel P. Berrange [this message]
2017-05-03  7:02     ` Mao Zhongyi
2017-04-27 16:20   ` Daniel P. Berrange
2017-05-03  7:02     ` Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 2/4] net/socket: Improve -net socket error reporting Mao Zhongyi
2017-04-27 16:10   ` Markus Armbruster
2017-05-03  7:07     ` Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 3/4] net/socket: Convert error report message to Error Mao Zhongyi
2017-04-27 16:24   ` Markus Armbruster
2017-04-27 16:30     ` Daniel P. Berrange
2017-04-28  8:02       ` Markus Armbruster
2017-05-03  7:09         ` Mao Zhongyi
2017-05-03  8:37           ` Daniel P. Berrange
2017-05-03  8:37             ` Mao Zhongyi
2017-05-03  8:54           ` Markus Armbruster
2017-05-03  8:59             ` Mao Zhongyi
2017-05-03 11:47               ` Jason Wang
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 4/4] net/net: Convert parse_host_port() " Mao Zhongyi
2017-04-27 16:25 ` [Qemu-devel] [PATCH v2 0/4] Convert non-blocking connect and fix its error reporting Markus Armbruster
2017-05-03  7:12   ` Mao Zhongyi
2017-05-05 16:39 ` Daniel P. Berrange
2017-05-09  1:26   ` Mao Zhongyi

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=20170427162227.GC30599@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=maozy.fnst@cn.fujitsu.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).