From patchwork Wed Mar 9 17:15:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohan Kumar M X-Patchwork-Id: 86138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BD9EDB6F2B for ; Thu, 10 Mar 2011 04:36:04 +1100 (EST) Received: from localhost ([127.0.0.1]:47041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxNIo-0005Hm-3U for incoming@patchwork.ozlabs.org; Wed, 09 Mar 2011 12:36:02 -0500 Received: from [140.186.70.92] (port=48284 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxN9N-0001ru-7T for qemu-devel@nongnu.org; Wed, 09 Mar 2011 12:26:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxN0Y-0005bi-T2 for qemu-devel@nongnu.org; Wed, 09 Mar 2011 12:17:12 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:52221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxN0X-0005bI-VL for qemu-devel@nongnu.org; Wed, 09 Mar 2011 12:17:10 -0500 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp05.in.ibm.com (8.14.4/8.13.1) with ESMTP id p29HH7Nr019381 for ; Wed, 9 Mar 2011 22:47:07 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p29HH60a3674208 for ; Wed, 9 Mar 2011 22:47:07 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p29HG6sh020192 for ; Wed, 9 Mar 2011 22:46:06 +0530 Received: from explorer.in.ibm.com ([9.124.208.3]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p29HG4w9020116; Wed, 9 Mar 2011 22:46:05 +0530 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org, Stefan Hajnoczi Date: Wed, 9 Mar 2011 22:45:53 +0530 Message-Id: <1299690960-12007-5-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1299690960-12007-1-git-send-email-mohan@in.ibm.com> References: <1299690960-12007-1-git-send-email-mohan@in.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 122.248.162.5 Cc: Subject: [Qemu-devel] [V8 PATCH 04/11] virtio-9p: Add qemu side interfaces for chroot environment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org QEMU side interfaces to communicate with chroot worker process. Signed-off-by: M. Mohan Kumar --- Makefile.objs | 2 +- hw/9pfs/virtio-9p-chroot.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-chroot.h | 1 + 3 files changed, 94 insertions(+), 1 deletions(-) create mode 100644 hw/9pfs/virtio-9p-chroot.c diff --git a/Makefile.objs b/Makefile.objs index 44891c1..6610de9 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -283,7 +283,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p-debug.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o -9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-chroot-worker.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-chroot-worker.o virtio-9p-chroot.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): CFLAGS += -I$(SRC_PATH)/hw/ diff --git a/hw/9pfs/virtio-9p-chroot.c b/hw/9pfs/virtio-9p-chroot.c new file mode 100644 index 0000000..4aa3b43 --- /dev/null +++ b/hw/9pfs/virtio-9p-chroot.c @@ -0,0 +1,92 @@ +/* + * Virtio 9p chroot environment for contained access to exported path + * Code handles qemu side interfaces to communicate with chroot worker process + * Copyright IBM, Corp. 2011 + * + * Authors: + * M. Mohan Kumar + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the copying file in the top-level directory + * + */ + +#include +#include +#include +#include "virtio.h" +#include "qemu_socket.h" +#include "qemu-thread.h" +#include "qerror.h" +#include "virtio-9p.h" +#include "virtio-9p-chroot.h" + +/* + * Return received file descriptor on success and -errno on failure. + * sock_error is set to 1 whenever there is error in socket IO + */ +static int v9fs_receivefd(int sockfd, int *sock_error) +{ + struct msghdr msg = { }; + struct iovec iov; + union MsgControl msg_control; + struct cmsghdr *cmsg; + int retval, fd; + + iov.iov_base = &fd; + iov.iov_len = sizeof(fd); + + *sock_error = 0; + 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) { + *sock_error = 1; + return -EIO; + } + + if (fd < 0) { + return fd; + } + 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)); + return fd; + } + return fd; +} + +/* + * V9fsFileObjectRequest is written into the socket by QEMU process. + * Then this request is read by chroot process using v9fs_read_request function + */ +static int v9fs_write_request(int sockfd, V9fsFileObjectRequest *request) +{ + int retval; + retval = qemu_write_full(sockfd, request, sizeof(*request)); + if (retval != sizeof(*request)) { + return -EIO; + } + return 0; +} + +/* + * This patch adds v9fs_receivefd and v9fs_write_request functions, + * but there is no callers. To avoid compiler warning message, + * refer these two functions + */ +void chroot_dummy(void) +{ + (void)v9fs_receivefd; + (void)v9fs_write_request; +} diff --git a/hw/9pfs/virtio-9p-chroot.h b/hw/9pfs/virtio-9p-chroot.h index c05e05b8..a218f95 100644 --- a/hw/9pfs/virtio-9p-chroot.h +++ b/hw/9pfs/virtio-9p-chroot.h @@ -32,5 +32,6 @@ typedef struct V9fsFileObjectRequest } V9fsFileObjectRequest; int v9fs_chroot(FsContext *fs_ctx); +void chroot_dummy(void); #endif /* _QEMU_VIRTIO_9P_CHROOT_H */