From patchwork Fri Jun 24 08:22:24 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: 101760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0DC3FB6F90 for ; Fri, 24 Jun 2011 19:32:21 +1000 (EST) Received: from localhost ([::1]:56782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa2kK-0006So-FA for incoming@patchwork.ozlabs.org; Fri, 24 Jun 2011 05:32:16 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1f2-00070q-Fq for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qa1ey-0002TO-Ge for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:44 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:43500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1ex-0002Qt-2S for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:40 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp04.in.ibm.com (8.14.4/8.13.1) with ESMTP id p5O8MUHJ020276 for ; Fri, 24 Jun 2011 13:52:30 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5O8MTQr299042 for ; Fri, 24 Jun 2011 13:52:29 +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 p5O8MTgd004295 for ; Fri, 24 Jun 2011 13:52:29 +0530 Received: from virtfs.in.ibm.com ([9.124.35.90]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p5O8MS7q004156; Fri, 24 Jun 2011 13:52:29 +0530 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org Date: Fri, 24 Jun 2011 13:52:24 +0530 Message-Id: <1308903744-2870-16-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1308903744-2870-1-git-send-email-mohan@in.ibm.com> References: <1308903744-2870-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.4 Cc: "M. Mohan Kumar" Subject: [Qemu-devel] [V11 15/15] virtio-9p: Chroot environment for other functions 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 From: "M. Mohan Kumar" Add chroot functionality for system calls that can operate on a file using relative directory file descriptor. Signed-off-by: M. Mohan Kumar --- hw/9pfs/virtio-9p-local.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index e865cc8..5847d43 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -608,7 +608,25 @@ static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) char buffer[PATH_MAX]; char *path = fs_path->data; - return truncate(rpath(ctx, path, buffer), size); + if (ctx->fs_sm == SM_PASSTHROUGH) { + int fd, retval, serrno; + fd = passthrough_request(ctx, NULL, path, O_RDWR, NULL, T_OPEN); + if (fd < 0) { + errno = -fd; + return -1; + } + retval = ftruncate(fd, size); + if (retval < 0) { + serrno = errno; + } + close(fd); + if (retval < 0) { + errno = serrno; + } + return retval; + } else { + return truncate(rpath(ctx, path, buffer), size); + } } static int local_rename(FsContext *ctx, const char *oldpath, @@ -648,8 +666,27 @@ static int local_utimensat(FsContext *s, V9fsPath *fs_path, char buffer[PATH_MAX]; char *path = fs_path->data; - return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf, + if (s->fs_sm == SM_PASSTHROUGH) { + int fd, retval, serrno = 0; + fd = passthrough_request(s, NULL, path, + O_RDONLY | O_NONBLOCK | O_NOFOLLOW, NULL, T_OPEN); + if (fd < 0) { + errno = -fd; + return -1; + } + retval = futimens(fd, buf); + if (retval < 0) { + serrno = errno; + } + close(fd); + if (retval < 0) { + errno = serrno; + } + return retval; + } else { + return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf, AT_SYMLINK_NOFOLLOW); + } } static int local_remove(FsContext *ctx, const char *path)