Patchwork [v2,2/2] i_generation / st_gen support for handle based fs driver

login
register
mail settings
Submitter Harsh Prateek Bora
Date Aug. 10, 2011, 5:36 a.m.
Message ID <1312954562-17540-3-git-send-email-harsh@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/109333/
State New
Headers show

Comments

Harsh Prateek Bora - Aug. 10, 2011, 5:36 a.m.
v2:
- close fd after use in handle_ioc_getversion

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p-handle.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index 548a841..98178e9 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -20,6 +20,9 @@ 
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <attr/xattr.h>
+#include <linux/fs.h>
+#include <linux/magic.h>
+#include <sys/ioctl.h>
 
 struct handle_data {
     int mountfd;
@@ -543,9 +546,26 @@  static int handle_unlinkat(FsContext *ctx, V9fsPath *dir,
     return ret;
 }
 
+static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path, uint64_t *st_gen)
+{
+    int mode = 0600;
+    int fd, err;
+
+    fd = handle_open(ctx, path, mode);
+    if(fd < 0) {
+        return fd;
+    }
+    err = ioctl(fd, FS_IOC_GETVERSION, st_gen);
+    handle_close(ctx, fd);
+    return err;
+}
+
+/*  XFS_SUPER_MAGIC not available in linux/fs.h */
+#define XFS_SUPER_MAGIC 0x58465342
 static int handle_init(FsContext *ctx)
 {
     int ret, mnt_id;
+    struct statfs stbuf;
     struct file_handle fh;
     struct handle_data *data = qemu_malloc(sizeof(struct handle_data));
     data->mountfd = open(ctx->fs_root, O_DIRECTORY);
@@ -553,6 +573,17 @@  static int handle_init(FsContext *ctx)
         ret = data->mountfd;
         goto err_out;
     }
+    ret = statfs(ctx->fs_root, &stbuf);
+    if(!ret) {
+        switch (stbuf.f_type) {
+        case EXT4_SUPER_MAGIC: /*  same magic val for ext2/3 */
+        case BTRFS_SUPER_MAGIC:
+        case REISERFS_SUPER_MAGIC:
+        case XFS_SUPER_MAGIC:
+            ctx->exops.get_st_gen = handle_ioc_getversion;
+            break;
+        }
+    }
     memset(&fh, 0, sizeof(struct file_handle));
     ret = name_to_handle(data->mountfd, ".", &fh, &mnt_id, 0);
     if (ret && errno == EOVERFLOW) {