From patchwork Thu Jan 23 08:27:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 313472 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 399642C0092 for ; Thu, 23 Jan 2014 19:28:52 +1100 (EST) Received: from localhost ([::1]:39485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fec-0002dc-1c for incoming@patchwork.ozlabs.org; Thu, 23 Jan 2014 03:28:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fe1-0002Qd-BT for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Fds-0000Dg-Cz for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:13 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:44143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Fdq-0000DA-Nz for qemu-devel@nongnu.org; Thu, 23 Jan 2014 03:28:04 -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:58:01 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) 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:58 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 6D45CE0057 for ; Thu, 23 Jan 2014 14:00:58 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s0N8RwSq9699690 for ; Thu, 23 Jan 2014 13:57:58 +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 s0N8RvJU020894 for ; Thu, 23 Jan 2014 13:57:57 +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 s0N8RjXq020467; Thu, 23 Jan 2014 13:57:56 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Thu, 23 Jan 2014 16:27:43 +0800 Message-Id: <1390465663-17650-6-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-00000B2232C4 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 5/5] virtio-9p-proxy: replace v9fs_receivefd 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 --- hw/9pfs/virtio-9p-proxy.c | 60 ++------------------------------------------ 1 files changed, 3 insertions(+), 57 deletions(-) diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index 5f44bb7..f34b845 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -14,6 +14,7 @@ #include "hw/virtio/virtio.h" #include "virtio-9p.h" #include "qemu/error-report.h" +#include "qemu/fd-exchange.h" #include "fsdev/qemu-fsdev.h" #include "virtio-9p-proxy.h" @@ -24,62 +25,6 @@ typedef struct V9fsProxy { struct iovec out_iovec; } V9fsProxy; -/* - * Return received file descriptor on success in *status. - * errno is also returned on *status (which will be < 0) - * return < 0 on transport error. - */ -static int v9fs_receivefd(int sockfd, int *status) -{ - struct iovec iov; - struct msghdr msg; - struct cmsghdr *cmsg; - int retval, data, fd; - union MsgControl msg_control; - - iov.iov_base = &data; - iov.iov_len = sizeof(data); - - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = &msg_control; - msg.msg_controllen = sizeof(msg_control); - - do { - retval = recvmsg(sockfd, &msg, 0); - } while (retval < 0 && errno == EINTR); - if (retval <= 0) { - return retval; - } - /* - * data is set to V9FS_FD_VALID, if ancillary data is sent. If this - * request doesn't need ancillary data (fd) or an error occurred, - * data is set to negative errno value. - */ - if (data != V9FS_FD_VALID) { - *status = data; - return 0; - } - /* - * File descriptor (fd) is sent in the ancillary data. Check if we - * indeed received it. One of the reasons to fail to receive it is if - * we exceeded the maximum number of file descriptors! - */ - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) || - cmsg->cmsg_level != SOL_SOCKET || - cmsg->cmsg_type != SCM_RIGHTS) { - continue; - } - fd = *((int *)CMSG_DATA(cmsg)); - *status = fd; - return 0; - } - *status = -ENFILE; /* Ancillary data sent but not received */ - return 0; -} - static ssize_t socket_read(int sockfd, void *buff, size_t size) { ssize_t retval, total = 0; @@ -307,6 +252,7 @@ static int v9fs_request(V9fsProxy *proxy, int type, V9fsString *name, *value; V9fsString *path, *oldpath; struct iovec *iovec = NULL, *reply = NULL; + int data = V9FS_FD_VALID; qemu_mutex_lock(&proxy->mutex); @@ -548,7 +494,7 @@ static int v9fs_request(V9fsProxy *proxy, int type, * A file descriptor is returned as response for * T_OPEN,T_CREATE on success */ - if (v9fs_receivefd(proxy->sockfd, &retval) < 0) { + if (qemu_recv_with_fd(proxy->sockfd, &retval, &data, sizeof(data)) < 0) { goto close_error; } break;