qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 09/12] hw/9pfs: Proxy getversion
Date: Tue, 15 Nov 2011 17:27:41 +0530	[thread overview]
Message-ID: <1321358265-10924-10-git-send-email-mohan@in.ibm.com> (raw)
In-Reply-To: <1321358265-10924-1-git-send-email-mohan@in.ibm.com>

Add proxy getversion to get generation number

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
 fsdev/virtfs-proxy-helper.c |   74 +++++++++++++++++++++++++++++++++++++++++++
 hw/9pfs/virtio-9p-proxy.c   |   31 ++++++++++++++++++
 hw/9pfs/virtio-9p-proxy.h   |    1 +
 3 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index ccd7ed8..917bb26 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -30,6 +30,11 @@
 #include <sys/vfs.h>
 #include <sys/stat.h>
 #include <attr/xattr.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#ifdef CONFIG_LINUX_MAGIC_H
+#include <linux/magic.h>
+#endif
 #include "qemu-common.h"
 #include "virtio-9p-marshal.h"
 #include "hw/9pfs/virtio-9p-proxy.h"
@@ -38,6 +43,19 @@
 
 #define PROGNAME "virtfs-proxy-helper"
 
+#ifndef XFS_SUPER_MAGIC
+#define XFS_SUPER_MAGIC  0x58465342
+#endif
+#ifndef EXT2_SUPER_MAGIC
+#define EXT2_SUPER_MAGIC 0xEF53
+#endif
+#ifndef REISERFS_SUPER_MAGIC
+#define REISERFS_SUPER_MAGIC 0x52654973
+#endif
+#ifndef BTRFS_SUPER_MAGIC
+#define BTRFS_SUPER_MAGIC 0x9123683E
+#endif
+
 static struct option helper_opts[] = {
     {"fd", required_argument, NULL, 'f'},
     {"path", required_argument, NULL, 'p'},
@@ -45,6 +63,7 @@ static struct option helper_opts[] = {
 };
 
 int is_daemon;
+int get_version; /* IOC getversion IOCTL supported */
 
 static void do_perror(const char *string)
 {
@@ -284,6 +303,42 @@ static int send_response(int sock, struct iovec *iovec, int size)
     return 0;
 }
 
+/*
+ * gets generation number
+ * returns -errno on failure and sizeof(generation number) on success
+ */
+static int do_getversion(struct iovec *iovec, struct iovec *out_iovec)
+{
+    int fd, retval;
+    uint64_t version;
+    V9fsString path;
+
+    retval = sizeof(version);
+    /* no need to issue ioctl */
+    if (!get_version) {
+        version = 0;
+        proxy_marshal(out_iovec, 1, HDR_SZ, "q", version);
+        return retval;
+    }
+
+    proxy_unmarshal(iovec, 1, HDR_SZ, "s", &path);
+
+    fd = open(path.data, O_RDONLY);
+    if (fd < 0) {
+        retval = -errno;
+        goto done;
+    }
+    if (ioctl(fd, FS_IOC_GETVERSION, &version) < 0) {
+        retval = -errno;
+    } else {
+        proxy_marshal(out_iovec, 1, HDR_SZ, "q", version);
+    }
+    close(fd);
+done:
+    v9fs_string_free(&path);
+    return retval;
+}
+
 static int do_getxattr(int type, struct iovec *iovec, struct iovec *out_iovec)
 {
     int size = 0, offset, retval;
@@ -667,6 +722,9 @@ static int process_requests(int sock)
             v9fs_string_free(&path);
             v9fs_string_free(&name);
             break;
+        case T_GETVERSION:
+            size = do_getversion(&in_iovec, &out_iovec);
+            break;
         default:
             goto error;
             break;
@@ -697,6 +755,7 @@ static int process_requests(int sock)
         case T_READLINK:
         case T_LGETXATTR:
         case T_LLISTXATTR:
+        case T_GETVERSION:
             if (send_response(sock, &out_iovec, size) < 0) {
                 goto error;
             }
@@ -718,6 +777,8 @@ int main(int argc, char **argv)
     char rpath[PATH_MAX];
     struct stat stbuf;
     int c, option_index;
+    int retval;
+    struct statfs st_fs;
 
     is_daemon = 1;
     rpath[0] = '\0';
@@ -775,6 +836,19 @@ int main(int argc, char **argv)
 
     do_log(LOG_INFO, "Started");
 
+    /* check whether underlying FS support IOC_GETVERSION */
+    retval = statfs(rpath, &st_fs);
+    if (!retval) {
+        switch (st_fs.f_type) {
+        case EXT2_SUPER_MAGIC:
+        case BTRFS_SUPER_MAGIC:
+        case REISERFS_SUPER_MAGIC:
+        case XFS_SUPER_MAGIC:
+            get_version = 1;
+            break;
+        }
+    }
+
     if (chroot(rpath) < 0) {
         do_perror("chroot");
         goto error;
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index f672ac3..bc63835 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -209,6 +209,9 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type,
         }
         break;
     }
+    case T_GETVERSION:
+        proxy_unmarshal(reply, 1, HDR_SZ, "q", response);
+        break;
     default:
         *sock_error = 1;
         return -1;
@@ -450,6 +453,13 @@ 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_GETVERSION:
+        path = va_arg(ap, V9fsString *);
+        header.size = proxy_marshal(iovec, 1, HDR_SZ, "s", path);
+        header.type = T_GETVERSION;
+        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);
@@ -497,6 +507,7 @@ static int v9fs_request(V9fsProxy *proxy, int type,
     case T_STATFS:
     case T_LGETXATTR:
     case T_LLISTXATTR:
+    case T_GETVERSION:
         retval = v9fs_receive_response(proxy, type, &sock_error, size,
                         response);
         if (sock_error) {
@@ -978,6 +989,25 @@ static int proxy_unlinkat(FsContext *ctx, V9fsPath *dir,
     return ret;
 }
 
+static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path,
+                                mode_t st_mode, uint64_t *st_gen)
+{
+    int err;
+
+    /* Do not try to open special files like device nodes, fifos etc
+     * we can get fd for regular files and directories only
+     */
+    if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
+        return 0;
+    }
+    err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, "s", path);
+    if (err < 0) {
+        errno = -err;
+        err = -1;
+    }
+    return err;
+}
+
 static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs)
 {
     const char *sock_fd = qemu_opt_get(opts, "sock_fd");
@@ -1012,6 +1042,7 @@ static int proxy_init(FsContext *ctx)
     qemu_mutex_init(&proxy->mutex);
 
     ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
+    ctx->exops.get_st_gen = proxy_ioc_getversion;
     return 0;
 }
 
diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/virtio-9p-proxy.h
index 4c691a8..37c260b 100644
--- a/hw/9pfs/virtio-9p-proxy.h
+++ b/hw/9pfs/virtio-9p-proxy.h
@@ -43,6 +43,7 @@ enum {
     T_LLISTXATTR,
     T_LSETXATTR,
     T_LREMOVEXATTR,
+    T_GETVERSION,
 };
 
 typedef struct {
-- 
1.7.6

  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 ` [Qemu-devel] [PATCH V2 07/12] hw/9pfs: File ownership and others M. Mohan Kumar
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 ` M. Mohan Kumar [this message]
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-10-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).