Received: from eggs.gnu.org ([2001:4830:134:3::10]:49521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3m96-00066X-Da for qemu-devel@nongnu.org; Thu, 27 Apr 2017 12:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3m93-0002Q0-Ov for qemu-devel@nongnu.org; Thu, 27 Apr 2017 12:19:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3m93-0002Pf-Ed for qemu-devel@nongnu.org; Thu, 27 Apr 2017 12:19:53 -0400 From: Markus Armbruster References: <6824abf3c4e5b865de1799c302f60e8055c8d3dc.1493191677.git.maozy.fnst@cn.fujitsu.com> <874lx9yht7.fsf@dusky.pond.sub.org> Date: Thu, 27 Apr 2017 18:19:50 +0200 In-Reply-To: <874lx9yht7.fsf@dusky.pond.sub.org> (Markus Armbruster's message of "Thu, 27 Apr 2017 17:46:28 +0200") Message-ID: <87y3ulu8k9.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 1/4] net/socket: Convert the non-blocking connection mechanism to QIOchannel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mao Zhongyi Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, jasowang@redhat.com Markus Armbruster writes: > Mao Zhongyi 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 >> --- >> 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. >> goto end; >> } >> [...]