Support for i_generation / st_gen in 9p server
v2 cover Support for i_generation / st_gen in 9p server
This patch series provide support for i_generation / st_gen in 9p server. First patch provide support for local fs type, second patch adds support for handle based fs driver.
Harsh Prateek Bora (2):
i_generation / st_gen support for local fs type i_generation / st_gen support for handle based fs driver
fsdev/file-op-9p.h | 7 +++++++ hw/9pfs/cofile.c | 22 ++++++++++++++++++++++ hw/9pfs/virtio-9p-coth.h | 2 ++ hw/9pfs/virtio-9p-device.c | 1 + hw/9pfs/virtio-9p-handle.c | 30 ++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-local.c | 32 +++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p.c | 9 +++++++++ 7 files changed, 102 insertions(+), 1 deletions(-)
PATCH v2 1/2 i_generation / st_gen support for local fs type
v2:
- close fd after use in local_ioc_getversion
Signed-off-by Harsh Prateek Bora <[email protected]>
--- fsdev/file-op-9p.h | 7 +++++++ hw/9pfs/cofile.c | 22 ++++++++++++++++++++++ hw/9pfs/virtio-9p-coth.h | 2 ++ hw/9pfs/virtio-9p-device.c | 1 + hw/9pfs/virtio-9p-local.c | 33 ++++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p.c | 9 +++++++++ 6 files changed, 73 insertions(+), 1 deletions(-)
fsdev/file-op-9p.h +7 -0
@@ -49,6 +49,12 @@ typedef struct FsCred } FsCred;struct xattr_operations ; +struct FsContext ; +struct V9fsPath ; + +typedef struct extended_ops { +int (*get_st_gen)(struct FsContext *,struct V9fsPath *,uint64_t *); +}extended_ops ;/* FsContext flag values */ #define PATHNAME_FSCONTEXT 0x1
@@ -62,6 +68,7 @@ typedef struct FsContextint open_flags;int cache_model;struct xattr_operations **xops; +struct extended_ops exops;/* fs driver specific data */ void *private; } FsContext;
hw/9pfs/cofile.c +22 -0
@@ -17,6 +17,28 @@#include "qemu-coroutine.h" #include "virtio-9p-coth.h" +int v9fs_co_st_gen (V9fsPDU *pdu,V9fsPath *path,V9fsStatDotl *v9stat) +{ +int err; +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, &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;
hw/9pfs/virtio-9p-coth.h +2 -0
@@ -101,4 +101,6 @@ 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,V9fsStatDotl *v9stat); +#endif
hw/9pfs/virtio-9p-device.c +1 -0
@@ -122,6 +122,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) } s->ctx.cache_model = fse->cache_model; s->ctx.fs_root =qemu_strdup (fse->path); + s->ctx.exops.get_st_gen =NULL ; len =strlen (conf->tag);if (len >MAX_TAG_LEN ) { len =MAX_TAG_LEN ;
hw/9pfs/virtio-9p-local.c +32 -1
@@ -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> static int local_lstat (FsContext *fs_ctx,V9fsPath *fs_path,struct stat *stbuf) {
@@ -645,10 +648,38 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,return ret; } +static int local_ioc_getversion (FsContext *ctx,V9fsPath *path,uint64_t *st_gen) +{ +int mode =0600 ; +int fd, err; + + fd =local_open (ctx, path, mode); +if (fd <0 ) { +return fd; + } + err =ioctl (fd,FS_IOC_GETVERSION , st_gen); +local_close (ctx, fd); +return err; +} +/* XFS_SUPER_MAGIC not available in linux/fs.h */ +#define XFS_SUPER_MAGIC 0x58465342static 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 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 = local_ioc_getversion; +break ; + } + } +return err; }FileOperations local_ops = {
hw/9pfs/virtio-9p.c +9 -0
@@ -1357,6 +1357,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, &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:
Signature · 1 line
1.7.1.1
PATCH v2 2/2 i_generation / st_gen support for handle based fs driver
In reply to Harsh Prateek Borav2:
- close fd after use in handle_ioc_getversion
Signed-off-by Harsh Prateek Bora <[email protected]>
--- hw/9pfs/virtio-9p-handle.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-)
hw/9pfs/virtio-9p-handle.c +31 -0
@@ -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 0x58465342static 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 ) {
Signature · 1 line
1.7.1.1