From patchwork Wed Mar 27 09:10:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 231618 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 DCCF02C009B for ; Wed, 27 Mar 2013 20:15:26 +1100 (EST) Received: from localhost ([::1]:42717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKmS4-0005ai-RR for incoming@patchwork.ozlabs.org; Wed, 27 Mar 2013 05:15:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKmQw-0004DG-Lx for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:14:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKmNn-0001VB-7O for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:11:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34985) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKmNm-0001V1-S5 for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:10:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2R9AqUX009571 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Mar 2013 05:10:52 -0400 Received: from localhost (dhcp-64-106.muc.redhat.com [10.32.64.106]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2R9Apxt028602; Wed, 27 Mar 2013 05:10:52 -0400 From: Stefan Hajnoczi To: Date: Wed, 27 Mar 2013 10:10:44 +0100 Message-Id: <1364375446-24180-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1364375446-24180-1-git-send-email-stefanha@redhat.com> References: <1364375446-24180-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Juan Quintela , mprivozn@redhat.com, coreyb@linux.vnet.ibm.com, david.pravec@nethost.cz, Luiz Capitulino , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 2/4] 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 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 --- 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;