fuse: LOOKUP_HANDLE operation
Subsystems (2)
cover fuse: LOOKUP_HANDLE operation
Hi!
In the scope of a wider project -- that of being able to restart a FUSE server -- it has been already identified some time ago that one of the missing pieces is the FUSE_LOOKUP_HANDLE operation. For context, please see [0] and [1].
I've been playing a bit with this operation implementation, and I decided to share a very early (and not particularly neat) draft of it. Because it needs to touch several different areas, it's quite possible that I'm doing it totally wrong and some early feedback would be great to help me fixing that. Also, please note that this patchset isn't complete, there are several things still missing. For example, handling compat is missing. Also, I haven't tried to include the optimisation suggested by Amir[2], to use a trick similar to the one used by fanotify_fid_event so that the fuse inodes could inline small file handles.
I'm not sharing (yet) the user-space I've used along with this patchset, as it's probably not relevant at this stage. Also note that this is barely tested, and the nfs-related changes in particular (export_operations) are not tested _at_all_.
Anyway, I hope this RFC can be used to support the discussion I started with the thread already mentioned above [0].
(And by the way, I understand there's probably a lot of useful information in the two threads [0] and [1] that is missing in the patches descriptions.)
Cheers,
Signature · 18 lines
Luis [0] https://lore.kernel.org/all/[email protected] [1] https://lore.kernel.org/all/CAJfpegvNZ6Z7uhuTdQ6quBaTOYNkAP8W_4yUY4L2JRAEKxEwOQ@mail.gmail.com [2] https://lore.kernel.org/all/CAOQ4uxjZ0B5TwV+HiWsUpBuFuZJZ_e4Bm_QfNn4crDoVAfkA9Q@mail.gmail.com Luis Henriques (3): fuse: initial infrastructure for FUSE_LOOKUP_HANDLE support fuse: move fuse_entry_out structs out of the stack fuse: implementation of the FUSE_LOOKUP_HANDLE operation fs/fuse/dev.c | 1 + fs/fuse/dir.c | 202 ++++++++++++++++++++++++++------------ fs/fuse/fuse_i.h | 45 ++++++++- fs/fuse/inode.c | 164 +++++++++++++++++++++++++++---- fs/fuse/readdir.c | 10 +- include/uapi/linux/fuse.h | 16 ++- 6 files changed, 348 insertions(+), 90 deletions(-)
RFC PATCH 1/3 fuse: initial infrastructure for FUSE_LOOKUP_HANDLE support
This patch adds the initial infrastructure to implement the FUSE_LOOKUP_HANDLE operation. It simply defines the new operation and the extra fuse_init_out field to set the maximum handle size.
--- fs/fuse/fuse_i.h | 4 ++++ fs/fuse/inode.c | 9 ++++++++- include/uapi/linux/fuse.h | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-)
fs/fuse/fuse_i.h +4 -0
@@ -907,6 +907,10 @@ struct fuse_conn {/* Is synchronous FUSE_INIT allowed? */ unsigned int sync_init:1; +/** Is LOOKUP_HANDLE implemented by fs? */ + unsigned int lookup_handle:1; +unsigned int max_handle_sz; +/* Use io_uring for communication */ unsigned int io_uring;
fs/fuse/inode.c +8 -1
@@ -1453,6 +1453,13 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,if (flags &FUSE_REQUEST_TIMEOUT ) timeout = arg->request_timeout; + +if ((flags &FUSE_HAS_LOOKUP_HANDLE ) && + (arg->max_handle_sz >0 ) && + (arg->max_handle_sz <=FUSE_MAX_HANDLE_SZ )) { + fc->lookup_handle =1 ; + fc->max_handle_sz = arg->max_handle_sz; + } }else { ra_pages = fc->max_read /PAGE_SIZE ; fc->no_lock =1 ;
@@ -1503,7 +1510,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)FUSE_SECURITY_CTX |FUSE_CREATE_SUPP_GROUP |FUSE_HAS_EXPIRE_ONLY |FUSE_DIRECT_IO_ALLOW_MMAP |FUSE_NO_EXPORT_SUPPORT |FUSE_HAS_RESEND |FUSE_ALLOW_IDMAP | -FUSE_REQUEST_TIMEOUT ; +FUSE_REQUEST_TIMEOUT |FUSE_LOOKUP_HANDLE ;#ifdef CONFIG_FUSE_DAX if (fm->fc->dax) flags |=FUSE_MAP_ALIGNMENT ;
include/uapi/linux/fuse.h +7 -1
@@ -495,6 +495,7 @@ struct fuse_file_lock {#define FUSE_ALLOW_IDMAP (1ULL << 40)#define FUSE_OVER_IO_URING (1ULL << 41)#define FUSE_REQUEST_TIMEOUT (1ULL << 42) +#define FUSE_HAS_LOOKUP_HANDLE (1ULL << 43)/** * CUSE INIT request/reply flags
@@ -663,6 +664,7 @@ enum fuse_opcode {FUSE_TMPFILE =51 ,FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_LOOKUP_HANDLE =54 ,/* CUSE specific operations */ CUSE_INIT = 4096,
@@ -908,6 +910,9 @@ struct fuse_init_in {uint32_t unused[11 ]; }; +/* Same value as MAX_HANDLE_SZ */ +#define FUSE_MAX_HANDLE_SZ 128 +#define FUSE_COMPAT_INIT_OUT_SIZE 8#define FUSE_COMPAT_22_INIT_OUT_SIZE 24
@@ -925,7 +930,8 @@ struct fuse_init_out {uint32_t flags2;uint32_t max_stack_depth;uint16_t request_timeout; -uint16_t unused[11 ]; +uint16_t max_handle_sz; +uint16_t unused[10 ]; };#define CUSE_INIT_INFO_MAX 4096
RFC PATCH 2/3 fuse: move fuse_entry_out structs out of the stack
In reply to Luis HenriquesThis patch simply turns all struct fuse_entry_out instances that are allocated in the stack into dynamically allocated structs. This is a preparation patch for further changes, including the extra helper function used to actually allocate the memory.
Also, remove all the memset()s that are used to zero-out these structures, as kzalloc() is being used.
--- fs/fuse/dir.c | 139 ++++++++++++++++++++++++++++++----------------- fs/fuse/fuse_i.h | 9 +++ fs/fuse/inode.c | 20 +++++-- 3 files changed, 114 insertions(+), 54 deletions(-)
fs/fuse/dir.c +89 -50
@@ -172,7 +172,6 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, u64 nodeid, const struct qstr *name, struct fuse_entry_out *outarg) { - memset(outarg, 0, sizeof(struct fuse_entry_out)); args->opcode = FUSE_LOOKUP; args->nodeid = nodeid; args->in_numargs =3 ;
@@ -213,7 +212,7 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, goto invalid; else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) || (flags & (LOOKUP_EXCL | LOOKUP_REVAL | LOOKUP_RENAME_TARGET))) { -struct fuse_entry_out outarg; +struct fuse_entry_out *outarg;FUSE_ARGS (args);struct fuse_forget_link *forget;u64 attr_version;
@@ -233,20 +232,27 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,if (!forget) goto out; + outarg =fuse_entry_out_alloc (fc); +if (!outarg) { +kfree (forget); + goto out; + } + attr_version =fuse_get_attr_version (fm->fc);fuse_lookup_init (fm->fc, &args,get_node_id (dir), - name, &outarg); + name, outarg); ret =fuse_simple_request (fm, &args);/* Zero nodeid is same as -ENOENT */ -if (!ret && !outarg.nodeid) +if (!ret && !outarg->nodeid) ret = -ENOENT ;if (!ret) { fi =get_fuse_inode (inode); -if (outarg.nodeid !=get_node_id (inode) || - (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg.attr.flags &FUSE_ATTR_SUBMOUNT )) { +if (outarg->nodeid !=get_node_id (inode) || + (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg->attr.flags &FUSE_ATTR_SUBMOUNT )) {fuse_queue_forget (fm->fc, forget, - outarg.nodeid,1 ); + outarg->nodeid,1 ); +kfree (outarg); goto invalid; }spin_lock (&fi->lock);
@@ -254,17 +260,22 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,spin_unlock (&fi->lock); }kfree (forget); -if (ret == -ENOMEM || ret == -EINTR ) +if (ret == -ENOMEM || ret == -EINTR ) { +kfree (outarg); goto out; -if (ret ||fuse_invalid_attr (&outarg.attr) || -fuse_stale_inode (inode, outarg.generation, &outarg.attr)) + } +if (ret ||fuse_invalid_attr (&outarg->attr) || +fuse_stale_inode (inode, outarg->generation, &outarg->attr)) { +kfree (outarg); goto invalid; + }forget_all_cached_acls (inode); -fuse_change_attributes (inode, &outarg.attr,NULL , -ATTR_TIMEOUT (&outarg), +fuse_change_attributes (inode, &outarg->attr,NULL , +ATTR_TIMEOUT (outarg), attr_version); -fuse_change_entry_timeout (entry, &outarg); +fuse_change_entry_timeout (entry, outarg); +kfree (outarg); }else if (inode) { fi =get_fuse_inode (inode);if (flags &LOOKUP_RCU ) {
@@ -410,7 +421,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *namestatic struct dentry *fuse_lookup (struct inode *dir,struct dentry *entry,unsigned int flags) { -struct fuse_entry_out outarg; +struct fuse_entry_out *outarg;struct fuse_conn *fc;struct inode *inode;struct dentry *newent;
@@ -424,9 +435,13 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, fc =get_fuse_conn_super (dir->i_sb); epoch =atomic_read (&fc->epoch); + outarg =fuse_entry_out_alloc (fc); +if (!outarg) +return ERR_PTR (-ENOMEM ); + locked =fuse_lock_inode (dir); err =fuse_lookup_name (dir->i_sb,get_node_id (dir), &entry->d_name, - &outarg, &inode); + outarg, &inode);fuse_unlock_inode (dir, locked);if (err == -ENOENT ) { outarg_valid = false;
@@ -447,17 +462,21 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, entry = newent ? newent : entry; entry->d_time = epoch;if (outarg_valid) -fuse_change_entry_timeout (entry, &outarg); +fuse_change_entry_timeout (entry, outarg);else fuse_invalidate_entry_cache (entry);if (inode)fuse_advise_use_readdirplus (dir); + +kfree (outarg); +return newent; - out_iput: +out_iput:iput (inode); - out_err: +out_err: +kfree (outarg);return ERR_PTR (err); }
@@ -625,7 +644,7 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,struct fuse_forget_link *forget;struct fuse_create_in inarg;struct fuse_open_out *outopenp; -struct fuse_entry_out outentry; +struct fuse_entry_out *outentry;struct fuse_inode *fi;struct fuse_file *ff;int epoch, err;
@@ -640,17 +659,19 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,if (!forget) goto out_err; - err = -ENOMEM ; ff =fuse_file_alloc (fm, true);if (!ff) goto out_put_forget_req; + outentry =fuse_entry_out_alloc (fm->fc); +if (!outentry) + goto out_free_ff; +if (!fm->fc->dont_mask) mode &= ~current_umask (); flags &= ~O_NOCTTY ;memset (&inarg,0 ,sizeof (inarg)); -memset (&outentry,0 ,sizeof (outentry)); inarg.flags = flags; inarg.mode = mode; inarg.umask =current_umask ();
@@ -668,8 +689,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, args.in_args[1 ].size = entry->d_name.len +1 ; args.in_args[1 ].value = entry->d_name.name; args.out_numargs =2 ; - args.out_args[0 ].size =sizeof (outentry); - args.out_args[0 ].value = &outentry; + args.out_args[0 ].size =sizeof (*outentry); + args.out_args[0 ].value = outentry;/* Store outarg for fuse_finish_open() */ outopenp = &ff->args->open_outarg; args.out_args[1 ].size =sizeof (*outopenp);
@@ -677,34 +698,35 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, err =get_create_ext (idmap, &args, dir, entry, mode);if (err) - goto out_free_ff; + goto out_free_outentry; err =fuse_simple_idmap_request (idmap, fm, &args);free_ext_value (&args);if (err) - goto out_free_ff; + goto out_free_outentry; err = -EIO ; -if (!S_ISREG (outentry.attr.mode) ||invalid_nodeid (outentry.nodeid) || -fuse_invalid_attr (&outentry.attr)) - goto out_free_ff; +if (!S_ISREG (outentry->attr.mode) ||invalid_nodeid (outentry->nodeid) || +fuse_invalid_attr (&outentry->attr)) + goto out_free_outentry; ff->fh = outopenp->fh; - ff->nodeid = outentry.nodeid; + ff->nodeid = outentry->nodeid; ff->open_flags = outopenp->open_flags; - inode =fuse_iget (dir->i_sb, outentry.nodeid, outentry.generation, - &outentry.attr,ATTR_TIMEOUT (&outentry),0 ,0 ); + inode =fuse_iget (dir->i_sb, outentry->nodeid, outentry->generation, + &outentry->attr,ATTR_TIMEOUT (outentry),0 ,0 );if (!inode) { flags &= ~(O_CREAT |O_EXCL |O_TRUNC );fuse_sync_release (NULL , ff, flags); -fuse_queue_forget (fm->fc, forget, outentry.nodeid,1 ); +fuse_queue_forget (fm->fc, forget, outentry->nodeid,1 ); err = -ENOMEM ; +kfree (outentry); goto out_err; }kfree (forget);d_instantiate (entry, inode); entry->d_time = epoch; -fuse_change_entry_timeout (entry, &outentry); +fuse_change_entry_timeout (entry, outentry);fuse_dir_changed (dir); err =generic_file_open (inode, file);if (!err) {
@@ -720,8 +742,13 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,else if (!(ff->open_flags &FOPEN_KEEP_CACHE ))invalidate_inode_pages2 (inode->i_mapping); } + +kfree (outentry); +return err; +out_free_outentry: +kfree (outentry); out_free_ff:fuse_file_free (ff); out_put_forget_req:
@@ -780,7 +807,7 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun struct fuse_args *args, struct inode *dir, struct dentry *entry, umode_t mode) { - struct fuse_entry_out outarg; + struct fuse_entry_out *outarg;struct inode *inode;struct dentry *d;struct fuse_forget_link *forget;
@@ -795,54 +822,66 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_mounif (!forget)return ERR_PTR (-ENOMEM ); -memset (&outarg,0 ,sizeof (outarg)); + outarg =fuse_entry_out_alloc (fm->fc); +if (!outarg) { + err = -ENOMEM ; + goto out_put_forget_req; + } + args->nodeid =get_node_id (dir); args->out_numargs =1 ; - args->out_args[0 ].size =sizeof (outarg); - args->out_args[0 ].value = &outarg; + args->out_args[0 ].size =sizeof (*outarg); + args->out_args[0 ].value = outarg;if (args->opcode !=FUSE_LINK ) { err =get_create_ext (idmap, args, dir, entry, mode);if (err) - goto out_put_forget_req; + goto out_free_outarg; } err =fuse_simple_idmap_request (idmap, fm, args);free_ext_value (args);if (err) - goto out_put_forget_req; + goto out_free_outarg; err = -EIO ; -if (invalid_nodeid (outarg.nodeid) ||fuse_invalid_attr (&outarg.attr)) - goto out_put_forget_req; +if (invalid_nodeid (outarg->nodeid) ||fuse_invalid_attr (&outarg->attr)) + goto out_free_outarg; -if ((outarg.attr.mode ^ mode) &S_IFMT ) - goto out_put_forget_req; +if ((outarg->attr.mode ^ mode) &S_IFMT ) + goto out_free_outarg; - inode =fuse_iget (dir->i_sb, outarg.nodeid, outarg.generation, - &outarg.attr,ATTR_TIMEOUT (&outarg),0 ,0 ); + inode =fuse_iget (dir->i_sb, outarg->nodeid, outarg->generation, + &outarg->attr,ATTR_TIMEOUT (outarg),0 ,0 );if (!inode) { -fuse_queue_forget (fm->fc, forget, outarg.nodeid,1 ); +fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 ); +kfree (outarg);return ERR_PTR (-ENOMEM ); }kfree (forget);d_drop (entry); d =d_splice_alias (inode, entry); -if (IS_ERR (d)) +if (IS_ERR (d)) { +kfree (outarg);return d; + }if (d) { d->d_time = epoch; -fuse_change_entry_timeout (d, &outarg); +fuse_change_entry_timeout (d, outarg); }else { entry->d_time = epoch; -fuse_change_entry_timeout (entry, &outarg); +fuse_change_entry_timeout (entry, outarg); }fuse_dir_changed (dir); +kfree (outarg); +return d; - out_put_forget_req: +out_free_outarg: +kfree (outarg); +out_put_forget_req:if (err == -EEXIST )fuse_invalidate_entry (entry);kfree (forget);
fs/fuse/fuse_i.h +9 -0
@@ -1092,6 +1092,15 @@ static inline bool fuse_is_bad(struct inode *inode)return unlikely (test_bit (FUSE_I_BAD , &get_fuse_inode (inode)->state)); } +static inline struct fuse_entry_out *fuse_entry_out_alloc (struct fuse_conn *fc) +{ +struct fuse_entry_out *entryout; + + entryout =kzalloc (sizeof (*entryout),GFP_KERNEL_ACCOUNT ); + +return entryout; +} +static inline struct folio **fuse_folios_alloc (unsigned int nfolios,gfp_t flags,struct fuse_folio_desc **desc) {
fs/fuse/inode.c +16 -4
@@ -1080,14 +1080,21 @@ static struct dentry *fuse_get_dentry(struct super_block *sb, inode =ilookup5 (sb, handle->nodeid, fuse_inode_eq, &handle->nodeid);if (!inode) { -struct fuse_entry_out outarg; +struct fuse_entry_out *outarg;const struct qstr name =QSTR_INIT ("." ,1 );if (!fc->export_support) goto out_err; - err =fuse_lookup_name (sb, handle->nodeid, &name, &outarg, + outarg =fuse_entry_out_alloc (fc); +if (!outarg) { + err = -ENOMEM ; + goto out_err; + } + + err =fuse_lookup_name (sb, handle->nodeid, &name, outarg, &inode); +kfree (outarg);if (err && err != -ENOENT ) goto out_err;if (err || !inode) {
@@ -1181,14 +1188,19 @@ static struct dentry *fuse_get_parent(struct dentry *child)struct fuse_conn *fc =get_fuse_conn (child_inode);struct inode *inode;struct dentry *parent; -struct fuse_entry_out outarg; +struct fuse_entry_out *outarg;int err;if (!fc->export_support)return ERR_PTR (-ESTALE ); + outarg =fuse_entry_out_alloc (fc); +if (!outarg) +return ERR_PTR (-ENOMEM ); + err =fuse_lookup_name (child_inode->i_sb,get_node_id (child_inode), - &dotdot_name, &outarg, &inode); + &dotdot_name, outarg, &inode); +kfree (outarg);if (err) {if (err == -ENOENT )return ERR_PTR (-ESTALE );
RFC PATCH 3/3 fuse: implementation of the FUSE_LOOKUP_HANDLE operation
In reply to Luis HenriquesThe implementation of LOOKUP_HANDLE simply modifies the LOOKUP operation to include an extra inarg: the file handle for the parent directory (if it is available). Also, because fuse_entry_out now has a extra variable size struct (the actual handle), it also sets the out_argvar flag to true.
Most of the other modifications in this patch are a fallout from these
changes: because fuse_entry_out has been modified to include a variable size struct, every operation that receives such a parameter have to take this into account:
CREATE, LINK, LOOKUP, MKDIR, MKNOD, READDIRPLUS, SYMLINK, TMPFILE
The export_operations were also modified to use this new file handle instead if the lookup_handle operation is implemented for the file system.
--- fs/fuse/dev.c | 1 + fs/fuse/dir.c | 75 +++++++++++++++----- fs/fuse/fuse_i.h | 34 ++++++++-- fs/fuse/inode.c | 139 +++++++++++++++++++++++++++++++++----- fs/fuse/readdir.c | 10 +-- include/uapi/linux/fuse.h | 8 +++ 6 files changed, 224 insertions(+), 43 deletions(-)
fs/fuse/dev.c +1 -0
@@ -632,6 +632,7 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)break ; } } +/* XXX handle FUSE_COMPAT_45_ENTRY_OUT_SIZE */ }static void fuse_force_creds (struct fuse_req *req)
fs/fuse/dir.c +58 -17
174 lines not on this page · raw message
fs/fuse/fuse_i.h +30 -4
@@ -216,6 +216,8 @@ struct fuse_inode {* so preserve the blocksize specified by the server. */ u8 cached_i_blkbits; + +struct fuse_file_handle *fh; };/** FUSE inode state bits */
@@ -1065,6 +1067,26 @@ static inline int invalid_nodeid(u64 nodeid)return !nodeid || nodeid ==FUSE_ROOT_ID ; } +static inline bool fuse_invalid_file_handle (struct fuse_conn *fc, +struct fuse_file_handle *handle) +{ +if (!fc->lookup_handle) +return false; + +return !handle->size || (handle->size >=FUSE_MAX_HANDLE_SZ ); +} + +static inline bool fuse_file_handle_is_equal (struct fuse_conn *fc, +struct fuse_file_handle *fh1, +struct fuse_file_handle *fh2) +{ +if (!fc->lookup_handle || !fh2->size ||// XXX more OPs without handle + ((fh1->size == fh2->size) && + (!memcmp (fh1->handle, fh2->handle, fh1->size)))) +return true; +return false; +} +static inline u64 fuse_get_attr_version (struct fuse_conn *fc) {return atomic64_read (&fc->attr_version);
@@ -1096,7 +1118,10 @@ static inline struct fuse_entry_out *fuse_entry_out_alloc(struct fuse_conn *fc) {struct fuse_entry_out *entryout; - entryout =kzalloc (sizeof (*entryout),GFP_KERNEL_ACCOUNT ); + entryout =kzalloc (sizeof (*entryout) + fc->max_handle_sz, +GFP_KERNEL_ACCOUNT ); +if (entryout) + entryout->fh.size = fc->max_handle_sz;return entryout; }
@@ -1143,10 +1168,11 @@ extern const struct dentry_operations fuse_dentry_operations;struct inode *fuse_iget (struct super_block *sb,u64 nodeid,int generation,struct fuse_attr *attr,u64 attr_valid,u64 attr_version, -u64 evict_ctr); +u64 evict_ctr,struct fuse_file_handle *fh); -int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name, -struct fuse_entry_out *outarg,struct inode **inode); +int fuse_lookup_name (struct super_block *sb,u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg, +struct inode **inode);/** * Send FORGET command
fs/fuse/inode.c +122 -17
252 lines not on this page · raw message
fs/fuse/readdir.c +5 -5
@@ -185,12 +185,12 @@ static int fuse_direntplus_link(struct file *file,return 0 ; } -if (invalid_nodeid (o->nodeid)) -return -EIO ; -if (fuse_invalid_attr (&o->attr)) + fc =get_fuse_conn (dir); + +if (invalid_nodeid (o->nodeid) ||fuse_invalid_attr (&o->attr) || +fuse_invalid_file_handle (fc, &o->fh))return -EIO ; - fc =get_fuse_conn (dir); epoch =atomic_read (&fc->epoch); name.hash =full_name_hash (parent, name.name, name.len);
@@ -235,7 +235,7 @@ static int fuse_direntplus_link(struct file *file, }else { inode =fuse_iget (dir->i_sb, o->nodeid, o->generation, &o->attr,ATTR_TIMEOUT (o), - attr_version, evict_ctr); + attr_version, evict_ctr, &o->fh);if (!inode) inode =ERR_PTR (-ENOMEM );
include/uapi/linux/fuse.h +8 -0
@@ -690,6 +690,13 @@ enum fuse_notify_code {#define FUSE_MIN_READ_BUFFER 8192#define FUSE_COMPAT_ENTRY_OUT_SIZE 120 +#define FUSE_COMPAT_45_ENTRY_OUT_SIZE 128 + +struct fuse_file_handle { +uint32_t size; +uint32_t type; +char handle[0 ]; +};struct fuse_entry_out {uint64_t nodeid;/* Inode ID */
@@ -700,6 +707,7 @@ struct fuse_entry_out {uint32_t entry_valid_nsec;uint32_t attr_valid_nsec;struct fuse_attr attr; +struct fuse_file_handle fh; };struct fuse_forget_in {
Re: [RFC PATCH v1 3/3] fuse: implementation of the FUSE_LOOKUP_HANDLE operation
Quoted 6 lines · Luis Henriques
The implementation of
LOOKUP_HANDLEsimply modifies the LOOKUP operation to include an extra inarg: the file handle for the parent directory (if it is available). Also, becausefuse_entry_outnow has a extra variable size struct (the actual handle), it also sets theout_argvarflag to true.
Quoted 7 lines
Most of the other modifications in this patch are a fallout from these
changes: becausefuse_entry_outhas been modified to include a variable size struct, every operation that receives such a parameter have to take this into account:CREATE, LINK, LOOKUP, MKDIR, MKNOD, READDIRPLUS, SYMLINK, TMPFILE
Overall, this is exactly what I had in mind.
Maybe it's utter garbage but that's what I was aiming for ;)
I'd like to get feedback from Miklos and Bernd on the details of the protocol extension, especially w.r.t backward compat aspects.
Quoted 2 lines
The
export_operationswere also modified to use this new file handle instead if thelookup_handleoperation is implemented for the file system.
This part is really broken. I will comment on it, but would not recommend that you include it in the same patch, because it is an independent change that may even require an independent opt-in flag.
Quoted 173 lines
Signed-off-by Luis Henriques <[email protected]>--- fs/fuse/dev.c | 1 + fs/fuse/dir.c | 75 +++++++++++++++----- fs/fuse/fuse_i.h | 34 ++++++++-- fs/fuse/inode.c | 139 +++++++++++++++++++++++++++++++++----- fs/fuse/readdir.c | 10 +-- include/uapi/linux/fuse.h | 8 +++ 6 files changed, 224 insertions(+), 43 deletions(-)fs/fuse/dev.c +1
-0@@ -632,6 +632,7 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)break ; } } +/* XXX handle FUSE_COMPAT_45_ENTRY_OUT_SIZE */ }static void fuse_force_creds (struct fuse_req *req)fs/fuse/dir.c +41
-14@@ -169,7 +169,8 @@ static void fuse_invalidate_entry(struct dentry *entry) }static void fuse_lookup_init (struct fuse_conn *fc,struct fuse_args *args, -u64 nodeid,const struct qstr *name, +u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg) { args->opcode =FUSE_LOOKUP ;@@ -181,8 +182,20 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, args->in_args[2 ].size =1 ; args->in_args[2 ].value ="" ; args->out_numargs =1 ; - args->out_args[0 ].size =sizeof (struct fuse_entry_out ); + args->out_args[0 ].size =sizeof (*outarg) + outarg->fh.size; args->out_args[0 ].value = outarg; + +if (fc->lookup_handle && dir) { +struct fuse_inode *fi =get_fuse_inode (dir); + + args->opcode =FUSE_LOOKUP_HANDLE ; +if (fi && fi->fh) { + args->in_numargs =4 ; + args->in_args[3 ].size =sizeof (*fi->fh) + fi->fh->size; + args->in_args[3 ].value = fi->fh; + } + args->out_argvar = true; + } }/* @@ -240,7 +253,7 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, attr_version =fuse_get_attr_version (fm->fc); -fuse_lookup_init (fm->fc, &args,get_node_id (dir), +fuse_lookup_init (fm->fc, &args,get_node_id (dir), dir, name, outarg); ret =fuse_simple_request (fm, &args);/* Zero nodeid is same as -ENOENT */ @@ -248,7 +261,8 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, ret = -ENOENT ;if (!ret) { fi =get_fuse_inode (inode); -if (outarg->nodeid !=get_node_id (inode) || +if (!fuse_file_handle_is_equal (fm->fc, fi->fh, &outarg->fh) || + outarg->nodeid !=get_node_id (inode) || (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg->attr.flags &FUSE_ATTR_SUBMOUNT )) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );@@ -365,8 +379,9 @@ bool fuse_invalid_attr(struct fuse_attr *attr)return !fuse_valid_type (attr->mode) || !fuse_valid_size (attr->size); } -int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name, -struct fuse_entry_out *outarg,struct inode **inode) +int fuse_lookup_name (struct super_block *sb,u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg, +struct inode **inode) {struct fuse_mount *fm =get_fuse_mount_super (sb);FUSE_ARGS (args);@@ -388,14 +403,15 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name attr_version =fuse_get_attr_version (fm->fc); evict_ctr =fuse_get_evict_ctr (fm->fc); -fuse_lookup_init (fm->fc, &args, nodeid, name, outarg); +fuse_lookup_init (fm->fc, &args, nodeid, dir, name, outarg); err =fuse_simple_request (fm, &args);/* Zero nodeid is same as -ENOENT, but with valid timeout */ -if (err || !outarg->nodeid) +if (err <0 || !outarg->nodeid)// XXX err = size if args->out_argvar = true goto out_put_forget; err = -EIO ; -if (fuse_invalid_attr (&outarg->attr)) +if (fuse_invalid_attr (&outarg->attr) || +fuse_invalid_file_handle (fm->fc, &outarg->fh)) goto out_put_forget;if (outarg->nodeid ==FUSE_ROOT_ID && outarg->generation !=0 ) {pr_warn_once ("root generation should be zero\n" );@@ -404,7 +420,8 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name *inode =fuse_iget (sb, outarg->nodeid, outarg->generation, &outarg->attr,ATTR_TIMEOUT (outarg), - attr_version, evict_ctr); + attr_version, evict_ctr, + &outarg->fh); err = -ENOMEM ;if (!*inode) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );@@ -440,14 +457,14 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,return ERR_PTR (-ENOMEM ); locked =fuse_lock_inode (dir); - err =fuse_lookup_name (dir->i_sb,get_node_id (dir), &entry->d_name, + err =fuse_lookup_name (dir->i_sb,get_node_id (dir), dir, &entry->d_name, outarg, &inode);fuse_unlock_inode (dir, locked);if (err == -ENOENT ) { outarg_valid = false; err =0 ; } -if (err) +if (err <0 )// XXX err = size if args->out_argvar = true goto out_err; err = -EIO ;@@ -688,8 +705,16 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, args.in_args[0 ].value = &inarg; args.in_args[1 ].size = entry->d_name.len +1 ; args.in_args[1 ].value = entry->d_name.name; +if (fm->fc->lookup_handle) { + fi =get_fuse_inode (dir); +if (fi->fh) { + args.in_numargs =3 ; + args.in_args[2 ].size =sizeof (*fi->fh) + fi->fh->size; + args.in_args[3 ].value = fi->fh; + } + } args.out_numargs =2 ; - args.out_args[0 ].size =sizeof (*outentry); + args.out_args[0 ].size =sizeof (*outentry) + outentry->fh.size; args.out_args[0 ].value = outentry;/* Store outarg for fuse_finish_open() */ outopenp = &ff->args->open_outarg;@@ -707,6 +732,7 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, err = -EIO ;if (!S_ISREG (outentry->attr.mode) ||invalid_nodeid (outentry->nodeid) || +fuse_invalid_file_handle (fm->fc, &outentry->fh) ||fuse_invalid_attr (&outentry->attr)) goto out_free_outentry;@@ -714,7 +740,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, ff->nodeid = outentry->nodeid; ff->open_flags = outopenp->open_flags; inode =fuse_iget (dir->i_sb, outentry->nodeid, outentry->generation, - &outentry->attr,ATTR_TIMEOUT (outentry),0 ,0 ); + &outentry->attr,ATTR_TIMEOUT (outentry),0 ,0 , + &outentry->fh);if (!inode) { flags &= ~(O_CREAT |O_EXCL |O_TRUNC );fuse_sync_release (NULL , ff, flags);
fs/fuse/dir.c static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun · line 864
Quoted 10 lines
fs/fuse/dir.c +7
-0@@ -828,9 +855,21 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun goto out_put_forget_req; } +if (fm->fc->lookup_handle) { +struct fuse_inode *fi =get_fuse_inode (dir); +int idx = args->in_numargs; + +WARN_ON_ONCE (idx >=4 ); + +if (fi->fh) {
This assertion can be handled gracefully
if (fi->fh && !WARN_ON_ONCE(idx >= 4)) {Quoted 173 lines
fs/fuse/dir.c +10
-3+ args->in_args[idx].size =sizeof (*fi->fh) + fi->fh->size; + args->in_args[idx].value = fi->fh; + args->in_numargs++; + } + } args->nodeid =get_node_id (dir); args->out_numargs =1 ; - args->out_args[0 ].size =sizeof (*outarg); + args->out_args[0 ].size =sizeof (*outarg) + outarg->fh.size; args->out_args[0 ].value = outarg;if (args->opcode !=FUSE_LINK ) {@@ -845,14 +884,16 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun goto out_free_outarg; err = -EIO ; -if (invalid_nodeid (outarg->nodeid) ||fuse_invalid_attr (&outarg->attr)) +if (invalid_nodeid (outarg->nodeid) ||fuse_invalid_attr (&outarg->attr) || +fuse_invalid_file_handle (fm->fc, &outarg->fh)) goto out_free_outarg;if ((outarg->attr.mode ^ mode) &S_IFMT ) goto out_free_outarg; inode =fuse_iget (dir->i_sb, outarg->nodeid, outarg->generation, - &outarg->attr,ATTR_TIMEOUT (outarg),0 ,0 ); + &outarg->attr,ATTR_TIMEOUT (outarg),0 ,0 , + &outarg->fh);if (!inode) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );kfree (outarg);fs/fuse/fuse_i.h +30
-4@@ -216,6 +216,8 @@ struct fuse_inode {* so preserve the blocksize specified by the server. */ u8 cached_i_blkbits; + +struct fuse_file_handle *fh; };/** FUSE inode state bits */ @@ -1065,6 +1067,26 @@ static inline int invalid_nodeid(u64 nodeid)return !nodeid || nodeid ==FUSE_ROOT_ID ; } +static inline bool fuse_invalid_file_handle (struct fuse_conn *fc, +struct fuse_file_handle *handle) +{ +if (!fc->lookup_handle) +return false; + +return !handle->size || (handle->size >=FUSE_MAX_HANDLE_SZ ); +} + +static inline bool fuse_file_handle_is_equal (struct fuse_conn *fc, +struct fuse_file_handle *fh1, +struct fuse_file_handle *fh2) +{ +if (!fc->lookup_handle || !fh2->size ||// XXX more OPs without handle + ((fh1->size == fh2->size) && + (!memcmp (fh1->handle, fh2->handle, fh1->size)))) +return true; +return false; +} +static inline u64 fuse_get_attr_version (struct fuse_conn *fc) {return atomic64_read (&fc->attr_version);@@ -1096,7 +1118,10 @@ static inline struct fuse_entry_out *fuse_entry_out_alloc(struct fuse_conn *fc) {struct fuse_entry_out *entryout; - entryout =kzalloc (sizeof (*entryout),GFP_KERNEL_ACCOUNT ); + entryout =kzalloc (sizeof (*entryout) + fc->max_handle_sz, +GFP_KERNEL_ACCOUNT ); +if (entryout) + entryout->fh.size = fc->max_handle_sz;return entryout; }@@ -1143,10 +1168,11 @@ extern const struct dentry_operations fuse_dentry_operations;struct inode *fuse_iget (struct super_block *sb,u64 nodeid,int generation,struct fuse_attr *attr,u64 attr_valid,u64 attr_version, -u64 evict_ctr); +u64 evict_ctr,struct fuse_file_handle *fh); -int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name, -struct fuse_entry_out *outarg,struct inode **inode); +int fuse_lookup_name (struct super_block *sb,u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg, +struct inode **inode);/** * Send FORGET command fs/fuse/inode.c +31
-1@@ -95,6 +95,25 @@ static struct fuse_submount_lookup *fuse_alloc_submount_lookup(void)return NULL ; } +/* +* XXX postpone this allocation and later use the real size instead of max +*/ +static bool fuse_inode_handle_alloc (struct super_block *sb, +struct fuse_inode *fi) +{ +struct fuse_conn *fc =get_fuse_conn_super (sb); + + fi->fh =NULL ; +if (fc->lookup_handle) { + fi->fh =kzalloc (sizeof (*fi->fh) + fc->max_handle_sz, +GFP_KERNEL_ACCOUNT ); +if (!fi->fh) +return false; + } + +return true; +} +static struct inode *fuse_alloc_inode (struct super_block *sb) {struct fuse_inode *fi;@@ -120,8 +139,15 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH ))fuse_inode_backing_set (fi,NULL ); +if (!fuse_inode_handle_alloc (sb, fi)) + goto out_free_dax; +return &fi->inode; +out_free_dax: +#ifdef CONFIG_FUSE_DAX +kfree (fi->dax); +#endif out_free_forget:kfree (fi->forget); out_free:@@ -132,6 +158,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)static void fuse_free_inode (struct inode *inode) {struct fuse_inode *fi =get_fuse_inode (inode); +struct fuse_conn *fc =get_fuse_conn (inode);mutex_destroy (&fi->mutex);kfree (fi->forget);@@ -141,6 +168,9 @@ static void fuse_free_inode(struct inode *inode)if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH ))fuse_backing_put (fuse_inode_backing (fi)); +if (fc->lookup_handle) +kfree (fi->fh); +kmem_cache_free (fuse_inode_cachep, fi); }@@ -465,7 +495,7 @@ static int fuse_inode_set(struct inode *inode, void *_nodeidp)struct inode *fuse_iget (struct super_block *sb,u64 nodeid,int generation,struct fuse_attr *attr,u64 attr_valid,u64 attr_version, -u64 evict_ctr) +u64 evict_ctr,struct fuse_file_handle *fh) {struct inode *inode;struct fuse_inode *fi;@@ -505,14 +535,29 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,if (!inode)
fs/fuse/inode.c struct inode *fuse_iget(struct super_block *sb, u64 nodeid, · line 545
Quoted 10 lines
fs/fuse/inode.c +8
-0return NULL ; + fi =get_fuse_inode (inode); +if (fc->lookup_handle && fh->size) { +if (fi->fh->size ==0 ) { +if (fh->size >= fc->max_handle_sz) +pr_warn ("Truncating file handle size (%u)\n" , + fh->size); + fi->fh->size = fh->size < fc->max_handle_sz ? + fh->size : fc->max_handle_sz -1 ;
I can't think of anything good that can come out of copying a truncated handle. If server provides a handle that does not meet the agreed max_handle_sz then it is an invalid handle.
Quoted 43 lines
fs/fuse/inode.c +14
-5+memcpy (fi->fh->handle, fh->handle, fi->fh->size); + }else +pr_warn ("handle was already set (size: %u)\n" , + fi->fh->size); + }if ((inode->i_state &I_NEW )) { inode->i_flags |=S_NOATIME ;if (!fc->writeback_cache || !S_ISREG (attr->mode)) inode->i_flags |=S_NOCMTIME ; inode->i_generation = generation; +fuse_init_inode (inode, attr, fc);unlock_new_inode (inode); - }else if (fuse_stale_inode (inode, generation, attr)) { + }else if (fuse_stale_inode (inode, generation, attr) || + !fuse_file_handle_is_equal (fc, fi->fh, fh)) {/* nodeid was reused, any I/O on the old inode should fail */ fuse_make_bad (inode);if (inode !=d_inode (sb->s_root)) {@@ -521,7 +566,6 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, goto retry; } } - fi =get_fuse_inode (inode);spin_lock (&fi->lock); fi->nlookup++;spin_unlock (&fi->lock);@@ -1059,12 +1103,23 @@ static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned int mo attr.mode = mode; attr.ino =FUSE_ROOT_ID ; attr.nlink =1 ; -return fuse_iget (sb,FUSE_ROOT_ID ,0 , &attr,0 ,0 ,0 ); +return fuse_iget (sb,FUSE_ROOT_ID ,0 , &attr,0 ,0 ,0 ,NULL );// XXX } +enum { +HANDLE_TYPE_NODEID =0 , +HANDLE_TYPE_HANDLE =1 , +}; +struct fuse_inode_handle { -u64 nodeid; -u32 generation;
fs/fuse/inode.c static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned int mo · line 1124
Quoted 10 lines
fs/fuse/inode.c +8
-0+u32 type; +union { +struct { +u64 nodeid; +u32 generation; + }; +struct fuse_file_handle fh; + }; };
These changes belong in a different patch, so I will reply in a separate email.
Thanks,
Amir.
Re: [RFC PATCH v1 3/3] fuse: implementation of the FUSE_LOOKUP_HANDLE operation
Thanks a lot for this Luis!
Quoted 12 lines · Amir Goldstein
Quoted 11 lines · Luis Henriques
The implementation of
LOOKUP_HANDLEsimply modifies the LOOKUP operation to include an extra inarg: the file handle for the parent directory (if it is available). Also, becausefuse_entry_outnow has a extra variable size struct (the actual handle), it also sets theout_argvarflag to true.Most of the other modifications in this patch are a fallout from these
changes: becausefuse_entry_outhas been modified to include a variable size struct, every operation that receives such a parameter have to take this into account:
Quoted 8 lines
Quoted 2 lines
CREATE, LINK, LOOKUP, MKDIR, MKNOD, READDIRPLUS, SYMLINK, TMPFILE
Overall, this is exactly what I had in mind.
Maybe it's utter garbage but that's what I was aiming for ;)I'd like to get feedback from Miklos and Bernd on the details of the protocol extension, especially w.r.t backward compat aspects.
I will look into it in the late afternoon
Re: [RFC PATCH v1 3/3] fuse: implementation of the FUSE_LOOKUP_HANDLE operation
Quoted 18 lines · Bernd Schubert
Thanks a lot for this Luis!
Quoted 15 lines · Amir Goldstein
Quoted 13 lines · Luis Henriques
The implementation of
LOOKUP_HANDLEsimply modifies the LOOKUP operation to include an extra inarg: the file handle for the parent directory (if it is available). Also, becausefuse_entry_outnow has a extra variable size struct (the actual handle), it also sets theout_argvarflag to true.Most of the other modifications in this patch are a fallout from these
changes: becausefuse_entry_outhas been modified to include a variable size struct, every operation that receives such a parameter have to take this into account:CREATE, LINK, LOOKUP, MKDIR, MKNOD, READDIRPLUS, SYMLINK, TMPFILE
Quoted 7 lines
Quoted 5 lines
Overall, this is exactly what I had in mind.
Maybe it's utter garbage but that's what I was aiming for ;)I'd like to get feedback from Miklos and Bernd on the details of the protocol extension, especially w.r.t backward compat aspects.
I will look into it in the late afternoon
That'd be awesome, thanks a lot Bernd!
Cheers,
Signature · 1 line
Luís
Re: [RFC PATCH v1 3/3] fuse: implementation of the FUSE_LOOKUP_HANDLE operation
In reply to Amir GoldsteinQuoted 12 lines · Amir Goldstein
Quoted 11 lines · Luis Henriques
The implementation of
LOOKUP_HANDLEsimply modifies the LOOKUP operation to include an extra inarg: the file handle for the parent directory (if it is available). Also, becausefuse_entry_outnow has a extra variable size struct (the actual handle), it also sets theout_argvarflag to true.Most of the other modifications in this patch are a fallout from these
changes: becausefuse_entry_outhas been modified to include a variable size struct, every operation that receives such a parameter have to take this into account:
Quoted 5 lines
Quoted 2 lines
CREATE, LINK, LOOKUP, MKDIR, MKNOD, READDIRPLUS, SYMLINK, TMPFILE
Overall, this is exactly what I had in mind.
Maybe it's utter garbage but that's what I was aiming for ;)
Heh! :-)
Quoted 2 lines
I'd like to get feedback from Miklos and Bernd on the details of the protocol extension, especially w.r.t backward compat aspects.
Right, on the backward compat side, I guess I could have at least added the code to fuse_adjust_compat(), similar to what's already there for other changes.
Quoted 6 lines
Quoted 2 lines
The
export_operationswere also modified to use this new file handle instead if thelookup_handleoperation is implemented for the file system.This part is really broken. I will comment on it, but would not recommend that you include it in the same patch, because it is an independent change that may even require an independent opt-in flag.
Yes, it definitely makes sense to separate that. The reason I decided to tackle it here was for convenience, I guess. Because I had to change interfaces of fuse_lookup_name, I decided to handle it here as well. But yeah it requires some more thought (and as we say, probably a separate flag).
Quoted 186 lines
Quoted 173 lines
Signed-off-by Luis Henriques <[email protected]>--- fs/fuse/dev.c | 1 + fs/fuse/dir.c | 75 +++++++++++++++----- fs/fuse/fuse_i.h | 34 ++++++++-- fs/fuse/inode.c | 139 +++++++++++++++++++++++++++++++++----- fs/fuse/readdir.c | 10 +-- include/uapi/linux/fuse.h | 8 +++ 6 files changed, 224 insertions(+), 43 deletions(-)fs/fuse/dev.c +1
-0@@ -632,6 +632,7 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)break ; } } +/* XXX handle FUSE_COMPAT_45_ENTRY_OUT_SIZE */ }static void fuse_force_creds (struct fuse_req *req)fs/fuse/dir.c +41
-14@@ -169,7 +169,8 @@ static void fuse_invalidate_entry(struct dentry *entry) }static void fuse_lookup_init (struct fuse_conn *fc,struct fuse_args *args, -u64 nodeid,const struct qstr *name, +u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg) { args->opcode =FUSE_LOOKUP ;@@ -181,8 +182,20 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, args->in_args[2 ].size =1 ; args->in_args[2 ].value ="" ; args->out_numargs =1 ; - args->out_args[0 ].size =sizeof (struct fuse_entry_out ); + args->out_args[0 ].size =sizeof (*outarg) + outarg->fh.size; args->out_args[0 ].value = outarg; + +if (fc->lookup_handle && dir) { +struct fuse_inode *fi =get_fuse_inode (dir); + + args->opcode =FUSE_LOOKUP_HANDLE ; +if (fi && fi->fh) { + args->in_numargs =4 ; + args->in_args[3 ].size =sizeof (*fi->fh) + fi->fh->size; + args->in_args[3 ].value = fi->fh; + } + args->out_argvar = true; + } }/* @@ -240,7 +253,7 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, attr_version =fuse_get_attr_version (fm->fc); -fuse_lookup_init (fm->fc, &args,get_node_id (dir), +fuse_lookup_init (fm->fc, &args,get_node_id (dir), dir, name, outarg); ret =fuse_simple_request (fm, &args);/* Zero nodeid is same as -ENOENT */ @@ -248,7 +261,8 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, ret = -ENOENT ;if (!ret) { fi =get_fuse_inode (inode); -if (outarg->nodeid !=get_node_id (inode) || +if (!fuse_file_handle_is_equal (fm->fc, fi->fh, &outarg->fh) || + outarg->nodeid !=get_node_id (inode) || (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg->attr.flags &FUSE_ATTR_SUBMOUNT )) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );@@ -365,8 +379,9 @@ bool fuse_invalid_attr(struct fuse_attr *attr)return !fuse_valid_type (attr->mode) || !fuse_valid_size (attr->size); } -int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name, -struct fuse_entry_out *outarg,struct inode **inode) +int fuse_lookup_name (struct super_block *sb,u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg, +struct inode **inode) {struct fuse_mount *fm =get_fuse_mount_super (sb);FUSE_ARGS (args);@@ -388,14 +403,15 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name attr_version =fuse_get_attr_version (fm->fc); evict_ctr =fuse_get_evict_ctr (fm->fc); -fuse_lookup_init (fm->fc, &args, nodeid, name, outarg); +fuse_lookup_init (fm->fc, &args, nodeid, dir, name, outarg); err =fuse_simple_request (fm, &args);/* Zero nodeid is same as -ENOENT, but with valid timeout */ -if (err || !outarg->nodeid) +if (err <0 || !outarg->nodeid)// XXX err = size if args->out_argvar = true goto out_put_forget; err = -EIO ; -if (fuse_invalid_attr (&outarg->attr)) +if (fuse_invalid_attr (&outarg->attr) || +fuse_invalid_file_handle (fm->fc, &outarg->fh)) goto out_put_forget;if (outarg->nodeid ==FUSE_ROOT_ID && outarg->generation !=0 ) {pr_warn_once ("root generation should be zero\n" );@@ -404,7 +420,8 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name *inode =fuse_iget (sb, outarg->nodeid, outarg->generation, &outarg->attr,ATTR_TIMEOUT (outarg), - attr_version, evict_ctr); + attr_version, evict_ctr, + &outarg->fh); err = -ENOMEM ;if (!*inode) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );@@ -440,14 +457,14 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,return ERR_PTR (-ENOMEM ); locked =fuse_lock_inode (dir); - err =fuse_lookup_name (dir->i_sb,get_node_id (dir), &entry->d_name, + err =fuse_lookup_name (dir->i_sb,get_node_id (dir), dir, &entry->d_name, outarg, &inode);fuse_unlock_inode (dir, locked);if (err == -ENOENT ) { outarg_valid = false; err =0 ; } -if (err) +if (err <0 )// XXX err = size if args->out_argvar = true goto out_err; err = -EIO ;@@ -688,8 +705,16 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, args.in_args[0 ].value = &inarg; args.in_args[1 ].size = entry->d_name.len +1 ; args.in_args[1 ].value = entry->d_name.name; +if (fm->fc->lookup_handle) { + fi =get_fuse_inode (dir); +if (fi->fh) { + args.in_numargs =3 ; + args.in_args[2 ].size =sizeof (*fi->fh) + fi->fh->size; + args.in_args[3 ].value = fi->fh; + } + } args.out_numargs =2 ; - args.out_args[0 ].size =sizeof (*outentry); + args.out_args[0 ].size =sizeof (*outentry) + outentry->fh.size; args.out_args[0 ].value = outentry;/* Store outarg for fuse_finish_open() */ outopenp = &ff->args->open_outarg;@@ -707,6 +732,7 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, err = -EIO ;if (!S_ISREG (outentry->attr.mode) ||invalid_nodeid (outentry->nodeid) || +fuse_invalid_file_handle (fm->fc, &outentry->fh) ||fuse_invalid_attr (&outentry->attr)) goto out_free_outentry;@@ -714,7 +740,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, ff->nodeid = outentry->nodeid; ff->open_flags = outopenp->open_flags; inode =fuse_iget (dir->i_sb, outentry->nodeid, outentry->generation, - &outentry->attr,ATTR_TIMEOUT (outentry),0 ,0 ); + &outentry->attr,ATTR_TIMEOUT (outentry),0 ,0 , + &outentry->fh);if (!inode) { flags &= ~(O_CREAT |O_EXCL |O_TRUNC );fuse_sync_release (NULL , ff, flags);fs/fuse/dir.c static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun · line 864
Quoted 10 lines
fs/fuse/dir.c +7
-0@@ -828,9 +855,21 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun goto out_put_forget_req; } +if (fm->fc->lookup_handle) { +struct fuse_inode *fi =get_fuse_inode (dir); +int idx = args->in_numargs; + +WARN_ON_ONCE (idx >=4 ); + +if (fi->fh) {This assertion can be handled gracefully
Quoted 1 line
if (fi->fh && !WARN_ON_ONCE(idx >= 4)) {Yep, makes sense.
Quoted 175 lines
Quoted 175 lines
fs/fuse/dir.c +10
-3+ args->in_args[idx].size =sizeof (*fi->fh) + fi->fh->size; + args->in_args[idx].value = fi->fh; + args->in_numargs++; + } + } args->nodeid =get_node_id (dir); args->out_numargs =1 ; - args->out_args[0 ].size =sizeof (*outarg); + args->out_args[0 ].size =sizeof (*outarg) + outarg->fh.size; args->out_args[0 ].value = outarg;if (args->opcode !=FUSE_LINK ) {@@ -845,14 +884,16 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun goto out_free_outarg; err = -EIO ; -if (invalid_nodeid (outarg->nodeid) ||fuse_invalid_attr (&outarg->attr)) +if (invalid_nodeid (outarg->nodeid) ||fuse_invalid_attr (&outarg->attr) || +fuse_invalid_file_handle (fm->fc, &outarg->fh)) goto out_free_outarg;if ((outarg->attr.mode ^ mode) &S_IFMT ) goto out_free_outarg; inode =fuse_iget (dir->i_sb, outarg->nodeid, outarg->generation, - &outarg->attr,ATTR_TIMEOUT (outarg),0 ,0 ); + &outarg->attr,ATTR_TIMEOUT (outarg),0 ,0 , + &outarg->fh);if (!inode) {fuse_queue_forget (fm->fc, forget, outarg->nodeid,1 );kfree (outarg);fs/fuse/fuse_i.h +30
-4@@ -216,6 +216,8 @@ struct fuse_inode {* so preserve the blocksize specified by the server. */ u8 cached_i_blkbits; + +struct fuse_file_handle *fh; };/** FUSE inode state bits */ @@ -1065,6 +1067,26 @@ static inline int invalid_nodeid(u64 nodeid)return !nodeid || nodeid ==FUSE_ROOT_ID ; } +static inline bool fuse_invalid_file_handle (struct fuse_conn *fc, +struct fuse_file_handle *handle) +{ +if (!fc->lookup_handle) +return false; + +return !handle->size || (handle->size >=FUSE_MAX_HANDLE_SZ ); +} + +static inline bool fuse_file_handle_is_equal (struct fuse_conn *fc, +struct fuse_file_handle *fh1, +struct fuse_file_handle *fh2) +{ +if (!fc->lookup_handle || !fh2->size ||// XXX more OPs without handle + ((fh1->size == fh2->size) && + (!memcmp (fh1->handle, fh2->handle, fh1->size)))) +return true; +return false; +} +static inline u64 fuse_get_attr_version (struct fuse_conn *fc) {return atomic64_read (&fc->attr_version);@@ -1096,7 +1118,10 @@ static inline struct fuse_entry_out *fuse_entry_out_alloc(struct fuse_conn *fc) {struct fuse_entry_out *entryout; - entryout =kzalloc (sizeof (*entryout),GFP_KERNEL_ACCOUNT ); + entryout =kzalloc (sizeof (*entryout) + fc->max_handle_sz, +GFP_KERNEL_ACCOUNT ); +if (entryout) + entryout->fh.size = fc->max_handle_sz;return entryout; }@@ -1143,10 +1168,11 @@ extern const struct dentry_operations fuse_dentry_operations;struct inode *fuse_iget (struct super_block *sb,u64 nodeid,int generation,struct fuse_attr *attr,u64 attr_valid,u64 attr_version, -u64 evict_ctr); +u64 evict_ctr,struct fuse_file_handle *fh); -int fuse_lookup_name (struct super_block *sb,u64 nodeid,const struct qstr *name, -struct fuse_entry_out *outarg,struct inode **inode); +int fuse_lookup_name (struct super_block *sb,u64 nodeid,struct inode *dir, +const struct qstr *name,struct fuse_entry_out *outarg, +struct inode **inode);/** * Send FORGET command fs/fuse/inode.c +31
-1@@ -95,6 +95,25 @@ static struct fuse_submount_lookup *fuse_alloc_submount_lookup(void)return NULL ; } +/* +* XXX postpone this allocation and later use the real size instead of max +*/ +static bool fuse_inode_handle_alloc (struct super_block *sb, +struct fuse_inode *fi) +{ +struct fuse_conn *fc =get_fuse_conn_super (sb); + + fi->fh =NULL ; +if (fc->lookup_handle) { + fi->fh =kzalloc (sizeof (*fi->fh) + fc->max_handle_sz, +GFP_KERNEL_ACCOUNT ); +if (!fi->fh) +return false; + } + +return true; +} +static struct inode *fuse_alloc_inode (struct super_block *sb) {struct fuse_inode *fi;@@ -120,8 +139,15 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH ))fuse_inode_backing_set (fi,NULL ); +if (!fuse_inode_handle_alloc (sb, fi)) + goto out_free_dax; +return &fi->inode; +out_free_dax: +#ifdef CONFIG_FUSE_DAX +kfree (fi->dax); +#endif out_free_forget:kfree (fi->forget); out_free:@@ -132,6 +158,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)static void fuse_free_inode (struct inode *inode) {struct fuse_inode *fi =get_fuse_inode (inode); +struct fuse_conn *fc =get_fuse_conn (inode);mutex_destroy (&fi->mutex);kfree (fi->forget);@@ -141,6 +168,9 @@ static void fuse_free_inode(struct inode *inode)if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH ))fuse_backing_put (fuse_inode_backing (fi)); +if (fc->lookup_handle) +kfree (fi->fh); +kmem_cache_free (fuse_inode_cachep, fi); }@@ -465,7 +495,7 @@ static int fuse_inode_set(struct inode *inode, void *_nodeidp)struct inode *fuse_iget (struct super_block *sb,u64 nodeid,int generation,struct fuse_attr *attr,u64 attr_valid,u64 attr_version, -u64 evict_ctr) +u64 evict_ctr,struct fuse_file_handle *fh) {struct inode *inode;struct fuse_inode *fi;@@ -505,14 +535,29 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,if (!inode)return NULL ;
Quoted 12 lines
fs/fuse/inode.c struct inode *fuse_iget(struct super_block *sb, u64 nodeid, · line 545
Quoted 8 lines
fs/fuse/inode.c +8
-0+ fi =get_fuse_inode (inode); +if (fc->lookup_handle && fh->size) { +if (fi->fh->size ==0 ) { +if (fh->size >= fc->max_handle_sz) +pr_warn ("Truncating file handle size (%u)\n" , + fh->size); + fi->fh->size = fh->size < fc->max_handle_sz ? + fh->size : fc->max_handle_sz -1 ;I can't think of anything good that can come out of copying a truncated handle. If server provides a handle that does not meet the agreed
max_handle_szthen it is an invalid handle.
True. I'll fix that.
Quoted 47 lines
Quoted 47 lines
fs/fuse/inode.c +18
-5+memcpy (fi->fh->handle, fh->handle, fi->fh->size); + }else +pr_warn ("handle was already set (size: %u)\n" , + fi->fh->size); + }if ((inode->i_state &I_NEW )) { inode->i_flags |=S_NOATIME ;if (!fc->writeback_cache || !S_ISREG (attr->mode)) inode->i_flags |=S_NOCMTIME ; inode->i_generation = generation; +fuse_init_inode (inode, attr, fc);unlock_new_inode (inode); - }else if (fuse_stale_inode (inode, generation, attr)) { + }else if (fuse_stale_inode (inode, generation, attr) || + !fuse_file_handle_is_equal (fc, fi->fh, fh)) {/* nodeid was reused, any I/O on the old inode should fail */ fuse_make_bad (inode);if (inode !=d_inode (sb->s_root)) {@@ -521,7 +566,6 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, goto retry; } } - fi =get_fuse_inode (inode);spin_lock (&fi->lock); fi->nlookup++;spin_unlock (&fi->lock);@@ -1059,12 +1103,23 @@ static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned int mo attr.mode = mode; attr.ino =FUSE_ROOT_ID ; attr.nlink =1 ; -return fuse_iget (sb,FUSE_ROOT_ID ,0 , &attr,0 ,0 ,0 ); +return fuse_iget (sb,FUSE_ROOT_ID ,0 , &attr,0 ,0 ,0 ,NULL );// XXX } +enum { +HANDLE_TYPE_NODEID =0 , +HANDLE_TYPE_HANDLE =1 , +}; + struct fuse_inode_handle { -u64 nodeid; -u32 generation; + u32 type; + union { + struct { + u64 nodeid;
Quoted 8 lines
fs/fuse/inode.c static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned int mo · line 1124
Quoted 6 lines
fs/fuse/inode.c +4
-0+u32 generation; + }; +struct fuse_file_handle fh; + }; };These changes belong in a different patch, so I will reply in a separate email.
OK, it definitely makes sense to split this. But, more important, I'll also need to "unbreak" it.
Again, thank you for the feedback. I'll keep working on this, and in the meantime maybe others will have some spare cycles to comment on this approach as well.
Cheers,
Signature · 1 line
Luís