qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com,
	Harsh Prateek Bora <harsh@linux.vnet.ibm.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -V2 08/13] hw/9pfs: Add st_gen support in getattr reply
Date: Tue, 11 Oct 2011 16:11:40 +0530	[thread overview]
Message-ID: <1318329705-3179-9-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1318329705-3179-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

From: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>

This patch use file system specific ioctl for getting i_generation
value. Not all file system support the ioctl. So we add an export
specific extended operation and assign right callback for the
file system that support i_generation ioctl

["M. Mohan Kumar" <mohan@in.ibm.com> we can do ioctl only for
regular files and directories on the server]

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 configure                  |   17 +++++++++++++
 fsdev/file-op-9p.h         |    8 ++++++
 hw/9pfs/cofile.c           |   24 +++++++++++++++++++
 hw/9pfs/virtio-9p-coth.h   |    3 ++
 hw/9pfs/virtio-9p-device.c |    2 +
 hw/9pfs/virtio-9p-local.c  |   54 +++++++++++++++++++++++++++++++++++++++++++-
 hw/9pfs/virtio-9p.c        |    9 +++++++
 7 files changed, 116 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 0216c53..4ce4f1f 100755
--- a/configure
+++ b/configure
@@ -2562,6 +2562,19 @@ if compile_prog "" "" ; then
     open_by_handle_at=yes
 fi
 
+########################################
+# check if we have linux/magic.h
+
+linux_magic_h=no
+cat > $TMPC << EOF
+#include <linux/magic.h>
+int main(void) {
+}
+EOF
+if compile_prog "" "" ; then
+    linux_magic_h=yes
+fi
+
 ##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -3045,6 +3058,10 @@ if test "$open_by_handle_at" = "yes" ; then
   echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
 fi
 
+if test "$linux_magic_h" = "yes" ; then
+  echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak
+fi
+
 # USB host support
 case "$usb" in
 linux)
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 84ec9e0..33fb07f 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -49,6 +49,13 @@ typedef struct FsCred
 } FsCred;
 
 struct xattr_operations;
+struct FsContext;
+struct V9fsPath;
+
+typedef struct extended_ops {
+    int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
+                      mode_t, uint64_t *);
+} extended_ops;
 
 /* FsContext flag values */
 #define PATHNAME_FSCONTEXT 0x1
@@ -64,6 +71,7 @@ typedef struct FsContext
     uid_t uid;
     int cache_flags;
     struct xattr_operations **xops;
+    struct extended_ops exops;
     /* fs driver specific data */
     void *private;
 } FsContext;
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 7ad4bec..692811e 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -17,6 +17,30 @@
 #include "qemu-coroutine.h"
 #include "virtio-9p-coth.h"
 
+int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
+                   V9fsStatDotl *v9stat)
+{
+    int err = 0;
+    V9fsState *s = pdu->s;
+
+    if (v9fs_request_cancelled(pdu)) {
+        return -EINTR;
+    }
+    if (s->ctx.exops.get_st_gen) {
+        v9fs_path_read_lock(s);
+        v9fs_co_run_in_worker(
+            {
+                err = s->ctx.exops.get_st_gen(&s->ctx, path, st_mode,
+                                              &v9stat->st_gen);
+                if (err < 0) {
+                    err = -errno;
+                }
+            });
+        v9fs_path_unlock(s);
+    }
+    return err;
+}
+
 int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
 {
     int err;
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 4630080..ca96b9c 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -101,4 +101,7 @@ extern int v9fs_co_preadv(V9fsPDU *, V9fsFidState *,
                           struct iovec *, int, int64_t);
 extern int v9fs_co_name_to_path(V9fsPDU *, V9fsPath *,
                                 const char *, V9fsPath *);
+extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t,
+                          V9fsStatDotl *v9stat);
+
 #endif
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 0930d22..bc25af5 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -117,6 +117,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
 
     s->ctx.cache_flags = fse->cache_flags;
     s->ctx.fs_root = g_strdup(fse->path);
+    s->ctx.exops.get_st_gen = NULL;
+
     len = strlen(conf->tag);
     if (len > MAX_TAG_LEN) {
         fprintf(stderr, "mount tag '%s' (%d bytes) is longer than "
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index 5745d14..aca4706 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -20,6 +20,24 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <attr/xattr.h>
+#include <linux/fs.h>
+#ifdef CONFIG_LINUX_MAGIC_H
+#include <linux/magic.h>
+#endif
+#include <sys/ioctl.h>
+
+#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 int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
 {
@@ -654,10 +672,44 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
     return ret;
 }
 
+static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
+                                mode_t st_mode, uint64_t *st_gen)
+{
+    int err, fd;
+    /*
+     * 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;
+    }
+    fd = local_open(ctx, path, O_RDONLY);
+    if (fd < 0) {
+        return fd;
+    }
+    err = ioctl(fd, FS_IOC_GETVERSION, st_gen);
+    local_close(ctx, fd);
+    return err;
+}
+
 static int local_init(FsContext *ctx)
 {
+    int err;
+    struct statfs stbuf;
+
     ctx->flags |= PATHNAME_FSCONTEXT;
-    return 0;
+    err = statfs(ctx->fs_root, &stbuf);
+    if (!err) {
+        switch (stbuf.f_type) {
+        case EXT2_SUPER_MAGIC:
+        case BTRFS_SUPER_MAGIC:
+        case REISERFS_SUPER_MAGIC:
+        case XFS_SUPER_MAGIC:
+            ctx->exops.get_st_gen = local_ioc_getversion;
+            break;
+        }
+    }
+    return err;
 }
 
 FileOperations local_ops = {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index dcbcdb0..2ad8f84 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1402,6 +1402,15 @@ static void v9fs_getattr(void *opaque)
         goto out;
     }
     stat_to_v9stat_dotl(s, &stbuf, &v9stat_dotl);
+
+    /*  fill st_gen if requested and supported by underlying fs */
+    if (request_mask & P9_STATS_GEN) {
+        retval = v9fs_co_st_gen(pdu, &fidp->path, stbuf.st_mode, &v9stat_dotl);
+        if (retval < 0) {
+            goto out;
+        }
+        v9stat_dotl.st_result_mask |= P9_STATS_GEN;
+    }
     retval = offset;
     retval += pdu_marshal(pdu, offset, "A", &v9stat_dotl);
 out:
-- 
1.7.5.4

  parent reply	other threads:[~2011-10-11 10:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 10:41 [Qemu-devel] [PATCH V2 00/13] VirtFS update Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 01/13] hw/9pfs: Use ioeventfd for 9p Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 02/13] hw/9pfs: Add new virtfs option cache=writethrough to skip host page cache Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 03/13] qemu-options.hx: Update virtfs command documentation Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 04/13] hw/9pfs: Fix build error on platform that don't support futimens Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 05/13] virtio-9p: Use 9P specific Lock constants Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 06/13] hw/9pfs: Ensure an error is reported to user if 9pfs mount tag is too long Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 07/13] hw/9pfs: Add open flag mapping Aneesh Kumar K.V
2011-10-11 10:41 ` Aneesh Kumar K.V [this message]
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 09/13] hw/9pfs: Add st_gen support for handle based fs driver Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 10/13] hw/9pfs: Introduce tracing for 9p pdu handlers Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 11/13] hw/9pfs: Remove virtio-9p-debug.* infra to be replaced by Qemu Tracing Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 12/13] scripts: Simpletrace log analysis script for pretty-printing 9p log Aneesh Kumar K.V
2011-10-11 10:41 ` [Qemu-devel] [PATCH -V2 13/13] hw/9pfs: Use fs driver specific lstat Aneesh Kumar K.V

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=1318329705-3179-9-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=harsh@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 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).