From patchwork Wed Mar 27 18:46:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 231794 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5D9F52C00D2 for ; Thu, 28 Mar 2013 05:49:34 +1100 (EST) Received: from localhost ([::1]:57394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKvPf-0002Xb-1B for incoming@patchwork.ozlabs.org; Wed, 27 Mar 2013 14:49:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKvMu-0006wZ-Ch for qemu-devel@nongnu.org; Wed, 27 Mar 2013 14:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKvMr-0004Qa-Ts for qemu-devel@nongnu.org; Wed, 27 Mar 2013 14:46:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKvMr-0004QQ-Lt for qemu-devel@nongnu.org; Wed, 27 Mar 2013 14:46:37 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2RIkaeu025370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Mar 2013 14:46:36 -0400 Received: from localhost (ovpn-113-92.phx2.redhat.com [10.3.113.92]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2RIkafP024069; Wed, 27 Mar 2013 14:46:36 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 27 Mar 2013 14:46:23 -0400 Message-Id: <1364409987-23742-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1364409987-23742-1-git-send-email-lcapitulino@redhat.com> References: <1364409987-23742-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PULL 2/6] net: ensure "socket" backend uses non-blocking fds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Hajnoczi There are several code paths in net_init_socket() depending on how the socket is created: file descriptor passing, UDP multicast, TCP, or UDP. Some of these support both listen and connect. Not all code paths set the socket to non-blocking. This patch addresses the file descriptor passing and UDP cases which were missing socket_set_nonblock(fd) calls. I considered moving socket_set_nonblock(fd) to a central location but it turns out the code paths are different enough to require non-blocking at different places. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- net/socket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/socket.c b/net/socket.c index b5c8e65..87af1d3 100644 --- a/net/socket.c +++ b/net/socket.c @@ -674,6 +674,7 @@ static int net_socket_udp_init(NetClientState *peer, closesocket(fd); return -1; } + qemu_set_nonblock(fd); s = net_socket_fd_init(peer, model, name, fd, 0); if (!s) { @@ -712,7 +713,11 @@ int net_init_socket(const NetClientOptions *opts, const char *name, int fd; fd = monitor_handle_fd_param(cur_mon, sock->fd); - if (fd == -1 || !net_socket_fd_init(peer, "socket", name, fd, 1)) { + if (fd == -1) { + return -1; + } + qemu_set_nonblock(fd); + if (!net_socket_fd_init(peer, "socket", name, fd, 1)) { return -1; } return 0;