From patchwork Thu Jan 23 08:27:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 313477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 58D182C0081 for ; Thu, 23 Jan 2014 19:31:55 +1100 (EST) Received: from localhost ([::1]:39519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6FhZ-00080z-8V for incoming@patchwork.ozlabs.org; Thu, 23 Jan 2014 03:31:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fe2-0002S4-Aj for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Fdt-0000Dq-CY for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:14 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:44125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fds-0000D2-NM for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:05 -0500 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 23 Jan 2014 13:57:57 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 23 Jan 2014 13:57:55 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 81D0C3940060 for ; Thu, 23 Jan 2014 13:57:54 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s0N8RbG82425198 for ; Thu, 23 Jan 2014 13:57:37 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s0N8RrcF020721 for ; Thu, 23 Jan 2014 13:57:54 +0530 Received: from localhost.cn.ibm.com ([9.115.122.232]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s0N8RjXo020467; Thu, 23 Jan 2014 13:57:52 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Thu, 23 Jan 2014 16:27:41 +0800 Message-Id: <1390465663-17650-4-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1390465663-17650-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1390465663-17650-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14012308-8256-0000-0000-00000B2232BB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: mohan@in.ibm.com, Lei Li , pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 3/5] net/tap: replace recv_fd with qemu_recv_with_fd 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 Signed-off-by: Lei Li --- net/tap.c | 40 +++------------------------------------- 1 files changed, 3 insertions(+), 37 deletions(-) diff --git a/net/tap.c b/net/tap.c index 39c1cda..97ee2e8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -39,6 +39,7 @@ #include "sysemu/sysemu.h" #include "qemu-common.h" #include "qemu/error-report.h" +#include "qemu/fd-exchange.h" #include "net/tap.h" @@ -385,40 +386,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) return -1; } -static int recv_fd(int c) -{ - int fd; - uint8_t msgbuf[CMSG_SPACE(sizeof(fd))]; - struct msghdr msg = { - .msg_control = msgbuf, - .msg_controllen = sizeof(msgbuf), - }; - struct cmsghdr *cmsg; - struct iovec iov; - uint8_t req[1]; - ssize_t len; - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); - msg.msg_controllen = cmsg->cmsg_len; - - iov.iov_base = req; - iov.iov_len = sizeof(req); - - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - len = recvmsg(c, &msg, 0); - if (len > 0) { - memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); - return fd; - } - - return len; -} - static int net_bridge_run_helper(const char *helper, const char *bridge) { sigset_t oldmask, mask; @@ -489,12 +456,11 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) } else if (pid > 0) { int fd; + char req[1] = { 0x00 }; close(sv[1]); - do { - fd = recv_fd(sv[0]); - } while (fd == -1 && errno == EINTR); + qemu_recv_with_fd(sv[0], &fd, &req, sizeof(req)); close(sv[0]);