fuse: atomic open
Subsystems (2)
v2 cover fuse: atomic open
From: jamz <[email protected]>
Add FUSE_OPEN_ATOMIC, allowing the kernel to skip LOOKUP to improve performance. A server implementing FUSE_OPEN_ATOMIC will look up the name, create it if O_CREAT is supplied, and open it in one request.
The reply says whether the file was created, as Miklos suggested in [1]. The overall pattern follows his sketch in [2]. For a cached name, the kernel compares the returned nodeid with the cached one and looks the name up again on a mismatch.
A server without FUSE_OPEN_ATOMIC replies -ENOSYS and keeps today's behaviour.
Tested with a new selftest under UML and KVM.
Changes in v2:
- Drop the d_drop() before d_splice_alias() for an entry-only reply, and use d_splice_alias() for FUSE_CREATE and FUSE_OPEN_ATOMIC replies. FUSE_TMPFILE keeps d_instantiate(), as its dentry stays unhashed (NeilBrown).
- Describe what the server does and when the kernel checks permission in each case (NeilBrown).
- Check in the selftest that an O_TMPFILE file has no name in its directory.
- Rebase onto fuse for-next, which has f1ac607f786f ("VFS: enhance d_splice_alias() to handle hashed dentries"). Accept a fuse_open_out without backing_id_64, as FUSE_CREATE and FUSE_OPEN now do, and test it.
v1: https://lore.kernel.org/fuse-devel/[email protected]/
[1] https://lore.kernel.org/all/CAJfpeguEK4JsFo60=yHkpLL6XkDGS7cQ5GOhiFL379KsYk0TsQ@mail.gmail.com/
[2] https://lore.kernel.org/all/CAJfpegvXtXY=Pbxv+dMGFR8mvWN0DUwhSo6NwaVexk6Y6sao+w@mail.gmail.com/
Jimmy Zuber (3):
fuse: add FUSE_OPEN_ATOMIC
fuse: open cached files with FUSE_OPEN_ATOMIC
selftests/fuse: add test for FUSE_OPEN_ATOMIC
fs/fuse/dir.c | 354 ++++++++++-- fs/fuse/file.c | 4 +- fs/fuse/fuse_i.h | 7 + include/uapi/linux/fuse.h | 8 +- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 3 +- .../filesystems/fuse/atomic_open_test.c | 518 ++++++++++++++++++ 7 files changed, 841 insertions(+), 54 deletions(-) create mode 100644 tools/testing/selftests/filesystems/fuse/atomic_open_test.c
base-commit: 9b1da7b4a4e197072e630c3b85d4100a399752ff
Signature · 1 line
2.50.1
PATCH v2 1/3 fuse: add FUSE_OPEN_ATOMIC
Add FUSE_OPEN_ATOMIC, allowing the kernel to skip LOOKUP to improve performance. A server implementing FUSE_OPEN_ATOMIC will look up the name, create it if O_CREAT is supplied, and open it in one request.
The server replies with the entry and, if it opened the file, the open file:
- New name with O_CREAT: the server creates and opens the file and sets FOPEN_CREATED. The kernel checks write permission on the parent before sending the request.
- Existing regular file without O_TRUNC: the server opens it. The kernel checks permission with may_open() after the reply and releases the file if the check fails, as for other ->atomic_open filesystems. A server can instead return the entry only, to have the kernel check permission before FUSE_OPEN.
- Existing file with O_TRUNC, or not a regular file: the server returns the entry only, and the VFS checks permission and opens it, so that truncation is performed after permissions are checked.
- Name that does not exist, without O_CREAT: the server returns a zero nodeid, cacheable like a negative LOOKUP.
FMODE_CREATED is set only when the server reports that it created the file. Therefore a file created by someone else between LOOKUP and CREATE is no longer opened without a permission check.
A server without the request replies -ENOSYS, and the kernel falls back to FUSE_LOOKUP, keeping backwards compatibility.
--- fs/fuse/dir.c | 107 +++++++++++++++++++++++++++++++++++--- fs/fuse/fuse_i.h | 6 +++ include/uapi/linux/fuse.h | 8 ++- 3 files changed, 112 insertions(+), 9 deletions(-)
fs/fuse/dir.c +99 -8
@@ -815,7 +815,46 @@ static void free_ext_value(struct fuse_args *args) }/* -* Atomic create+open operation +* FUSE_OPEN_ATOMIC found an existing name and left the open to the VFS. A +* zero nodeid means the name does not exist. +*/ +static int fuse_open_atomic_found (struct inode *dir,struct dentry *entry, +struct file *file, +struct fuse_entry_out *outarg, +struct fuse_forget_link *forget,int epoch, +u64 attr_version,u64 evict_ctr) +{ +struct fuse_conn *fc =get_fuse_conn (dir); +struct inode *inode =NULL ; +struct dentry *res; + +if (outarg->nodeid) { + inode =fuse_iget (dir->i_sb, outarg->nodeid, outarg->generation, + &outarg->attr,ATTR_TIMEOUT (outarg), + attr_version, evict_ctr); +if (!inode) { +fuse_chan_queue_forget (fc->chan, forget, + outarg->nodeid,1 ); +return -ENOMEM ; + } + } +kfree (forget); +if (inode &&get_node_id (inode) ==FUSE_ROOT_ID ) { +iput (inode); +return -EIO ; + } + + res =d_splice_alias (inode, entry); +if (!IS_ERR (res)) { +fuse_dentry_set_epoch (res ?: entry, epoch); +fuse_change_entry_timeout (res ?: entry, outarg); + } +return finish_no_open (file, res); +} + +/* +* Atomic create+open operation, or lookup with optional create and open for +* FUSE_OPEN_ATOMIC * * If the filesystem doesn't support this, then fall back to separate * 'mknod' + 'open' requests.
@@ -833,8 +872,12 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,struct fuse_entry_out outentry;struct fuse_inode *fi;struct fuse_file *ff; +u64 attr_version, evict_ctr;int epoch, err;bool trunc = flags &O_TRUNC ; +bool atomic = opcode ==FUSE_OPEN_ATOMIC ; +bool create = !atomic || (flags &O_CREAT ); +bool locked, created;/* Userspace expects S_IFREG in create mode */ BUG_ON ((mode &S_IFMT ) !=S_IFREG );
@@ -880,25 +923,59 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, args.out_args[1 ].size =sizeof (*outopenp); args.out_args[1 ].value = outopenp; - err =get_create_ext (idmap, &args, dir, entry, mode); -if (err) - goto out_free_ff; +if (create) { + err =get_create_ext (idmap, &args, dir, entry, mode); +if (err) + goto out_free_ff; + }else { + idmap = &invalid_mnt_idmap; + } + + attr_version =fuse_get_attr_version (fm->fc); + evict_ctr =fuse_get_evict_ctr (fm->fc); +/* Without O_CREAT the parent is locked shared, as for a lookup */ + locked = !create &&fuse_lock_inode (dir); err =fuse_simple_idmap_request (idmap, fm, &args); +fuse_unlock_inode (dir, locked);free_ext_value (&args);if (err <0 ) goto out_free_ff; err = -EIO ; +if (atomic && !args.out_args[1 ].size) { +/* A zero nodeid: the name does not exist and was not created */ +if (!outentry.nodeid && create) + goto out_free_ff; +if (outentry.nodeid && (invalid_nodeid (outentry.nodeid) || +fuse_invalid_attr (&outentry.attr))) + goto out_free_ff; +fuse_file_free (ff); +return fuse_open_atomic_found (dir, entry, file, &outentry, + forget, epoch, attr_version, + evict_ctr); + } +if (!S_ISREG (outentry.attr.mode) ||invalid_nodeid (outentry.nodeid) || -fuse_invalid_attr (&outentry.attr)) +fuse_invalid_attr (&outentry.attr) || + args.out_args[1 ].size <FUSE_COMPAT_OPEN_OUT_SIZE ) goto out_free_ff; + created = !atomic || (outopenp->open_flags &FOPEN_CREATED ); +if (atomic) { +/* Only O_CREAT creates; O_TRUNC opens are left to the VFS */ +if ((created && !create) || (!created && trunc)) + goto out_free_ff; +if (created) + file->f_mode |=FMODE_CREATED ; + } + ff->fh = outopenp->fh; 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), + created ?0 : attr_version, created ?0 : evict_ctr);if (!inode) { flags &= ~(O_CREAT |O_EXCL |O_TRUNC );fuse_sync_release (NULL , ff, flags);
@@ -907,10 +984,14 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, goto out_err; }kfree (forget); -d_instantiate (entry, inode); +if (opcode ==FUSE_TMPFILE ) +d_instantiate (entry, inode); +else +d_splice_alias (inode, entry);fuse_dentry_set_epoch (entry, epoch);fuse_change_entry_timeout (entry, &outentry); -fuse_dir_changed (dir); +if (created) +fuse_dir_changed (dir); err =generic_file_open (inode, file);if (!err) { file->private_data = ff;
@@ -948,6 +1029,16 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,if (fuse_is_bad (dir))return -EIO ; +if (!fc->no_open_atomic && (d_in_lookup (entry) || (flags &O_CREAT ))) { + err =fuse_create_open (idmap, dir, entry, file, flags, + mode |S_IFREG ,FUSE_OPEN_ATOMIC ); +if (err == -EEXIST ) +fuse_invalidate_entry (entry); +if (err != -ENOSYS ) +return err; + fc->no_open_atomic =1 ; + } +if (d_in_lookup (entry)) {struct dentry *res =fuse_lookup (dir, entry,0 );if (res ||d_really_is_positive (entry))
fs/fuse/fuse_i.h +6 -0
@@ -50,6 +50,9 @@/** Number of dentries for each connection in the control filesystem */ #define FUSE_CTL_NUM_DENTRIES 5 +/** Size of fuse_open_out without backing_id_64 */ +#define FUSE_COMPAT_OPEN_OUT_SIZE offsetofend(struct fuse_open_out, backing_id) +/* * Dentries invalidation workqueue period, in seconds. The value of this * parameter shall be >= FUSE_DENTRY_INVAL_FREQ_MIN seconds, or 0 (zero), in
@@ -617,6 +620,9 @@ struct fuse_conn {/** @no_create: Is create not implemented by fs? */ unsigned no_create:1; +/** @no_open_atomic: Is open atomic not implemented by fs? */ + unsigned no_open_atomic:1; +/** @no_bmap: Is bmap not implemented by fs? */ unsigned no_bmap:1;
include/uapi/linux/fuse.h +7 -1
@@ -257,6 +257,9 @@* - add backing_id_64 to fuse_open_out * - add FUSE_NOTIFY_BACKING_MAP, fuse_notify_backing_map_out, fuse_extent * - add FUSE_BACKING_MAP_CREATE, FUSE_BACKING_MAP_CYCLIC +* +* 7.48 +* - add FUSE_OPEN_ATOMIC and FOPEN_CREATED */ #ifndef _LINUX_FUSE_H
@@ -292,7 +295,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 47 +#define FUSE_KERNEL_MINOR_VERSION 48/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -406,6 +409,7 @@ struct fuse_file_lock {* (FUSE_URING_ZERO_COPY) and the request carries page * payload. Otherwise reads/writes fall back to * copying. +* FOPEN_CREATED: FUSE_OPEN_ATOMIC created the file */ #define FOPEN_DIRECT_IO (1 << 0)#define FOPEN_KEEP_CACHE (1 << 1)
@@ -416,6 +420,7 @@ struct fuse_file_lock {#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)#define FOPEN_PASSTHROUGH (1 << 7)#define FOPEN_IO_URING_ZERO_COPY (1 << 8) +#define FOPEN_CREATED (1 << 9)/* * INIT request/reply flags
@@ -698,6 +703,7 @@ enum fuse_opcode {FUSE_TMPFILE =51 ,FUSE_STATX =52 ,FUSE_COPY_FILE_RANGE_64 =53 , +FUSE_OPEN_ATOMIC =54 ,/* CUSE specific operations */ CUSE_INIT = 4096,
Signature · 1 line
2.50.1
PATCH v2 2/3 fuse: open cached files with FUSE_OPEN_ATOMIC
In reply to Jimmy ZuberWhen the server implements FUSE_OPEN_ATOMIC, skip LOOKUP for a regular file being opened, opening it by name from fuse_open() instead. If the name now refers to a different file or to nothing, drop the dentry and return -EOPENSTALE, so that the VFS looks the name up again. A matching reply refreshes the attributes and the entry timeout.
If the server replies -ENOSYS, fuse_open() sends the skipped LOOKUP itself.
--- fs/fuse/dir.c | 247 ++++++++++++++++++++++++++++++++++++++--------- fs/fuse/file.c | 4 +- fs/fuse/fuse_i.h | 1 + 3 files changed, 208 insertions(+), 44 deletions(-)
fs/fuse/dir.c +204 -43
@@ -379,6 +379,60 @@ static void fuse_lookup_init(struct fuse_args *args, u64 nodeid, args->out_args[0 ].value = outarg; } +/* +* Look the name of @entry up again. Returns 1 if it still refers to the +* inode of @entry, refreshing its attributes and entry timeout, 0 if it does +* not, or -ENOMEM / -EINTR. +*/ +static int fuse_revalidate_lookup (struct inode *dir,const struct qstr *name, +struct dentry *entry) +{ +struct inode *inode =d_inode (entry); +struct fuse_mount *fm =get_fuse_mount (inode); +struct fuse_inode *fi =get_fuse_inode (inode); +struct fuse_entry_out outarg; +FUSE_ARGS (args); +struct fuse_forget_link *forget; +u64 attr_version; +int ret; + + forget =fuse_alloc_forget (); +if (!forget) +return -ENOMEM ; + + attr_version =fuse_get_attr_version (fm->fc); + +fuse_lookup_init (&args,get_node_id (dir), name, &outarg); + ret =fuse_simple_request (fm, &args); +/* Zero nodeid is same as -ENOENT */ +if (!ret && !outarg.nodeid) + ret = -ENOENT ; +if (!ret) { +if (outarg.nodeid !=get_node_id (inode) || + (bool )IS_AUTOMOUNT (inode) != (bool ) (outarg.attr.flags &FUSE_ATTR_SUBMOUNT )) { +fuse_chan_queue_forget (fm->fc->chan, forget, + outarg.nodeid,1 ); +return 0 ; + } +spin_lock (&fi->lock); + fi->nlookup++; +spin_unlock (&fi->lock); + } +kfree (forget); +if (ret == -ENOMEM || ret == -EINTR ) +return ret; +if (ret ||fuse_invalid_attr (&outarg.attr) || +fuse_stale_inode (inode, outarg.generation, &outarg.attr)) +return 0 ; + +forget_all_cached_acls (inode); +fuse_change_attributes (inode, &outarg.attr,NULL , +ATTR_TIMEOUT (&outarg), + attr_version); +fuse_change_entry_timeout (entry, &outarg); +return 1 ; +} +/* * Check whether the dentry is still valid *
@@ -392,7 +446,6 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name, struct dentry *entry, unsigned int flags) {struct inode *inode; -struct fuse_mount *fm;struct fuse_conn *fc;struct fuse_inode *fi;struct fuse_dentry *fd = entry->d_fsdata;
@@ -407,57 +460,24 @@ 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; -FUSE_ARGS (args); -struct fuse_forget_link *forget; -u64 attr_version; -/* For negative dentries, always do a fresh lookup */ if (!inode) goto invalid; +/* fuse_open_revalidate() checks the name of a file it opens */ +if (!fc->no_open_atomic && (flags &LOOKUP_OPEN ) && + !(flags & (LOOKUP_EXCL |LOOKUP_REVAL | +LOOKUP_RENAME_TARGET )) && +S_ISREG (inode->i_mode) && !d_mountpoint (entry)) + goto valid; + ret = -ECHILD ;if (flags &LOOKUP_RCU ) goto out; - fm =get_fuse_mount (inode); - - forget =fuse_alloc_forget (); - ret = -ENOMEM ; -if (!forget) - goto out; - - attr_version =fuse_get_attr_version (fm->fc); - -fuse_lookup_init (&args,get_node_id (dir), name, &outarg); - ret =fuse_simple_request (fm, &args); -/* Zero nodeid is same as -ENOENT */ -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 )) { -fuse_chan_queue_forget (fm->fc->chan, forget, - outarg.nodeid,1 ); - goto invalid; - } -spin_lock (&fi->lock); - fi->nlookup++; -spin_unlock (&fi->lock); - } -kfree (forget); -if (ret == -ENOMEM || ret == -EINTR ) + ret =fuse_revalidate_lookup (dir, name, entry); +if (ret <=0 ) goto out; -if (ret ||fuse_invalid_attr (&outarg.attr) || -fuse_stale_inode (inode, outarg.generation, &outarg.attr)) - goto invalid; - -forget_all_cached_acls (inode); -fuse_change_attributes (inode, &outarg.attr,NULL , -ATTR_TIMEOUT (&outarg), - attr_version); -fuse_change_entry_timeout (entry, &outarg); } else if (inode) { fi =get_fuse_inode (inode);if (flags &LOOKUP_RCU ) {
@@ -467,6 +487,7 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,fuse_advise_use_readdirplus (dir); } } +valid: ret =1 ; out:return ret;
@@ -1016,6 +1037,146 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,return err; } +/* +* Open a regular file whose dentry has expired with FUSE_OPEN_ATOMIC, which +* revalidates the name in the same request. Returns 1 if the file still +* needs FUSE_OPEN, or -EOPENSTALE if the name no longer refers to it. +*/ +int fuse_open_revalidate (struct file *file) +{ +struct dentry *entry = file->f_path.dentry; +struct inode *inode =d_inode (entry); +struct fuse_inode *fi =get_fuse_inode (inode); +struct fuse_mount *fm =get_fuse_mount (inode); +struct fuse_conn *fc = fm->fc; +FUSE_ARGS (args); +struct fuse_forget_link *forget; +struct fuse_create_in inarg; +struct fuse_entry_out outentry; +struct fuse_open_out *outopenp; +struct name_snapshot name; +struct dentry *parent; +struct fuse_file *ff; +u64 attr_version; +int err; + +if (fc->no_open_atomic ||IS_ROOT (entry) || !S_ISREG (inode->i_mode) || + !time_before64 (fuse_dentry_time (entry),get_jiffies_64 ())) +return 1 ; + + forget =fuse_alloc_forget (); +if (!forget) +return -ENOMEM ; + ff =fuse_file_alloc (fm, true); +if (!ff) { +kfree (forget); +return -ENOMEM ; + } + +memset (&inarg,0 ,sizeof (inarg)); +memset (&outentry,0 ,sizeof (outentry)); + inarg.flags = file->f_flags & ~(O_CREAT |O_EXCL |O_NOCTTY ); + inarg.mode =S_IFREG ; + parent =dget_parent (entry); +take_dentry_name_snapshot (&name, entry); + args.opcode =FUSE_OPEN_ATOMIC ; + args.nodeid =get_node_id (d_inode (parent)); + args.in_numargs =2 ; + args.in_args[0 ].size =sizeof (inarg); + args.in_args[0 ].value = &inarg; + args.in_args[1 ].size = name.name.len +1 ; + args.in_args[1 ].value = name.name.name; + args.out_numargs =2 ; + args.out_args[0 ].size =sizeof (outentry); + args.out_args[0 ].value = &outentry; + outopenp = &ff->args->open_outarg; + args.out_args[1 ].size =sizeof (*outopenp); + args.out_args[1 ].value = outopenp; + args.out_argvar = true; + + attr_version =fuse_get_attr_version (fc); + err =fuse_simple_request (fm, &args); +if (err == -ENOSYS ) { +/* d_revalidate() skipped the LOOKUP, so send it here */ + fc->no_open_atomic =1 ; + err =fuse_revalidate_lookup (d_inode (parent), &name.name, + entry); +if (!err) { +d_drop (entry); + err = -EOPENSTALE ; + } +release_dentry_name_snapshot (&name); +dput (parent); +fuse_file_free (ff); +kfree (forget); +return err; + } +release_dentry_name_snapshot (&name); +dput (parent); + +if (err == -ENOENT ) { +d_drop (entry); + err = -EOPENSTALE ; + } +if (err <0 ) + goto out_free; + +if (args.out_args[1 ].size) { + ff->fh = outopenp->fh; + ff->nodeid = outentry.nodeid; + ff->open_flags = outopenp->open_flags; + } + +/* The retry looks the name up again */ + err = -EOPENSTALE ; +if (outentry.nodeid !=get_node_id (inode) || +fuse_invalid_attr (&outentry.attr) || +fuse_stale_inode (inode, outentry.generation, &outentry.attr)) { +d_drop (entry); + goto out_release; + } + +/* Only O_CREAT creates; O_TRUNC leaves the file unopened */ + err = -EIO ; +if (args.out_args[1 ].size && + (args.out_args[1 ].size <FUSE_COMPAT_OPEN_OUT_SIZE || + (outopenp->open_flags &FOPEN_CREATED ) || + (file->f_flags &O_TRUNC ))) + goto out_release; + +spin_lock (&fi->lock); + fi->nlookup++; +spin_unlock (&fi->lock); +kfree (forget); +forget_all_cached_acls (inode); +fuse_change_attributes (inode, &outentry.attr,NULL , +ATTR_TIMEOUT (&outentry), attr_version); +fuse_change_entry_timeout (entry, &outentry); + +if (!args.out_args[1 ].size) { +fuse_file_free (ff); +return 1 ; + } + file->private_data = ff; +return 0 ; + +out_release: +if (outentry.nodeid) +fuse_chan_queue_forget (fc->chan, forget, outentry.nodeid,1 ); +else +kfree (forget); +if (args.out_args[1 ].size) +fuse_sync_release (NULL , ff, file->f_flags); +else +fuse_file_free (ff); +return err; + +out_free: +fuse_file_free (ff); +kfree (forget); +return err; +} +static int fuse_mknod (struct mnt_idmap *,struct inode *,struct dentry *,umode_t ,dev_t ); static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
fs/fuse/file.c +3 -1
@@ -286,7 +286,9 @@ static int fuse_open(struct inode *inode, struct file *file)if (is_wb_truncate || vdax_truncate)fuse_set_nowrite (inode); - err =fuse_do_open (fm,get_node_id (inode), file, false); + err =fuse_open_revalidate (file); +if (err >0 ) + err =fuse_do_open (fm,get_node_id (inode), file, false);if (!err) { ff = file->private_data; err =fuse_finish_open (inode, file);
fs/fuse/fuse_i.h +1 -0
@@ -994,6 +994,7 @@ void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,struct fuse_file *fuse_file_alloc (struct fuse_mount *fm,bool release);void fuse_file_free (struct fuse_file *ff);int fuse_finish_open (struct inode *inode,struct file *file); +int fuse_open_revalidate (struct file *file);void fuse_sync_release (struct fuse_inode *fi,struct fuse_file *ff,unsigned int flags);
Signature · 1 line
2.50.1
PATCH v2 3/3 selftests/fuse: add test for FUSE_OPEN_ATOMIC
In reply to Jimmy ZuberCheck the requests sent when opening and creating new, existing, missing and expired names, against a raw /dev/fuse server with and without FUSE_OPEN_ATOMIC, that opening an existing read-only file is still permission checked, that an O_TMPFILE file has no name in its directory, and that a fuse_open_out without backing_id_64 is accepted.
--- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 3 +- .../filesystems/fuse/atomic_open_test.c | 518 ++++++++++++++++++ 3 files changed, 521 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/filesystems/fuse/atomic_open_test.c
tools/testing/selftests/filesystems/fuse/.gitignore +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +atomic_open_test fuse_mnt fusectl_test test_syncfs
tools/testing/selftests/filesystems/fuse/Makefile +2 -1
@@ -3,7 +3,7 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) TEST_GEN_PROGS := fusectl_test test_syncfs -TEST_GEN_PROGS += write_extend_eof_test +TEST_GEN_PROGS += write_extend_eof_test atomic_open_test TEST_GEN_PROGS += fuse_acl_cache_test TEST_GEN_PROGS += fuse_symlink_cache_test TEST_GEN_PROGS += fuse_readdir_cache_test
@@ -12,6 +12,7 @@ TEST_GEN_FILES := fuse_mnt include ../../lib.mk $(OUTPUT)/write_extend_eof_test: LDLIBS += -lpthread +$(OUTPUT)/atomic_open_test: LDLIBS += -lpthread VAR_CFLAGS := $(shell pkg-config fuse3 --cflags 2>/dev/null) ifeq ($(VAR_CFLAGS),)
tools/testing/selftests/filesystems/fuse/atomic_open_test.c new file +518 -0
518 lines not on this page · raw message
Signature · 1 line
2.50.1
Quoted 11 lines · Jimmy Zuber
From: jamz <[email protected]>
Add
FUSE_OPEN_ATOMIC, allowing the kernel to skip LOOKUP to improve performance. A server implementingFUSE_OPEN_ATOMICwill look up the name, create it ifO_CREATis supplied, and open it in one request.The reply says whether the file was created, as Miklos suggested in [1]. The overall pattern follows his sketch in [2]. For a cached name, the kernel compares the returned nodeid with the cached one and looks the name up again on a mismatch.
Quoted 4 lines
A server without
FUSE_OPEN_ATOMICreplies-ENOSYSand keeps today's behaviour.Tested with a new selftest under UML and KVM.
Hi Jimmy, I will try to review today or tomorrow. Did you see the Sashiko reports?
Thanks,
Bernd
Quoted 37 lines
Changes in v2:
- Drop thed_drop()befored_splice_alias()for an entry-only reply, and used_splice_alias()forFUSE_CREATEandFUSE_OPEN_ATOMICreplies.FUSE_TMPFILEkeepsd_instantiate(), as its dentry stays unhashed (NeilBrown).
- Describe what the server does and when the kernel checks permission in each case (NeilBrown).
- Check in the selftest that anO_TMPFILEfile has no name in its directory.
- Rebase onto fuse for-next, which hasf1ac607f786f("VFS: enhanced_splice_alias()to handle hashed dentries"). Accept afuse_open_outwithoutbacking_id_64, asFUSE_CREATEandFUSE_OPENnow do, and test it.v1: https://lore.kernel.org/fuse-devel/[email protected]/
[1] https://lore.kernel.org/all/CAJfpeguEK4JsFo60=yHkpLL6XkDGS7cQ5GOhiFL379KsYk0TsQ@mail.gmail.com/
[2] https://lore.kernel.org/all/CAJfpegvXtXY=Pbxv+dMGFR8mvWN0DUwhSo6NwaVexk6Y6sao+w@mail.gmail.com/Jimmy Zuber (3):
fuse: addFUSE_OPEN_ATOMIC
fuse: open cached files withFUSE_OPEN_ATOMIC
selftests/fuse: add test forFUSE_OPEN_ATOMICfs/fuse/dir.c | 354 ++++++++++-- fs/fuse/file.c | 4 +- fs/fuse/fuse_i.h | 7 + include/uapi/linux/fuse.h | 8 +- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 3 +- .../filesystems/fuse/atomic_open_test.c | 518 ++++++++++++++++++ 7 files changed, 841 insertions(+), 54 deletions(-) create mode 100644 tools/testing/selftests/filesystems/fuse/atomic_open_test.cbase-commit:
9b1da7b4a4e197072e630c3b85d4100a399752ff
Quoted 2 lines · Bernd Schubert
Hi Jimmy, I will try to review today or tomorrow. Did you see the Sashiko reports?
Thank you for the pointer to Sashiko - I've addressed its feedback in v3: