From: "M. Mohan Kumar" <mohan@in.ibm.com>
To: qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
stefanha@gmail.com, berrange@redhat.com
Subject: [Qemu-devel] [PATCH V2 07/12] hw/9pfs: File ownership and others
Date: Tue, 15 Nov 2011 17:27:39 +0530 [thread overview]
Message-ID: <1321358265-10924-8-git-send-email-mohan@in.ibm.com> (raw)
In-Reply-To: <1321358265-10924-1-git-send-email-mohan@in.ibm.com>
Add file ownership interfaces like chmod/chown, utime update, rename,
remove and truncating files for proxy FS
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
Makefile | 2 +-
fsdev/virtfs-proxy-helper.c | 66 +++++++++++++++++++++
hw/9pfs/virtio-9p-proxy.c | 134 +++++++++++++++++++++++++++++++++++++++----
hw/9pfs/virtio-9p-proxy.h | 6 ++
4 files changed, 195 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
index 19b481a..378ee4d 100644
--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,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
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 eb33504..ded0ead 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -495,6 +495,9 @@ static void usage(char *prog)
static int process_requests(int sock)
{
+ uint64_t offset;
+ int mode, uid, gid;
+ struct timespec spec[2];
int type, retval = 0;
V9fsString oldpath, path;
struct iovec in_iovec, out_iovec;
@@ -535,6 +538,63 @@ static int process_requests(int sock)
case T_READLINK:
size = do_readlink(&in_iovec, &out_iovec);
break;
+ case T_CHMOD:
+ proxy_unmarshal(&in_iovec, 1, HDR_SZ, "sd",
+ &path, &mode);
+ retval = chmod(path.data, mode);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&path);
+ break;
+ case T_CHOWN:
+ proxy_unmarshal(&in_iovec, 1, HDR_SZ, "sdd", &path,
+ &uid, &gid);
+ retval = lchown(path.data, uid, gid);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&path);
+ break;
+ case T_TRUNCATE:
+ proxy_unmarshal(&in_iovec, 1, HDR_SZ, "sq",
+ &path, &offset);
+ retval = truncate(path.data, offset);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&path);
+ break;
+ case T_UTIME:
+ proxy_unmarshal(&in_iovec, 1,
+ HDR_SZ, "sqqqq", &path,
+ &spec[0].tv_sec, &spec[0].tv_nsec,
+ &spec[1].tv_sec, &spec[1].tv_nsec);
+ retval = qemu_utimensat(AT_FDCWD, path.data, spec,
+ AT_SYMLINK_NOFOLLOW);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&path);
+ break;
+ case T_RENAME:
+ proxy_unmarshal(&in_iovec, 1,
+ HDR_SZ, "ss", &oldpath, &path);
+ retval = rename(oldpath.data, path.data);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&oldpath);
+ v9fs_string_free(&path);
+ break;
+ case T_REMOVE:
+ proxy_unmarshal(&in_iovec, 1, HDR_SZ, "s", &path);
+ retval = remove(path.data);
+ if (retval < 0) {
+ retval = -errno;
+ }
+ v9fs_string_free(&path);
+ break;
default:
goto error;
break;
@@ -550,6 +610,12 @@ static int process_requests(int sock)
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:
send_status(sock, &out_iovec, retval);
break;
case T_LSTAT:
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index 090db44..aefdc61 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -242,6 +242,8 @@ static int v9fs_request(V9fsProxy *proxy, int type,
struct iovec *iovec = NULL, *reply = NULL;
dev_t rdev;
int size = 0;
+ struct timespec spec[2];
+ uint64_t offset;
qemu_mutex_lock(&proxy->mutex);
@@ -339,6 +341,63 @@ static int v9fs_request(V9fsProxy *proxy, int type,
proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
header.size += HDR_SZ;
break;
+ case T_CHMOD:
+ path = va_arg(ap, V9fsString *);
+ mode = va_arg(ap, int);
+ header.size = proxy_marshal(iovec, 1, HDR_SZ, "sd",
+ path, mode);
+ header.type = T_CHMOD;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ break;
+ case T_CHOWN:
+ path = va_arg(ap, V9fsString *);
+ uid = va_arg(ap, int);
+ gid = va_arg(ap, int);
+ header.size = proxy_marshal(iovec, 1, HDR_SZ, "sdd",
+ path, uid, gid);
+ header.type = T_CHOWN;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ break;
+ case T_TRUNCATE:
+ path = va_arg(ap, V9fsString *);
+ offset = va_arg(ap, uint64_t);
+ header.size = proxy_marshal(iovec, 1, HDR_SZ, "sq",
+ path, offset);
+ header.type = T_TRUNCATE;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ 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, 1, HDR_SZ, "sqqqq",
+ path, spec[0].tv_sec, spec[1].tv_nsec,
+ spec[1].tv_sec, spec[1].tv_nsec);
+ header.type = T_UTIME;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ break;
+ case T_RENAME:
+ oldpath = va_arg(ap, V9fsString *);
+ path = va_arg(ap, V9fsString *);
+ header.size = proxy_marshal(iovec, 1, HDR_SZ, "ss",
+ oldpath, path);
+ header.type = T_RENAME;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ break;
+ case T_REMOVE:
+ path = va_arg(ap, V9fsString *);
+ header.size = proxy_marshal(iovec, 1, HDR_SZ, "s", path);
+ header.type = T_REMOVE;
+ proxy_marshal(iovec, 1, 0, "dd", header.type, header.size);
+ header.size += HDR_SZ;
+ break;
default:
error_report("Invalid type %d\n", type);
va_end(ap);
@@ -368,6 +427,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:
retval = v9fs_receive_status(proxy, &sock_error, reply);
if (sock_error) {
goto close_error;
@@ -530,8 +595,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,
@@ -644,34 +714,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, V9fsFidOpenState *fs, int datasync)
diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/virtio-9p-proxy.h
index 578ca19..ef8a0f3 100644
--- a/hw/9pfs/virtio-9p-proxy.h
+++ b/hw/9pfs/virtio-9p-proxy.h
@@ -33,6 +33,12 @@ enum {
T_LSTAT,
T_READLINK,
T_STATFS,
+ T_CHMOD,
+ T_CHOWN,
+ T_TRUNCATE,
+ T_UTIME,
+ T_RENAME,
+ T_REMOVE,
};
typedef struct {
--
1.7.6
next prev parent reply other threads:[~2011-11-15 11:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-15 11:57 [Qemu-devel] [PATCH V2 00/12] Proxy FS driver for VirtFS M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 01/12] hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 02/12] hw/9pfs: Add new proxy filesystem driver M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 03/12] hw/9pfs: File system helper process for qemu 9p proxy FS M. Mohan Kumar
2011-11-15 14:03 ` Stefan Hajnoczi
2011-11-16 8:51 ` M. Mohan Kumar
2011-11-16 10:23 ` Stefan Hajnoczi
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 04/12] hw/9pfs: Open and create files M. Mohan Kumar
2011-11-17 15:46 ` Stefan Hajnoczi
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 05/12] hw/9pfs: Create other filesystem objects M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 06/12] hw/9pfs: Add stat/readlink/statfs for proxy FS M. Mohan Kumar
2011-11-15 11:57 ` M. Mohan Kumar [this message]
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 08/12] hw/9pfs: xattr interfaces in proxy filesystem driver M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 09/12] hw/9pfs: Proxy getversion M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 10/12] hw/9pfs: Documentation changes related to proxy fs M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 11/12] hw/9pfs: man page for proxy helper M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH V2 12/12] hw/9pfs: Add support to use named socket for proxy FS M. Mohan Kumar
2011-11-15 11:57 ` [Qemu-devel] [PATCH 00/12] Proxy FS driver for VirtFS M. Mohan Kumar
2011-11-15 12:09 ` [Qemu-devel] [PATCH V2 " M. Mohan Kumar
2011-11-17 16:00 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321358265-10924-8-git-send-email-mohan@in.ibm.com \
--to=mohan@in.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).