From patchwork Mon Dec 5 16:18:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "M. Mohan Kumar" X-Patchwork-Id: 129370 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 C9AB8B6F9B for ; Tue, 6 Dec 2011 04:12:35 +1100 (EST) Received: from localhost ([::1]:54302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXbJg-0001f0-2W for incoming@patchwork.ozlabs.org; Mon, 05 Dec 2011 11:22:56 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXbIb-0007D1-HG for qemu-devel@nongnu.org; Mon, 05 Dec 2011 11:21:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXbIU-0008Tn-FG for qemu-devel@nongnu.org; Mon, 05 Dec 2011 11:21:44 -0500 Received: from mail-yw0-f45.google.com ([209.85.213.45]:43928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXbIU-0008Td-AV for qemu-devel@nongnu.org; Mon, 05 Dec 2011 11:21:42 -0500 Received: by ywe9 with SMTP id 9so5954475ywe.4 for ; Mon, 05 Dec 2011 08:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=PItNAVz8XVaLfM/1El4D3NcrqCpeZxwaJ9X+epO6eqw=; b=gtdtFfamFgy95JDWksuZwk22QyHTGFVxNYBz6MAj3LcR2MeOdzFTAmMDEcoFm2z1/t FLLNKZapIMibIcXQ/DN5MgANLwsjfCBqMDX8BoYChqmiKmFgiOsU54DDJ2uOsJ6Ncdon 446yyeZXY9FVLUXEpAPIwE4M2sMJqt2100tL0= Received: by 10.50.208.100 with SMTP id md4mr10986756igc.9.1323102101616; Mon, 05 Dec 2011 08:21:41 -0800 (PST) Received: from explorer.in.ibm.com ([117.192.11.142]) by mx.google.com with ESMTPS id el2sm78245721ibb.10.2011.12.05.08.21.38 (version=SSLv3 cipher=OTHER); Mon, 05 Dec 2011 08:21:40 -0800 (PST) From: "M. Mohan Kumar" To: qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com, stefanha@gmail.com Date: Mon, 5 Dec 2011 21:48:45 +0530 Message-Id: <1323101930-27163-9-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1323101930-27163-1-git-send-email-mohan@in.ibm.com> References: <1323101930-27163-1-git-send-email-mohan@in.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.45 Cc: "M. Mohan Kumar" Subject: [Qemu-devel] [PATCH V4 08/13] hw/9pfs: File ownership and others 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 file ownership interfaces like chmod/chown, utime update, rename, remove and truncating files for proxy FS Signed-off-by: M. Mohan Kumar --- Makefile | 2 +- fsdev/virtfs-proxy-helper.c | 83 +++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 142 +++++++++++++++++++++++++++++++++++++++---- hw/9pfs/virtio-9p-proxy.h | 6 ++ 4 files changed, 220 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 1906c5e..0acad52 100644 --- a/Makefile +++ b/Makefile @@ -154,7 +154,7 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) -fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o +fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o oslib-posix.o $(trace-obj-y) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 8bb1e06..871e3f4 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -610,6 +610,12 @@ static int process_reply(int sock, int type, case T_MKDIR: case T_SYMLINK: case T_LINK: + case T_CHMOD: + case T_CHOWN: + case T_TRUNCATE: + case T_UTIME: + case T_RENAME: + case T_REMOVE: if (send_status(sock, out_iovec, retval) < 0) { return -1; } @@ -631,7 +637,10 @@ static int process_reply(int sock, int type, static int process_requests(int sock) { int retval = 0; + uint64_t offset; ProxyHeader header; + int mode, uid, gid; + struct timespec spec[2]; V9fsString oldpath, path; struct iovec in_iovec, out_iovec; @@ -697,6 +706,80 @@ static int process_requests(int sock) case T_READLINK: retval = do_readlink(&in_iovec, &out_iovec); break; + case T_CHMOD: + v9fs_string_init(&path); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, + "sd", &path, &mode); + if (retval > 0) { + retval = chmod(path.data, mode); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&path); + break; + case T_CHOWN: + v9fs_string_init(&path); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sdd", &path, + &uid, &gid); + if (retval > 0) { + retval = lchown(path.data, uid, gid); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&path); + break; + case T_TRUNCATE: + v9fs_string_init(&path); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sq", + &path, &offset); + if (retval > 0) { + retval = truncate(path.data, offset); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&path); + break; + case T_UTIME: + v9fs_string_init(&path); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sqqqq", &path, + &spec[0].tv_sec, &spec[0].tv_nsec, + &spec[1].tv_sec, &spec[1].tv_nsec); + if (retval > 0) { + retval = qemu_utimens(path.data, spec); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&path); + break; + case T_RENAME: + v9fs_string_init(&path); + v9fs_string_init(&oldpath); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, + "ss", &oldpath, &path); + if (retval > 0) { + retval = rename(oldpath.data, path.data); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&oldpath); + v9fs_string_free(&path); + break; + case T_REMOVE: + v9fs_string_init(&path); + retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "s", &path); + if (retval > 0) { + retval = remove(path.data); + if (retval < 0) { + retval = -errno; + } + } + v9fs_string_free(&path); + break; default: goto err_out; break; diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index bfbdcb5..588d806 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -287,7 +287,9 @@ static int v9fs_request(V9fsProxy *proxy, int type, va_list ap; int size = 0; int retval = 0; + uint64_t offset; ProxyHeader header; + struct timespec spec[2]; int flags, mode, uid, gid; V9fsString *path, *oldpath; struct iovec *iovec = NULL, *reply = NULL; @@ -405,6 +407,71 @@ static int v9fs_request(V9fsProxy *proxy, int type, } header.type = T_STATFS; break; + case T_CHMOD: + path = va_arg(ap, V9fsString *); + mode = va_arg(ap, int); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, mode); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_CHMOD; + break; + case T_CHOWN: + path = va_arg(ap, V9fsString *); + uid = va_arg(ap, int); + gid = va_arg(ap, int); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "sdd", path, uid, gid); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_CHOWN; + break; + case T_TRUNCATE: + path = va_arg(ap, V9fsString *); + offset = va_arg(ap, uint64_t); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "sq", path, offset); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_TRUNCATE; + break; + case T_UTIME: + path = va_arg(ap, V9fsString *); + spec[0].tv_sec = va_arg(ap, long); + spec[0].tv_nsec = va_arg(ap, long); + spec[1].tv_sec = va_arg(ap, long); + spec[1].tv_nsec = va_arg(ap, long); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "sqqqq", path, + spec[0].tv_sec, spec[1].tv_nsec, + spec[1].tv_sec, spec[1].tv_nsec); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_UTIME; + break; + case T_RENAME: + oldpath = va_arg(ap, V9fsString *); + path = va_arg(ap, V9fsString *); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", oldpath, path); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_RENAME; + break; + case T_REMOVE: + path = va_arg(ap, V9fsString *); + header.size = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); + if (header.size < 0) { + retval = header.size; + break; + } + header.type = T_REMOVE; + break; default: error_report("Invalid type %d\n", type); retval = -EINVAL; @@ -440,6 +507,12 @@ static int v9fs_request(V9fsProxy *proxy, int type, case T_MKDIR: case T_SYMLINK: case T_LINK: + case T_CHMOD: + case T_CHOWN: + case T_RENAME: + case T_TRUNCATE: + case T_UTIME: + case T_REMOVE: if (v9fs_receive_status(proxy, reply, &retval) < 0) { goto close_error; } @@ -600,8 +673,13 @@ static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs, static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) { - errno = EOPNOTSUPP; - return -1; + int retval; + retval = v9fs_request(fs_ctx->private, T_CHMOD, NULL, "sd", + fs_path, credp->fc_mode); + if (retval < 0) { + errno = -retval; + } + return retval; } static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path, @@ -719,34 +797,74 @@ static int proxy_link(FsContext *ctx, V9fsPath *oldpath, static int proxy_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) { - errno = EOPNOTSUPP; - return -1; + int retval; + + retval = v9fs_request(ctx->private, T_TRUNCATE, NULL, "sq", fs_path, size); + if (retval < 0) { + errno = -retval; + return -1; + } + return 0; } static int proxy_rename(FsContext *ctx, const char *oldpath, const char *newpath) { - errno = EOPNOTSUPP; - return -1; + int retval; + V9fsString oldname, newname; + + v9fs_string_init(&oldname); + v9fs_string_init(&newname); + + v9fs_string_sprintf(&oldname, "%s", oldpath); + v9fs_string_sprintf(&newname, "%s", newpath); + retval = v9fs_request(ctx->private, T_RENAME, NULL, "ss", + &oldname, &newname); + v9fs_string_free(&oldname); + v9fs_string_free(&newname); + if (retval < 0) { + errno = -retval; + } + return retval; } static int proxy_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) { - errno = EOPNOTSUPP; - return -1; + int retval; + retval = v9fs_request(fs_ctx->private, T_CHOWN, NULL, "sdd", + fs_path, credp->fc_uid, credp->fc_gid); + if (retval < 0) { + errno = -retval; + } + return retval; } static int proxy_utimensat(FsContext *s, V9fsPath *fs_path, const struct timespec *buf) { - errno = EOPNOTSUPP; - return -1; + int retval; + retval = v9fs_request(s->private, T_UTIME, NULL, "sqqqq", + fs_path, + buf[0].tv_sec, buf[0].tv_nsec, + buf[1].tv_sec, buf[1].tv_nsec); + if (retval < 0) { + errno = -retval; + } + return retval; } static int proxy_remove(FsContext *ctx, const char *path) { - errno = EOPNOTSUPP; - return -1; + int retval; + V9fsString name; + v9fs_string_init(&name); + v9fs_string_sprintf(&name, "%s", path); + retval = v9fs_request(ctx->private, T_REMOVE, NULL, "s", &name); + v9fs_string_free(&name); + if (retval < 0) { + errno = -retval; + } + return retval; } static int proxy_fsync(FsContext *ctx, int fid_type, diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/virtio-9p-proxy.h index f08874a..49aae66 100644 --- a/hw/9pfs/virtio-9p-proxy.h +++ b/hw/9pfs/virtio-9p-proxy.h @@ -48,6 +48,12 @@ enum { T_LSTAT, T_READLINK, T_STATFS, + T_CHMOD, + T_CHOWN, + T_TRUNCATE, + T_UTIME, + T_RENAME, + T_REMOVE, }; typedef struct {