All of lore.kernel.org
 help / color / mirror / Atom feed
From: "M. Mohan Kumar" <mohan@in.ibm.com>
To: qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com
Cc: "M. Mohan Kumar" <mohan@in.ibm.com>
Subject: [Qemu-devel] [PATCH 07/13] hw/9pfs: Create other filesystem objects
Date: Tue,  1 Nov 2011 02:23:26 +0530	[thread overview]
Message-ID: <1320094412-19091-8-git-send-email-mohan@in.ibm.com> (raw)
In-Reply-To: <1320094412-19091-1-git-send-email-mohan@in.ibm.com>

From: "M. Mohan Kumar" <mohan@in.ibm.com>

Add interfaces to create filesystem objects like directory,
device nodes, symbolic links, links for proxy filesytem driver

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
 hw/9pfs/proxy.h               |    4 ++
 hw/9pfs/virtfs-proxy-helper.c |   63 +++++++++++++++++++++-
 hw/9pfs/virtio-9p-proxy.c     |  119 +++++++++++++++++++++++++++++++++++++----
 3 files changed, 175 insertions(+), 11 deletions(-)

diff --git a/hw/9pfs/proxy.h b/hw/9pfs/proxy.h
index 69e7baa..5564eb5 100644
--- a/hw/9pfs/proxy.h
+++ b/hw/9pfs/proxy.h
@@ -17,6 +17,10 @@ typedef struct {
 enum {
     T_OPEN = 1,
     T_CREATE,
+    T_MKNOD,
+    T_MKDIR,
+    T_SYMLINK,
+    T_LINK,
 };
 
 #endif
diff --git a/hw/9pfs/virtfs-proxy-helper.c b/hw/9pfs/virtfs-proxy-helper.c
index 73609e1..82aa267 100644
--- a/hw/9pfs/virtfs-proxy-helper.c
+++ b/hw/9pfs/virtfs-proxy-helper.c
@@ -268,6 +268,48 @@ static int setfsugid(int uid, int gid)
 }
 
 /*
+ * create a other filesystem objects and send 0 on success
+ * return -errno on error
+ */
+static int do_create_others(int type, struct iovec *iovec)
+{
+    V9fsString oldpath, path;
+    int retval, mode, uid, gid, cur_uid, cur_gid;
+    dev_t rdev;
+    int offset;
+
+    cur_uid = geteuid();
+    cur_gid = getegid();
+
+    offset = v9fs_unmarshal(iovec, 1, 0, "dd", &uid, &gid);
+    if (setfsugid(uid, gid) < 0) {
+        return -EPERM;
+    }
+    switch (type) {
+    case T_MKNOD:
+        v9fs_unmarshal(iovec, 1, offset, "sdq", &path, &mode, &rdev);
+        retval = mknod(path.data, mode, rdev);
+        break;
+    case T_MKDIR:
+        v9fs_unmarshal(iovec, 1, offset, "sd", &path, &mode);
+        retval = mkdir(path.data, mode);
+        break;
+    case T_SYMLINK:
+        v9fs_unmarshal(iovec, 1, offset, "ss", &oldpath, &path);
+        retval = symlink(oldpath.data, path.data);
+        v9fs_string_free(&oldpath);
+        break;
+    }
+
+    if (retval < 0) {
+        retval = -errno;
+    }
+    v9fs_string_free(&path);
+    setfsugid(cur_uid, cur_gid);
+    return retval;
+}
+
+/*
  * create a file and send fd on success
  * return -errno on error
  */
@@ -325,6 +367,7 @@ static int process_requests(int sock)
     int type, retval;
     struct iovec iovec;
     int valid_fd;
+    V9fsString oldpath, path;
 
     iovec.iov_base = g_malloc(BUFF_SZ);
     iovec.iov_len = BUFF_SZ;
@@ -344,6 +387,20 @@ static int process_requests(int sock)
                 valid_fd = 1;
             }
             break;
+        case T_MKNOD:
+        case T_MKDIR:
+        case T_SYMLINK:
+            retval = do_create_others(type, &iovec);
+            break;
+        case T_LINK:
+            v9fs_unmarshal(&iovec, 1, 0, "ss", &oldpath, &path);
+            retval = link(oldpath.data, path.data);
+            if (retval < 0) {
+                retval = -errno;
+            }
+            v9fs_string_free(&oldpath);
+            v9fs_string_free(&path);
+            break;
         default:
             goto error;
             break;
@@ -353,7 +410,11 @@ static int process_requests(int sock)
         switch (type) {
         case T_OPEN:
         case T_CREATE:
-            sendfd(sock, retval, valid_fd);
+        case T_MKNOD:
+        case T_MKDIR:
+        case T_SYMLINK:
+        case T_LINK:
+             sendfd(sock, retval, valid_fd);
             break;
         default:
             break;
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index d686454..5f5eb35 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -97,9 +97,10 @@ static int v9fs_request(V9fsProxy *proxy, int type,
     int retval;
     ProxyHeader header;
     va_list ap;
-    V9fsString *path;
+    V9fsString *path, *oldpath;
     int sock_error, flags, mode, uid, gid;
     struct iovec *iovec = NULL;
+    dev_t rdev;
 
     qemu_mutex_lock(&proxy->mutex);
 
@@ -131,6 +132,49 @@ static int v9fs_request(V9fsProxy *proxy, int type,
         v9fs_marshal(iovec, 1, 0, "dd", header.type, header.size);
         header.size += sizeof(header);
         break;
+    case T_MKNOD:
+        path = va_arg(ap, V9fsString *);
+        mode = va_arg(ap, int);
+        rdev = va_arg(ap, long int);
+        uid = va_arg(ap, int);
+        gid = va_arg(ap, int);
+        header.size = v9fs_marshal(iovec, 1, sizeof(ProxyHeader), "ddsdq",
+                        uid, gid, path, mode, rdev);
+        header.type = T_MKNOD;
+        v9fs_marshal(iovec, 1, 0, "dd", header.type, header.size);
+        header.size += sizeof(header);
+        break;
+    case T_MKDIR:
+        path = va_arg(ap, V9fsString *);
+        mode = va_arg(ap, int);
+        uid = va_arg(ap, int);
+        gid = va_arg(ap, int);
+        header.size = v9fs_marshal(iovec, 1, sizeof(ProxyHeader), "ddsd",
+                        uid, gid, path, mode);
+        header.type = T_MKDIR;
+        v9fs_marshal(iovec, 1, 0, "dd", header.type, header.size);
+        header.size += sizeof(header);
+        break;
+    case T_SYMLINK:
+        oldpath = va_arg(ap, V9fsString *);
+        path = va_arg(ap, V9fsString *);
+        uid = va_arg(ap, int);
+        gid = va_arg(ap, int);
+        header.size = v9fs_marshal(iovec, 1, sizeof(ProxyHeader), "ddss",
+                        uid, gid, oldpath, path);
+        header.type = T_SYMLINK;
+        v9fs_marshal(iovec, 1, 0, "dd", header.type, header.size);
+        header.size += sizeof(header);
+        break;
+    case T_LINK:
+        oldpath = va_arg(ap, V9fsString *);
+        path = va_arg(ap, V9fsString *);
+        header.size = v9fs_marshal(iovec, 1, sizeof(ProxyHeader), "ss",
+                        oldpath, path);
+        header.type = T_LINK;
+        v9fs_marshal(iovec, 1, 0, "dd", header.type, header.size);
+        header.size += sizeof(header);
+        break;
     default:
         fprintf(stderr, "Invalid type %d\n", type);
         goto close_error;
@@ -149,6 +193,10 @@ static int v9fs_request(V9fsProxy *proxy, int type,
     switch (type) {
     case T_OPEN:
     case T_CREATE:
+    case T_MKNOD:
+    case T_MKDIR:
+    case T_SYMLINK:
+    case T_LINK:
         retval = v9fs_receivefd(proxy->sockfd, &sock_error);
         if (sock_error) {
             goto close_error;
@@ -294,15 +342,40 @@ static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
 static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
                        const char *name, FsCred *credp)
 {
-    errno = EOPNOTSUPP;
-    return -1;
+    V9fsString fullname;
+    int retval;
+    v9fs_string_init(&fullname);
+    v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
+
+    retval = v9fs_request(fs_ctx->private, T_MKNOD, NULL, "sdqdd",
+                    &fullname, credp->fc_mode, credp->fc_rdev,
+                    credp->fc_uid, credp->fc_gid);
+    v9fs_string_free(&fullname);
+    if (retval < 0) {
+        errno = -retval;
+        retval = -1;
+    }
+    return retval;
 }
 
 static int proxy_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
                        const char *name, FsCred *credp)
 {
-    errno = EOPNOTSUPP;
-    return -1;
+    V9fsString fullname;
+    int retval;
+
+    v9fs_string_init(&fullname);
+    v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
+
+    retval = v9fs_request(fs_ctx->private, T_MKDIR, NULL, "sddd", &fullname,
+                    credp->fc_mode, credp->fc_uid, credp->fc_gid);
+    v9fs_string_free(&fullname);
+    if (retval < 0) {
+        errno = -retval;
+        retval = -1;
+    }
+    v9fs_string_free(&fullname);
+    return retval;
 }
 
 static int proxy_fstat(FsContext *fs_ctx,
@@ -332,19 +405,45 @@ static int proxy_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
     return fs->fd;
 }
 
-
 static int proxy_symlink(FsContext *fs_ctx, const char *oldpath,
                          V9fsPath *dir_path, const char *name, FsCred *credp)
 {
-    errno = EOPNOTSUPP;
-    return -1;
+    V9fsString fullname, target;
+    int retval;
+
+    v9fs_string_init(&fullname);
+    v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
+    v9fs_string_init(&target);
+    v9fs_string_sprintf(&target, "%s", oldpath);
+
+    retval = v9fs_request(fs_ctx->private, T_SYMLINK, NULL, "ssdd",
+                    &target, &fullname, credp->fc_uid, credp->fc_gid);
+    v9fs_string_free(&fullname);
+    if (retval < 0) {
+        errno = -retval;
+        retval = -1;
+    }
+    return retval;
 }
 
 static int proxy_link(FsContext *ctx, V9fsPath *oldpath,
                       V9fsPath *dirpath, const char *name)
 {
-    errno = EOPNOTSUPP;
-    return -1;
+    int retval;
+    V9fsString newpath;
+
+    v9fs_string_init(&newpath);
+    v9fs_string_sprintf(&newpath, "%s/%s", dirpath->data, name);
+
+    retval = v9fs_request(ctx->private, T_LINK, NULL, "ss",
+                    oldpath, &newpath);
+    v9fs_string_free(&newpath);
+    if (retval < 0) {
+        errno = -retval;
+        retval = -1;
+    }
+    v9fs_string_free(&newpath);
+    return retval;
 }
 
 static int proxy_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
-- 
1.7.6

  parent reply	other threads:[~2011-10-31 20:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 20:53 [Qemu-devel] [PATCH 00/13] Proxy FS driver for VirtFS M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 01/13] hw/9pfs: Move opt validation to FsDriver callback M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 02/13] hw/9pfs: Move pdu_marshal/unmarshal code to a seperate file M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 03/13] hw/9pfs: Add new proxy filesystem driver M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 04/13] hw/9pfs: File system helper process for qemu 9p proxy FS M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 05/13] hw/9pfs: Add support to use named socket for " M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 06/13] hw/9pfs: Open and create files M. Mohan Kumar
2011-10-31 20:53 ` M. Mohan Kumar [this message]
2011-10-31 20:53 ` [Qemu-devel] [PATCH 08/13] hw/9pfs: Add stat/readlink/statfs for proxy FS M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 09/13] hw/9pfs: File ownership and others M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 10/13] hw/9pfs: xattr interfaces in proxy filesystem driver M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 12/13] hw/9pfs: Documentation changes related to proxy fs M. Mohan Kumar
2011-10-31 20:53 ` [Qemu-devel] [PATCH 13/13] hw/9pfs: man page for proxy helper M. Mohan Kumar

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=1320094412-19091-8-git-send-email-mohan@in.ibm.com \
    --to=mohan@in.ibm.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.