famfs: FUSE_FAMFS_EXT_INTERLEAVE -> FUSE_DEV_IOC_STRIPE_OPEN
Subsystems (3)
PATCH 1/1 famfs: FUSE_FAMFS_EXT_INTERLEAVE -> FUSE_DEV_IOC_STRIPE_OPEN
Add striped "virtual" backing devices (idea from Darrick).
This decouples interleaving from extents, since the interleaving is configured on the striped backing device, while simple extents select which striped device is to be used and the length/offset within that virtual device.
---
This is the second part of what we were talking about: using the backing API for striping.
It's on top of the famfs-v10 patchset + the FUSE_BACKING_DAXDEV patch
Totally Untested (TM).
The third part will be to use the fuse-iomap uAPI (and just the API, not any of the code) from Darrick to describe the simple extents themselves.
And that should be it. Just some review and testing and I'll be happy to move this into fuse-next.
Thanks,
Miklos
fs/fuse/backing.c | 108 +++++++++----- fs/fuse/dev.c | 38 +++++ fs/fuse/famfs.c | 296 +++++++++----------------------------- fs/fuse/famfs_kfmap.h | 25 +--- fs/fuse/fuse_i.h | 23 ++- include/uapi/linux/fuse.h | 29 ++-- 6 files changed, 219 insertions(+), 300 deletions(-)
fs/fuse/backing.c +71 -37
@@ -37,14 +37,14 @@ void fuse_backing_files_init(struct fuse_conn *fc)idr_init (&fc->backing_files_map); } -int fuse_backing_id_alloc (struct fuse_conn *fc,void *obj) +int fuse_backing_id_alloc (struct fuse_conn *fc,struct fuse_backing_common *backing) {int id;idr_preload (GFP_KERNEL );spin_lock (&fc->lock);/* FIXME: xarray might be space inefficient */ - id =idr_alloc_cyclic (&fc->backing_files_map, obj,1 ,0 ,GFP_ATOMIC ); + id =idr_alloc_cyclic (&fc->backing_files_map, backing,1 ,0 ,GFP_ATOMIC );spin_unlock (&fc->lock);idr_preload_end ();
@@ -52,33 +52,43 @@ int fuse_backing_id_alloc(struct fuse_conn *fc, void *obj)return id; } -static struct fuse_backing *fuse_backing_id_remove (struct fuse_conn *fc, -int id) +static void fuse_backing_file_free (struct fuse_backing_common *backing) { -struct fuse_backing *fb; +struct fuse_backing *fb =container_of (backing,typeof (*fb), backing); -spin_lock (&fc->lock); - fb =idr_remove (&fc->backing_files_map, id); -spin_unlock (&fc->lock); +WARN_ON_ONCE (refcount_read (&fb->count) !=1 ); +fuse_backing_free (fb); +} -return fb; +static void fuse_stripe_free (struct fuse_backing_common *backing) +{ +struct fuse_backing_stripe *bstripe =container_of (backing,typeof (*bstripe), backing); + +kfree (bstripe->stripe); +kfree (bstripe); }static int fuse_backing_id_free (int id,void *p,void *data) { -struct fuse_backing *fb = p; - -WARN_ON_ONCE (refcount_read (&fb->count) !=1 ); -fuse_backing_free (fb); +struct fuse_backing_common *backing = p; + +switch (backing->type) { +case FUSE_BCK_FILE : +fuse_backing_file_free (backing); +break ; +case FUSE_BCK_DAXDEV : +famfs_devidx_free (backing); +break ; +case FUSE_BCK_STRIPE : +fuse_stripe_free (backing); +break ; + }return 0 ; }void fuse_backing_files_free (struct fuse_conn *fc) { -if (fc->famfs_iomap) -famfs_teardown (fc); -else -idr_for_each (&fc->backing_files_map, fuse_backing_id_free,NULL ); +idr_for_each (&fc->backing_files_map, fuse_backing_id_free,NULL );idr_destroy (&fc->backing_files_map); }
@@ -130,11 +140,12 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)if (!fb) goto out_fput; + fb->backing.type =FUSE_BCK_FILE ; fb->file = file; fb->cred =prepare_creds ();refcount_set (&fb->count,1 ); - res =fuse_backing_id_alloc (fc, fb); + res =fuse_backing_id_alloc (fc, &fb->backing);if (res <0 ) {fuse_backing_free (fb); fb =NULL ;
@@ -150,30 +161,54 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) goto out; } +int fuse_stripe_open (struct fuse_conn *fc,struct fuse_stripe *stripe) +{ +int res; + struct fuse_backing_stripe *bstripe __free(kfree) = kmalloc_obj(*bstripe); + +if (!bstripe) +return -ENOMEM ; + + bstripe->backing.type =FUSE_BCK_STRIPE ; + bstripe->stripe = stripe; + + res =fuse_backing_id_alloc (fc, &bstripe->backing); +if (res >=0 ) +retain_and_null_ptr (bstripe); + +return res; +} +int fuse_backing_close (struct fuse_conn *fc,int backing_id) { +struct fuse_backing_common *backing;struct fuse_backing *fb =NULL ;int err;pr_debug ("%s: backing_id=%d\n" , __func__, backing_id); -/* No close for dax device (yet) */ -if (fc->famfs_iomap) -return -EINVAL ; - -/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */ - err = -EPERM ; -if (!fc->passthrough || !capable (CAP_SYS_ADMIN )) - goto out; - err = -EINVAL ;if (backing_id <=0 ) goto out; - err = -ENOENT ; - fb =fuse_backing_id_remove (fc, backing_id); -if (!fb) - goto out; + scoped_guard(spinlock, &fc->lock) { + err = -ENOENT ; + backing =idr_find (&fc->backing_files_map, backing_id); +if (!backing) + goto out; + err = -EINVAL ; +if (backing->type !=FUSE_BCK_FILE ) + goto out; + + fb =container_of (backing,typeof (*fb), backing); + +/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */ + err = -EPERM ; +if (!fc->passthrough || !capable (CAP_SYS_ADMIN )) + goto out; + +WARN_ON (idr_remove (&fc->backing_files_map, backing_id) != backing); + }fuse_backing_put (fb); err =0 ;
@@ -185,14 +220,13 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)struct fuse_backing *fuse_backing_lookup (struct fuse_conn *fc,int backing_id) { -struct fuse_backing *fb; - -if (fc->famfs_iomap) -return NULL ; +struct fuse_backing_common *backing; +struct fuse_backing *fb =NULL ;rcu_read_lock (); - fb =idr_find (&fc->backing_files_map, backing_id); - fb =fuse_backing_get (fb); + backing =idr_find (&fc->backing_files_map, backing_id); +if (backing && backing->type ==FUSE_BCK_FILE ) + fb =fuse_backing_get (container_of (backing,typeof (*fb), backing));rcu_read_unlock ();return fb;
fs/fuse/dev.c +38 -0
@@ -2636,6 +2636,41 @@ static long fuse_dev_ioctl_backing_open(struct file *file,return fuse_backing_open (fud->fc, &map); } + +static long fuse_dev_ioctl_stripe_open (struct file *file,struct fuse_stripe __user *argp) +{ +struct fuse_dev *fud =fuse_get_dev (file); +struct fuse_stripe hdr; +size_t size; +int backing_id; + +if (IS_ERR (fud)) +return PTR_ERR (fud); + +if (!IS_ENABLED (CONFIG_FUSE_FAMFS_DAX )) +return -EOPNOTSUPP ; + +if (copy_from_user (&hdr, argp,sizeof (hdr))) +return -EFAULT ; + +if (hdr.nr_strips >FUSE_STRIPS_MAX ) +return -EINVAL ; + + size = offsetof(struct fuse_stripe, strips[hdr.nr_strips]); + struct fuse_stripe *stripe __free(kfree) = kmalloc(size, GFP_KERNEL_ACCOUNT); +if (!stripe) +return -ENOMEM ; + +if (copy_from_user (stripe, argp, size)) +return -EFAULT ; + + backing_id =fuse_stripe_open (fud->fc, stripe); +if (backing_id >=0 ) +retain_and_null_ptr (stripe); + +return backing_id; +} +static long fuse_dev_ioctl_backing_close (struct file *file,__u32 __user *argp) {struct fuse_dev *fud =fuse_get_dev (file);
@@ -2678,6 +2713,9 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,case FUSE_DEV_IOC_BACKING_OPEN :return fuse_dev_ioctl_backing_open (file, argp); +case FUSE_DEV_IOC_STRIPE_OPEN : +return fuse_dev_ioctl_stripe_open (file, argp); +case FUSE_DEV_IOC_BACKING_CLOSE :return fuse_dev_ioctl_backing_close (file, argp);
fs/fuse/famfs.c +66 -230
418 lines not on this page · raw message
fs/fuse/famfs_kfmap.h +6 -19
@@ -7,6 +7,8 @@#ifndef FAMFS_KFMAP_H #define FAMFS_KFMAP_H +#include "fuse_i.h" +/* KABI version 43 (aka v2) fmap structures * * The location of the memory backing for a famfs file is described by
@@ -96,13 +98,6 @@ enum famfs_file_type { FAMFS_LOG, }; -/* We anticipate the possibility of supporting additional types of extents */ -enum famfs_extent_type { -SIMPLE_DAX_EXTENT , -INTERLEAVED_EXTENT , -INVALID_EXTENT_TYPE , -}; -struct famfs_meta_simple_ext {u64 dev_index;u64 ext_offset;
@@ -122,18 +117,9 @@ struct famfs_meta_interleaved_ext {struct famfs_file_meta {bool error;enum famfs_file_type file_type; -size_t file_size; -enum famfs_extent_type fm_extent_type; -union { -struct { -size_t fm_nextents; -struct famfs_meta_simple_ext *se; - }; -struct { -size_t fm_niext; -struct famfs_meta_interleaved_ext *ie; - }; - }; +size_t file_size; +size_t fm_nextents; +struct famfs_meta_simple_ext *se; };/*
@@ -143,6 +129,7 @@ struct famfs_file_meta {* the responses to GET_FMAP messages */ struct famfs_daxdev { +struct fuse_backing_common backing;/* Include dev uuid? */ bool error;/* Dax has reported a memory error (probably poison) */ bool dax_err;/* fs_dax_get() failed */
fs/fuse/fuse_i.h +20 -3
@@ -103,8 +103,19 @@ struct fuse_submount_lookup {struct fuse_forget_link *forget; }; +enum fuse_backing_type { +FUSE_BCK_FILE , +FUSE_BCK_DAXDEV , +FUSE_BCK_STRIPE , +}; + +struct fuse_backing_common { +enum fuse_backing_type type; +}; +/** Container for data related to mapping to backing file */ struct fuse_backing { +struct fuse_backing_common backing;struct file *file;struct cred *cred;
@@ -113,6 +124,11 @@ struct fuse_backing {struct rcu_head rcu; }; +struct fuse_backing_stripe { +struct fuse_backing_common backing; +struct fuse_stripe *stripe; +}; +/** FUSE inode */ struct fuse_inode {/** Inode data */
@@ -1567,7 +1583,7 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,struct fuse_backing *fuse_backing_get (struct fuse_backing *fb);void fuse_backing_put (struct fuse_backing *fb);struct fuse_backing *fuse_backing_lookup (struct fuse_conn *fc,int backing_id); -int fuse_backing_id_alloc (struct fuse_conn *fc,void *obj); +int fuse_backing_id_alloc (struct fuse_conn *fc,struct fuse_backing_common *backing);#else static inline struct fuse_backing *fuse_backing_get (struct fuse_backing *fb)
@@ -1588,6 +1604,7 @@ static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,void fuse_backing_files_init (struct fuse_conn *fc);void fuse_backing_files_free (struct fuse_conn *fc);int fuse_backing_open (struct fuse_conn *fc,struct fuse_backing_map *map); +int fuse_stripe_open (struct fuse_conn *fc,struct fuse_stripe *stripe);int fuse_backing_close (struct fuse_conn *fc,int backing_id);/* passthrough.c */
@@ -1649,7 +1666,7 @@ int famfs_fuse_mmap(struct file *file, struct vm_area_struct *vma);void __famfs_meta_free (void *map);int famfs_daxdev_open (struct fuse_conn *fc,struct fuse_backing_map *map); -void famfs_teardown (struct fuse_conn *fc); +void famfs_devidx_free (struct fuse_backing_common *backing);/* Set fi->famfs_meta iff the current value is NULL */ static inline struct fuse_backing *famfs_meta_set(struct fuse_inode *fi,
@@ -1675,7 +1692,7 @@ int fuse_get_fmap(struct fuse_mount *fm, struct inode *inode);#else /* !CONFIG_FUSE_FAMFS_DAX */ -static inline void famfs_teardown (struct fuse_conn *fc) +static inline void famfs_devidx_free (struct fuse_backing_common *backing) { } static inline ssize_t famfs_fuse_write_iter(struct kiocb *iocb,
include/uapi/linux/fuse.h +18 -11
@@ -245,7 +245,6 @@* - Add FUSE_DAX_FMAP capability - ability to handle in-kernel fsdax maps * - Add the following structures for the GET_FMAP message reply components: * - struct fuse_famfs_simple_ext -* - struct fuse_famfs_iext * - struct fuse_famfs_fmap_header * - Add the following structs for the GET_DAXDEV message and reply * - struct fuse_get_daxdev_out
@@ -1153,6 +1152,23 @@ struct fuse_backing_map {uint64_t padding; }; +struct fuse_strip { +uint32_t backing_id; +uint32_t reserved; +uint64_t offset; +}; + +#define FUSE_STRIPS_MAX (256) + +struct fuse_stripe { +uint16_t nr_strips; +uint16_t reserved1; +uint32_t reserved2; +uint64_t chunk_size; + + struct fuse_strip strips[] __counted_by(nr_strips); +}; +/* Device ioctls: */ #define FUSE_DEV_IOC_MAGIC 229#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1160,6 +1176,7 @@ struct fuse_backing_map { struct fuse_backing_map)#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)#define FUSE_DEV_IOC_SYNC_INIT _IO(FUSE_DEV_IOC_MAGIC, 3) +#define FUSE_DEV_IOC_STRIPE_OPEN _IOW(FUSE_DEV_IOC_MAGIC, 4, struct fuse_stripe)struct fuse_lseek_in {uint64_t fh;
@@ -1345,7 +1362,6 @@ enum fuse_famfs_file_type {enum famfs_ext_type {FUSE_FAMFS_EXT_SIMPLE =0 , -FUSE_FAMFS_EXT_INTERLEAVE =1 , };struct fuse_famfs_simple_ext {
@@ -1355,15 +1371,6 @@ struct fuse_famfs_simple_ext {uint64_t se_len; }; -struct fuse_famfs_iext {/* Interleaved extent */ -uint32_t ie_nstrips; -uint32_t ie_chunk_size; -uint64_t ie_nbytes;/* Total bytes for this interleaved_ext; -* sum of strips may be more -*/ -uint64_t reserved; -}; -struct fuse_famfs_fmap_header {uint8_t file_type;/* enum famfs_file_type */ uint8_t reserved;
Signature · 1 line
2.54.0
Amir Goldstein
maintainerQuoted 16 lines · Miklos Szeredi
Add striped "virtual" backing devices (idea from Darrick).
This decouples interleaving from extents, since the interleaving is configured on the striped backing device, while simple extents select which striped device is to be used and the length/offset within that virtual device.
Signed-off-by Miklos Szeredi <[email protected]>---
This is the second part of what we were talking about: using the backing API for striping.
It's on top of the famfs-v10 patchset + the
FUSE_BACKING_DAXDEVpatch
Quoted 7 lines
Totally Untested (TM).
The third part will be to use the fuse-iomap uAPI (and just the API, not any of the code) from Darrick to describe the simple extents themselves.
And that should be it. Just some review and testing and I'll be happy to move this into fuse-next.
Yey :)
This looks very nice!
I hope it meets John's technical requirements.
Quoted 20 lines
Thanks,
Miklosfs/fuse/backing.c | 108 +++++++++----- fs/fuse/dev.c | 38 +++++ fs/fuse/famfs.c | 296 +++++++++----------------------------- fs/fuse/famfs_kfmap.h | 25 +--- fs/fuse/fuse_i.h | 23 ++- include/uapi/linux/fuse.h | 29 ++-- 6 files changed, 219 insertions(+), 300 deletions(-)fs/fuse/backing.c +0
-0@@ -37,14 +37,14 @@ void fuse_backing_files_init(struct fuse_conn *fc)idr_init (&fc->backing_files_map); }
fs/fuse/backing.c void fuse_backing_files_init(struct fuse_conn *fc) · line 47
Quoted 10 lines
fs/fuse/backing.c +2
-2-int fuse_backing_id_alloc (struct fuse_conn *fc,void *obj) +int fuse_backing_id_alloc (struct fuse_conn *fc,struct fuse_backing_common *backing) {int id;idr_preload (GFP_KERNEL );spin_lock (&fc->lock);/* FIXME: xarray might be space inefficient */ - id =idr_alloc_cyclic (&fc->backing_files_map, obj,1 ,0 ,GFP_ATOMIC ); + id =idr_alloc_cyclic (&fc->backing_files_map, backing,1 ,0 ,GFP_ATOMIC );
Darrick's iomap patches have the range determined by the backing ops.
Considering that John wants the daxdev ids to be allocated by userspace I suppose the number of daxdev ids is limited, same as with iomap backing devs, so we could probably start allocating backing stripes from max_daxdevs (1000?), to be negotiated at init time.
Quoted 83 lines
fs/fuse/backing.c +30
-16spin_unlock (&fc->lock);idr_preload_end ();@@ -52,33 +52,43 @@ int fuse_backing_id_alloc(struct fuse_conn *fc, void *obj)return id; } -static struct fuse_backing *fuse_backing_id_remove (struct fuse_conn *fc, -int id) +static void fuse_backing_file_free (struct fuse_backing_common *backing) { -struct fuse_backing *fb; +struct fuse_backing *fb =container_of (backing,typeof (*fb), backing); -spin_lock (&fc->lock); - fb =idr_remove (&fc->backing_files_map, id); -spin_unlock (&fc->lock); +WARN_ON_ONCE (refcount_read (&fb->count) !=1 ); +fuse_backing_free (fb); +} -return fb; +static void fuse_stripe_free (struct fuse_backing_common *backing) +{ +struct fuse_backing_stripe *bstripe =container_of (backing,typeof (*bstripe), backing); + +kfree (bstripe->stripe); +kfree (bstripe); }static int fuse_backing_id_free (int id,void *p,void *data) { -struct fuse_backing *fb = p; - -WARN_ON_ONCE (refcount_read (&fb->count) !=1 ); -fuse_backing_free (fb); +struct fuse_backing_common *backing = p; + +switch (backing->type) { +case FUSE_BCK_FILE : +fuse_backing_file_free (backing); +break ; +case FUSE_BCK_DAXDEV : +famfs_devidx_free (backing); +break ; +case FUSE_BCK_STRIPE : +fuse_stripe_free (backing); +break ; + }return 0 ; }void fuse_backing_files_free (struct fuse_conn *fc) { -if (fc->famfs_iomap) -famfs_teardown (fc); -else -idr_for_each (&fc->backing_files_map, fuse_backing_id_free,NULL ); +idr_for_each (&fc->backing_files_map, fuse_backing_id_free,NULL );idr_destroy (&fc->backing_files_map); }@@ -130,11 +140,12 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)if (!fb) goto out_fput; + fb->backing.type =FUSE_BCK_FILE ; fb->file = file; fb->cred =prepare_creds ();refcount_set (&fb->count,1 ); - res =fuse_backing_id_alloc (fc, fb); + res =fuse_backing_id_alloc (fc, &fb->backing);if (res <0 ) {fuse_backing_free (fb); fb =NULL ;@@ -150,30 +161,54 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) goto out; } +int fuse_stripe_open (struct fuse_conn *fc,struct fuse_stripe *stripe) +{ +int res;
fs/fuse/backing.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 176
Quoted 10 lines
fs/fuse/backing.c +10
-0+ struct fuse_backing_stripe *bstripe __free(kfree) = kmalloc_obj(*bstripe); + +if (!bstripe) +return -ENOMEM ; + + bstripe->backing.type =FUSE_BCK_STRIPE ; + bstripe->stripe = stripe; + + res =fuse_backing_id_alloc (fc, &bstripe->backing); +if (res >=0 )
0 is reserved, it cannot be allocated
(for daxdev userspace should be able to assign id 0 if needed)
Quoted 99 lines
fs/fuse/backing.c +29
-19+retain_and_null_ptr (bstripe); + +return res; +} +int fuse_backing_close (struct fuse_conn *fc,int backing_id) { +struct fuse_backing_common *backing;struct fuse_backing *fb =NULL ;int err;pr_debug ("%s: backing_id=%d\n" , __func__, backing_id); -/* No close for dax device (yet) */ -if (fc->famfs_iomap) -return -EINVAL ; - -/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */ - err = -EPERM ; -if (!fc->passthrough || !capable (CAP_SYS_ADMIN )) - goto out; - err = -EINVAL ;if (backing_id <=0 ) goto out; - err = -ENOENT ; - fb =fuse_backing_id_remove (fc, backing_id); -if (!fb) - goto out; + scoped_guard(spinlock, &fc->lock) { + err = -ENOENT ; + backing =idr_find (&fc->backing_files_map, backing_id); +if (!backing) + goto out; + err = -EINVAL ; +if (backing->type !=FUSE_BCK_FILE ) + goto out; + + fb =container_of (backing,typeof (*fb), backing); + +/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */ + err = -EPERM ; +if (!fc->passthrough || !capable (CAP_SYS_ADMIN )) + goto out; + +WARN_ON (idr_remove (&fc->backing_files_map, backing_id) != backing); + }fuse_backing_put (fb); err =0 ;@@ -185,14 +220,13 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)struct fuse_backing *fuse_backing_lookup (struct fuse_conn *fc,int backing_id) { -struct fuse_backing *fb; - -if (fc->famfs_iomap) -return NULL ; +struct fuse_backing_common *backing; +struct fuse_backing *fb =NULL ;rcu_read_lock (); - fb =idr_find (&fc->backing_files_map, backing_id); - fb =fuse_backing_get (fb); + backing =idr_find (&fc->backing_files_map, backing_id); +if (backing && backing->type ==FUSE_BCK_FILE ) + fb =fuse_backing_get (container_of (backing,typeof (*fb), backing));rcu_read_unlock ();return fb;fs/fuse/dev.c +20
-0@@ -2636,6 +2636,41 @@ static long fuse_dev_ioctl_backing_open(struct file *file,return fuse_backing_open (fud->fc, &map); } + +static long fuse_dev_ioctl_stripe_open (struct file *file,struct fuse_stripe __user *argp) +{ +struct fuse_dev *fud =fuse_get_dev (file); +struct fuse_stripe hdr; +size_t size; +int backing_id; + +if (IS_ERR (fud)) +return PTR_ERR (fud); + +if (!IS_ENABLED (CONFIG_FUSE_FAMFS_DAX )) +return -EOPNOTSUPP ; + +if (copy_from_user (&hdr, argp,sizeof (hdr))) +return -EFAULT ; + +if (hdr.nr_strips >FUSE_STRIPS_MAX ) +return -EINVAL ; +
fs/fuse/dev.c static long fuse_dev_ioctl_backing_open(struct file *file, · line 2668
Quoted 10 lines
fs/fuse/dev.c +10
-0+ size = offsetof(struct fuse_stripe, strips[hdr.nr_strips]); + struct fuse_stripe *stripe __free(kfree) = kmalloc(size, GFP_KERNEL_ACCOUNT); +if (!stripe) +return -ENOMEM ; + +if (copy_from_user (stripe, argp, size)) +return -EFAULT ; + + backing_id =fuse_stripe_open (fud->fc, stripe); +if (backing_id >=0 )
Again not sure about 0
fs/fuse/famfs.c
Quoted 22 lines
fs/fuse/dev.c +8
-0+retain_and_null_ptr (stripe); + +return backing_id; +} +static long fuse_dev_ioctl_backing_close (struct file *file,__u32 __user *argp) {struct fuse_dev *fud =fuse_get_dev (file);@@ -2678,6 +2713,9 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,case FUSE_DEV_IOC_BACKING_OPEN :return fuse_dev_ioctl_backing_open (file, argp); +case FUSE_DEV_IOC_STRIPE_OPEN : +return fuse_dev_ioctl_stripe_open (file, argp); +case FUSE_DEV_IOC_BACKING_CLOSE :return fuse_dev_ioctl_backing_close (file, argp);fs/fuse/famfs.c +0
-0
I will leave it to John to review the famfs side of things.
Thanks,
Amir.
Miklos Szeredi
maintainerQuoted 4 lines · Amir Goldstein
Considering that John wants the daxdev ids to be allocated by userspace I suppose the number of daxdev ids is limited, same as with iomap backing devs, so we could probably start allocating backing stripes from
max_daxdevs(1000?), to be negotiated at init time.
This doesn't belong in the kernel.
If we really need to have allocation policies for backing IDs, then just move it completely to userspace. I.e. pass the backing ID infuse_backing_map together with a flag (FUSE_BACKING_ID_SET). It
would make the open/close more symmetric, and is a nice flexible interface, so we should have done that from the beginning. But I guess we opted for the kernel allocation scheme due to its similarity
with file descriptors. Oh well.
Quoted 4 lines
fs/fuse/backing.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 176
Quoted 2 lines
fs/fuse/backing.c +2
-0+ res =fuse_backing_id_alloc (fc, &bstripe->backing); +if (res >=0 )0 is reserved, it cannot be allocated
It is confusing either way. The (res >= 0) is expressing the fact that this is not an error value. If the condition becomes (res > 0) then the zero value becomes an error condition, which is crazy.
Thanks,
Miklos
Amir Goldstein
maintainerQuoted 10 lines · Miklos Szeredi
Quoted 4 lines · Amir Goldstein
Considering that John wants the daxdev ids to be allocated by userspace I suppose the number of daxdev ids is limited, same as with iomap backing devs, so we could probably start allocating backing stripes from
max_daxdevs(1000?), to be negotiated at init time.This doesn't belong in the kernel.
Quoted 7 lines
If we really need to have allocation policies for backing IDs, then just move it completely to userspace. I.e. pass the backing ID in
fuse_backing_maptogether with a flag (FUSE_BACKING_ID_SET). It
would make the open/close more symmetric, and is a nice flexible interface, so we should have done that from the beginning. But I guess we opted for the kernel allocation scheme due to its similarity
with file descriptors. Oh well.
fds also have both dup() and dup2() ;)
Yeh it's no big deal.
Auto id allocate is a convenient feature, which has cost us nothing to implement.FUSE_BACKING_ID_SET would be just as easy and would not add that much complication, just do idr_alloc with range of 1.
We could already reserve the code point for user assigned id for famfs or if we want to use this in the future and shrink the ops_mask from FUSE_PASSTHROUGH_INO patches to 32bit
as Joanne had already suggested:
struct fuse_backing_map {
int32_t fd;
uint32_t flags;
int32_t id;
uint32_t ops_mask;
};Quoted 9 lines
Quoted 5 lines
fs/fuse/backing.c int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map) · line 176
Quoted 3 lines
fs/fuse/backing.c +2
-0+ res =fuse_backing_id_alloc (fc, &bstripe->backing); +if (res >=0 )0 is reserved, it cannot be allocated
It is confusing either way. The (res >= 0) is expressing the fact that this is not an error value. If the condition becomes (res > 0) then the zero value becomes an error condition, which is crazy.
OK. make sense.
Thanks,
Amir.
Miklos Szeredi
maintainerQuoted 6 lines · Amir Goldstein
struct fuse_backing_map {
int32_t fd;
uint32_t flags;
int32_t id;
uint32_t ops_mask;
};Or make backing ID 64 bit (same as node ID, can cast from/to pointer) and ops_mask be part of flags?
Thanks,
Miklos
Amir Goldstein
maintainerQuoted 10 lines · Miklos Szeredi
Quoted 6 lines · Amir Goldstein
struct fuse_backing_map { int32_t fd; uint32_t flags; int32_t id; uint32_t ops_mask; };
Quoted 2 lines
Or make backing ID 64 bit (same as node ID, can cast from/to pointer) and
ops_maskbe part of flags?
Feels wrong to mix them. I would rather extend fuse_backing_map for ops_mask in that case.
But note that if we support 64bit ids, we could not use the idr map and fuse_open_out and FUSE_DEV_IOC_BACKING_CLOSE
would be incompatible with this id, so do we really need this widening?
I agree that it would have been useful to map a backing file directly to an inode on lookup, without having to go through a backing_id mapping, sort of a compound LOOKUP+STATX+GET_BACKING
but there is this security risk of writing an fd using write() syscall.
This risk is not relevant in io_uring AFAIK, so with io_uring we could map backing files without a temp id unless the same backing file needs to be shared among different inodes or referenced from backing stripes.
Anyway, if you think we should reserve the place for 64bit id just for extendability I have no problems with that.
Thanks,
Amir.
Miklos Szeredi
maintainerQuoted 8 lines · Amir Goldstein
Quoted 2 lines · Miklos Szeredi
Or make backing ID 64 bit (same as node ID, can cast from/to pointer) and
ops_maskbe part of flags?Feels wrong to mix them. I would rather extend
fuse_backing_mapforops_maskin that case.
Both work.
Quoted 1 line
But note that if we support 64bit ids, we could not use the idr map
Idr map wasn't the best fit anyway, since it works best for dense maps, but a 2^32 cyclic allocation could end up with a very sparse one.
A hash map would be much better.
Quoted 2 lines
and
fuse_open_outandFUSE_DEV_IOC_BACKING_CLOSE
would be incompatible with this id, so do we really need this widening?
Argh...
Quoted 9 lines
I agree that it would have been useful to map a backing file directly to an inode on lookup, without having to go through a
backing_idmapping, sort of a compound LOOKUP+STATX+GET_BACKING
but there is this security risk of writing an fd usingwrite()syscall.This risk is not relevant in
io_uringAFAIK, so withio_uringwe could map backing files without a temp id unless the same backing file needs to be shared among different inodes or referenced from backing stripes.
Yeah, we could allow using fd in place of a backing id in io_uring.
Someone was complaining about extra syscall overhead with the current scheme, so it's probably a good idea.
Quoted 2 lines
Anyway, if you think we should reserve the place for 64bit id just for extendability I have no problems with that.
I think we should bite the bullet now instead of having to modify the interface yet again sometime in the future.
Thanks,
Miklos