From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53083 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpgWO-0000W6-96 for qemu-devel@nongnu.org; Wed, 16 Feb 2011 07:30:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PpgWM-0003ep-Q9 for qemu-devel@nongnu.org; Wed, 16 Feb 2011 07:30:16 -0500 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:56200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PpgWL-0003ed-Vu for qemu-devel@nongnu.org; Wed, 16 Feb 2011 07:30:14 -0500 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp06.in.ibm.com (8.14.4/8.13.1) with ESMTP id p1GCNI9n002053 for ; Wed, 16 Feb 2011 17:53:18 +0530 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 p1GCNGji2592840 for ; Wed, 16 Feb 2011 17:53:17 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p1GCNGpb009584 for ; Wed, 16 Feb 2011 23:23:16 +1100 From: "M. Mohan Kumar" Date: Wed, 16 Feb 2011 17:53:10 +0530 Message-Id: <1297858995-24676-4-git-send-email-mohan@in.ibm.com> In-Reply-To: <1297858995-24676-1-git-send-email-mohan@in.ibm.com> References: <1297858995-24676-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [V5 PATCH 3/8] virtio-9p: Add client side interfaces for chroot environment List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Stefan Hajnoczi , "Daniel P. Berrange" , blauwirbel@gmail.com Define QEMU side interfaces used for chroot environment. Signed-off-by: M. Mohan Kumar --- Makefile.objs | 2 +- hw/9pfs/virtio-9p-chroot-clnt.c | 96 +++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-chroot.h | 1 + 3 files changed, 98 insertions(+), 1 deletions(-) create mode 100644 hw/9pfs/virtio-9p-chroot-clnt.c diff --git a/Makefile.objs b/Makefile.objs index bf8ebd9..c98cb72 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -282,7 +282,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-sv.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-chroot-sv.o virtio-9p-chroot-clnt.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-clnt.c b/hw/9pfs/virtio-9p-chroot-clnt.c new file mode 100644 index 0000000..ac65f03 --- /dev/null +++ b/hw/9pfs/virtio-9p-chroot-clnt.c @@ -0,0 +1,96 @@ +/* + * Virtio 9p chroot environment for contained access to exported path + * Client code + * 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" + +/* Receive file descriptor and error status from chroot process */ +static int v9fs_receivefd(int sockfd, int *error) +{ + struct msghdr msg = { }; + struct iovec iov; + union MsgControl msg_control; + struct cmsghdr *cmsg; + int retval, fd; + FdInfo fd_info; + + iov.iov_base = &fd_info; + iov.iov_len = sizeof(fd_info); + + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = &msg_control; + msg.msg_controllen = sizeof(msg_control); + + *error = 0; + retval = recvmsg(sockfd, &msg, 0); + if (retval < 0) { + *error = EIO; + return -EIO; + } + if (fd_info.fi_flags & FI_SOCKERR) { + *error = EIO; + return -EIO; + } + /* If error is set, ancillary data is not present */ + if (fd_info.fi_error) { + *error = fd_info.fi_error; + return -1; + } + + if (!fd_info.fi_flags & FI_FDVALID) { + return 0; + } + + 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; + } + + *error = EAGAIN; + return -1; +} + +/* + * V9fsFileObjectRequest is written into the socket by QEMU process. + * Then this request is read by chroot process using 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; +} + +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 73cf144..9122edc 100644 --- a/hw/9pfs/virtio-9p-chroot.h +++ b/hw/9pfs/virtio-9p-chroot.h @@ -53,5 +53,6 @@ typedef struct V9fsFileObjectRequest } V9fsFileObjectRequest; int v9fs_chroot(FsContext *fs_ctx); +void chroot_dummy(void); #endif /* _QEMU_VIRTIO_9P_CHROOT_H */ -- 1.7.3.4