Skip to contentSkip to conversation

FUSE: Implement full atomic open

PATCH Superseded Bernd Schubert 3 participants 5 messages Jul 7, 2023 – Aug 8, 2023

Subsystems (2)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover FUSE: Implement full atomic open

In FUSE, as of now, uncached lookups are expensive over the wire. E.g additional latencies and stressing (meta data) servers from thousands of clients. With atomic-open lookup before open can be avoided.

Here is the link to performance numbers
https://lore.kernel.org/linux-fsdevel/[email protected]/

Here is the libfuse pull request
https://github.com/libfuse/libfuse/pull/813

The patches are passing passthrough_hp xfstests (libfuse part applied), although we had to introduce umount retries into xfstests, as recent kernels/xfstests fail umount in some tests with
EBUSY - independent of atomic open.

v6: Addressed Miklos comments and rewrote atomic open into its own
function and fuse opcode.
Dropped for now is the revalidate optimization, we
have the code/patch, but it needs more testing. Also easier to first agree on atomic open and then to land the next optimization.

v5: Addressed comments

v3: Addressed comments

v4: Addressed all comments and refactored the code into 3 separate patches
respectively for Atomic create, Atomic open, optimizing lookup in d_revalidate().

v3: handle review comments

v2: fixed a memory leak in <fuse_atomic_open_common>

Bernd Schubert (1):
fuse: rename fuse_create_open

Dharmendra Singh (1):
fuse: introduce atomic open

 fs/fuse/dir.c             | 176 +++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_i.h          |   3 +
 include/uapi/linux/fuse.h |   3 +
 3 files changed, 178 insertions(+), 4 deletions(-)
Signature · 1 line
2.37.2
#1 lore raw

PATCH v6 1/2 fuse: rename fuse_create_open

Just preparation work for atomic open.

---
 fs/fuse/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/fuse/dir.c +3 -3
index 35bc174f9ba2..6ffc573de470 100644
@@ -613,7 +613,7 @@ static void free_ext_value(struct fuse_args *args)
  * If the filesystem doesn't support this, then fall back to separate
  * 'mknod' + 'open' requests.
  */
-static int fuse_create_open(struct inode *dir, struct dentry *entry,
+static int _fuse_create_open(struct inode *dir, struct dentry *entry,
 			    struct file *file, unsigned int flags,
 			    umode_t mode, u32 opcode)
 {
@@ -753,7 +753,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
 	if (fc->no_create)
 		goto mknod;
 
-	err = fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE);
+	err = _fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE);
 	if (err == -ENOSYS) {
 		fc->no_create = 1;
 		goto mknod;
@@ -879,7 +879,7 @@ static int fuse_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
 	if (fc->no_tmpfile)
 		return -EOPNOTSUPP;
 
-	err = fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE);
+	err = _fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE);
 	if (err == -ENOSYS) {
 		fc->no_tmpfile = 1;
 		err = -EOPNOTSUPP;
Signature · 1 line
2.37.2
#2 lore raw

PATCH v6 2/2 fuse: introduce atomic open

In reply to Bernd Schubert

From: Dharmendra Singh <[email protected]>

This adds full atomic open support, to avoid lookup before open/create. If the implementation (fuse server/daemon) does not support atomic open it falls back to non-atomic open.

---
 fs/fuse/dir.c             | 170 +++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_i.h          |   3 +
 include/uapi/linux/fuse.h |   3 +
 3 files changed, 175 insertions(+), 1 deletion(-)
fs/fuse/dir.c +169 -1
index 6ffc573de470..8145bbfc7a40 100644
@@ -724,7 +724,7 @@ static int _fuse_create_open(struct inode *dir, struct dentry *entry,
 
 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,
+static int fuse_create_open(struct inode *dir, struct dentry *entry,
 			    struct file *file, unsigned flags,
 			    umode_t mode)
 {
@@ -770,6 +770,174 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
 	return finish_no_open(file, res);
 }
 
+static int _fuse_atomic_open(struct inode *dir, struct dentry *entry,
+			    struct file *file, unsigned flags,
+			    umode_t mode)
+{
+
+	int err;
+	struct inode *inode;
+	struct fuse_mount *fm = get_fuse_mount(dir);
+	struct fuse_conn *fc = fm->fc;
+	FUSE_ARGS(args);
+	struct fuse_forget_link *forget;
+	struct fuse_create_in inarg;
+	struct fuse_open_out outopen;
+	struct fuse_entry_out outentry;
+	struct fuse_inode *fi;
+	struct fuse_file *ff;
+	struct dentry *res = NULL;
+
+	/* Userspace expects S_IFREG in create mode */
+	if ((flags & O_CREAT) && (mode & S_IFMT) != S_IFREG) {
+		WARN_ON(1);
+		err = -EINVAL;
+		goto out_err;
+	}
+	forget = fuse_alloc_forget();
+	err = -ENOMEM;
+	if (!forget)
+		goto out_err;
+
+	err = -ENOMEM;
+	ff = fuse_file_alloc(fm);
+	if (!ff)
+		goto out_put_forget_req;
+
+	if (!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();
+
+	if (fc->handle_killpriv_v2 && (flags & O_TRUNC) &&
+	    !(flags & O_EXCL) && !capable(CAP_FSETID)) {
+		inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
+	}
+
+	args.opcode = FUSE_OPEN_ATOMIC;
+	args.nodeid = get_node_id(dir);
+	args.in_numargs = 2;
+	args.in_args[0].size = sizeof(inarg);
+	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;
+	args.out_numargs = 2;
+	args.out_args[0].size = sizeof(outentry);
+	args.out_args[0].value = &outentry;
+	args.out_args[1].size = sizeof(outopen);
+	args.out_args[1].value = &outopen;
+
+	if (flags & O_CREAT) {
+		err = get_create_ext(&args, dir, entry, mode);
+		if (err)
+			goto out_free_ff;
+	}
+
+	err = fuse_simple_request(fm, &args);
+	if (err == -ENOSYS) {
+		fc->no_open_atomic = 1;
+		fuse_file_free(ff);
+		kfree(forget);
+		goto fallback;
+	}
+	if (err) {
+		if (err == -ENOENT)
+			fuse_invalidate_entry_cache(entry);
+		goto out_free_ff;
+	}
+
+	err = -EIO;
+	if (invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr))
+		goto out_free_ff;
+
+	ff->fh = outopen.fh;
+	ff->nodeid = outentry.nodeid;
+	ff->open_flags = outopen.open_flags;
+	inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
+			  &outentry.attr, entry_attr_timeout(&outentry), 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);
+		err = -ENOMEM;
+		goto out_err;
+	}
+	if (d_in_lookup(entry)) {
+		res = d_splice_alias(inode, entry);
+		if (res) {
+			if (IS_ERR(res)) {
+				/*
+				 * Close the file in user space, but do not unlink it,
+				 * if it was created - with network file systems other
+				 * clients might have already accessed it.
+				 */
+				fi = get_fuse_inode(inode);
+				fuse_sync_release(fi, ff, flags);
+				fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
+				err = PTR_ERR(res);
+				goto out_err;
+			}
+			entry = res;
+		}
+	} else
+		d_instantiate(entry, inode);
+	fuse_change_entry_timeout(entry, &outentry);
+
+	if (outopen.open_flags & FOPEN_FILE_CREATED) {
+		if (!(flags & O_CREAT)) {
+			pr_debug("Server side bug, FOPEN_FILE_CREATED set "
+				 "without O_CREAT, ignoring.");
+		} else {
+			/* This should be always set when the file is created */
+			fuse_dir_changed(dir);
+			file->f_mode |= FMODE_CREATED;
+		}
+	}
+
+	if (!(flags & O_CREAT))
+		fuse_advise_use_readdirplus(dir);
+	if (S_ISDIR(mode))
+		ff->open_flags &= ~FOPEN_DIRECT_IO;
+	err = finish_open(file, entry, generic_file_open);
+	if (err) {
+		fi = get_fuse_inode(inode);
+		fuse_sync_release(fi, ff, flags);
+	} else {
+		file->private_data = ff;
+		fuse_finish_open(inode, file);
+	}
+	kfree(forget);
+	dput(res);
+	return err;
+
+out_free_ff:
+	fuse_file_free(ff);
+out_put_forget_req:
+	kfree(forget);
+out_err:
+	return err;
+
+fallback:
+	return fuse_create_open(dir, entry, file, flags, mode);
+}
+
+static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
+			    struct file *file, unsigned flags,
+			    umode_t mode)
+{
+	struct fuse_conn *fc = get_fuse_conn(dir);
+
+	if (fc->no_open_atomic)
+		return fuse_create_open(dir, entry, file, flags, mode);
+	else
+		return _fuse_atomic_open(dir, entry, file, flags, mode);
+}
+
 /*
  * Code shared between mknod, mkdir, symlink and link
  */
fs/fuse/fuse_i.h +3 -0
index 9b7fc7d3c7f1..4e2ebcc28912 100644
@@ -672,6 +672,9 @@ struct fuse_conn {
 	/** Is open/release not implemented by fs? */
 	unsigned no_open:1;
 
+	/** Is open atomic not impelmented by fs? */
+	unsigned no_open_atomic:1;
+
 	/** Is opendir/releasedir not implemented by fs? */
 	unsigned no_opendir:1;
 
include/uapi/linux/fuse.h +3 -0
index 1b9d0dfae72d..ee36263c0f3a 100644
@@ -314,6 +314,7 @@ struct fuse_file_lock {
  * FOPEN_STREAM: the file is stream-like (no file position at all)
  * FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE)
  * FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode
+ * FOPEN_FILE_CREATED: the file was indeed created
  */
 #define FOPEN_DIRECT_IO		(1 << 0)
 #define FOPEN_KEEP_CACHE	(1 << 1)
@@ -322,6 +323,7 @@ struct fuse_file_lock {
 #define FOPEN_STREAM		(1 << 4)
 #define FOPEN_NOFLUSH		(1 << 5)
 #define FOPEN_PARALLEL_DIRECT_WRITES	(1 << 6)
+#define FOPEN_FILE_CREATED	(1 << 7)
 
 /**
  * INIT request/reply flags
@@ -572,6 +574,7 @@ enum fuse_opcode {
 	FUSE_REMOVEMAPPING	= 49,
 	FUSE_SYNCFS		= 50,
 	FUSE_TMPFILE		= 51,
+	FUSE_OPEN_ATOMIC	= 52,
 
 	/* CUSE specific operations */
 	CUSE_INIT		= 4096,
Signature · 1 line
2.37.2
maintainer
#3 lore raw

Re: [PATCH 2/2] fuse: introduce atomic open

Quoted 92 lines · Bernd Schubert

From: Dharmendra Singh <[email protected]>

This adds full atomic open support, to avoid lookup before open/create. If the implementation (fuse server/daemon) does not support atomic open it falls back to non-atomic open.

---
 fs/fuse/dir.c             | 170 +++++++++++++++++++++++++++++++++++++-
 fs/fuse/fuse_i.h          |   3 +
 include/uapi/linux/fuse.h |   3 +
 3 files changed, 175 insertions(+), 1 deletion(-)
fs/fuse/dir.c +60 -1
index 6ffc573de470..8145bbfc7a40 100644
@@ -724,7 +724,7 @@ static int _fuse_create_open(struct inode *dir, struct dentry *entry,
 
 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,
+static int fuse_create_open(struct inode *dir, struct dentry *entry,
                            struct file *file, unsigned flags,
                            umode_t mode)
 {
@@ -770,6 +770,174 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
        return finish_no_open(file, res);
 }
 
+static int _fuse_atomic_open(struct inode *dir, struct dentry *entry,
+                           struct file *file, unsigned flags,
+                           umode_t mode)
+{
+
+       int err;
+       struct inode *inode;
+       struct fuse_mount *fm = get_fuse_mount(dir);
+       struct fuse_conn *fc = fm->fc;
+       FUSE_ARGS(args);
+       struct fuse_forget_link *forget;
+       struct fuse_create_in inarg;
+       struct fuse_open_out outopen;
+       struct fuse_entry_out outentry;
+       struct fuse_inode *fi;
+       struct fuse_file *ff;
+       struct dentry *res = NULL;
+
+       /* Userspace expects S_IFREG in create mode */
+       if ((flags & O_CREAT) && (mode & S_IFMT) != S_IFREG) {
+               WARN_ON(1);
+               err = -EINVAL;
+               goto out_err;
+       }
+       forget = fuse_alloc_forget();
+       err = -ENOMEM;
+       if (!forget)
+               goto out_err;
+
+       err = -ENOMEM;
+       ff = fuse_file_alloc(fm);
+       if (!ff)
+               goto out_put_forget_req;
+
+       if (!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();
+
+       if (fc->handle_killpriv_v2 && (flags & O_TRUNC) &&
+           !(flags & O_EXCL) && !capable(CAP_FSETID)) {
+               inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
+       }
+
+       args.opcode = FUSE_OPEN_ATOMIC;
+       args.nodeid = get_node_id(dir);
+       args.in_numargs = 2;
+       args.in_args[0].size = sizeof(inarg);
+       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;
+       args.out_numargs = 2;
+       args.out_args[0].size = sizeof(outentry);
+       args.out_args[0].value = &outentry;

fs/fuse/dir.c static int fuse_atomic_open(struct inode *dir, struct dentry *entry, · line 841

Quoted 10 lines
fs/fuse/dir.c +10 -0
+       args.out_args[1].size = sizeof(outopen);
+       args.out_args[1].value = &outopen;
+
+       if (flags & O_CREAT) {
+               err = get_create_ext(&args, dir, entry, mode);
+               if (err)
+                       goto out_free_ff;
+       }
+
+       err = fuse_simple_request(fm, &args);

free_ext_value() missing.

Which also begs the question: can't _fuse_create_open() and _fuse_atomic_open() be consolidated into a common helper? There's just too much duplication between them to warrant completely separate implementations.

Quoted 52 lines
fs/fuse/dir.c +52 -0
+       if (err == -ENOSYS) {
+               fc->no_open_atomic = 1;
+               fuse_file_free(ff);
+               kfree(forget);
+               goto fallback;
+       }
+       if (err) {
+               if (err == -ENOENT)
+                       fuse_invalidate_entry_cache(entry);
+               goto out_free_ff;
+       }
+
+       err = -EIO;
+       if (invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr))
+               goto out_free_ff;
+
+       ff->fh = outopen.fh;
+       ff->nodeid = outentry.nodeid;
+       ff->open_flags = outopen.open_flags;
+       inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
+                         &outentry.attr, entry_attr_timeout(&outentry), 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);
+               err = -ENOMEM;
+               goto out_err;
+       }
+       if (d_in_lookup(entry)) {
+               res = d_splice_alias(inode, entry);
+               if (res) {
+                       if (IS_ERR(res)) {
+                               /*
+                                * Close the file in user space, but do not unlink it,
+                                * if it was created - with network file systems other
+                                * clients might have already accessed it.
+                                */
+                               fi = get_fuse_inode(inode);
+                               fuse_sync_release(fi, ff, flags);
+                               fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
+                               err = PTR_ERR(res);
+                               goto out_err;
+                       }
+                       entry = res;
+               }
+       } else
+               d_instantiate(entry, inode);
+       fuse_change_entry_timeout(entry, &outentry);
+
+       if (outopen.open_flags & FOPEN_FILE_CREATED) {
+               if (!(flags & O_CREAT)) {
+                       pr_debug("Server side bug, FOPEN_FILE_CREATED set "

fs/fuse/dir.c static int fuse_atomic_open(struct inode *dir, struct dentry *entry, · line 903

Quoted 10 lines
fs/fuse/dir.c +10 -0
+                                "without O_CREAT, ignoring.");
+               } else {
+                       /* This should be always set when the file is created */
+                       fuse_dir_changed(dir);
+                       file->f_mode |= FMODE_CREATED;
+               }
+       }
+
+       if (!(flags & O_CREAT))
+               fuse_advise_use_readdirplus(dir);

We advise to use readdirplus from lookup, because readdirplus can substitute for a lookup. But readdirplus cannot substitute for the atomic open, so it's not a good idea to advise using readdirpuls in this case. At least that's how I see this.

Thanks,
Miklos

#4 lore raw

Re: [PATCH 2/2] fuse: introduce atomic open

Quoted 106 lines · Miklos Szeredi
Quoted 92 lines · Bernd Schubert

From: Dharmendra Singh <[email protected]>

This adds full atomic open support, to avoid lookup before open/create. If the implementation (fuse server/daemon) does not support atomic open it falls back to non-atomic open.

---
  fs/fuse/dir.c             | 170 +++++++++++++++++++++++++++++++++++++-
  fs/fuse/fuse_i.h          |   3 +
  include/uapi/linux/fuse.h |   3 +
  3 files changed, 175 insertions(+), 1 deletion(-)
fs/fuse/dir.c +60 -1
index 6ffc573de470..8145bbfc7a40 100644
@@ -724,7 +724,7 @@ static int _fuse_create_open(struct inode *dir, struct dentry *entry,
 
  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,
+static int fuse_create_open(struct inode *dir, struct dentry *entry,
                             struct file *file, unsigned flags,
                             umode_t mode)
  {
@@ -770,6 +770,174 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
         return finish_no_open(file, res);
  }
 
+static int _fuse_atomic_open(struct inode *dir, struct dentry *entry,
+                           struct file *file, unsigned flags,
+                           umode_t mode)
+{
+
+       int err;
+       struct inode *inode;
+       struct fuse_mount *fm = get_fuse_mount(dir);
+       struct fuse_conn *fc = fm->fc;
+       FUSE_ARGS(args);
+       struct fuse_forget_link *forget;
+       struct fuse_create_in inarg;
+       struct fuse_open_out outopen;
+       struct fuse_entry_out outentry;
+       struct fuse_inode *fi;
+       struct fuse_file *ff;
+       struct dentry *res = NULL;
+
+       /* Userspace expects S_IFREG in create mode */
+       if ((flags & O_CREAT) && (mode & S_IFMT) != S_IFREG) {
+               WARN_ON(1);
+               err = -EINVAL;
+               goto out_err;
+       }
+       forget = fuse_alloc_forget();
+       err = -ENOMEM;
+       if (!forget)
+               goto out_err;
+
+       err = -ENOMEM;
+       ff = fuse_file_alloc(fm);
+       if (!ff)
+               goto out_put_forget_req;
+
+       if (!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();
+
+       if (fc->handle_killpriv_v2 && (flags & O_TRUNC) &&
+           !(flags & O_EXCL) && !capable(CAP_FSETID)) {
+               inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
+       }
+
+       args.opcode = FUSE_OPEN_ATOMIC;
+       args.nodeid = get_node_id(dir);
+       args.in_numargs = 2;
+       args.in_args[0].size = sizeof(inarg);
+       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;
+       args.out_numargs = 2;
+       args.out_args[0].size = sizeof(outentry);
+       args.out_args[0].value = &outentry;

fs/fuse/dir.c static int fuse_atomic_open(struct inode *dir, struct dentry *entry, · line 841

Quoted 10 lines
fs/fuse/dir.c +10 -0
+       args.out_args[1].size = sizeof(outopen);
+       args.out_args[1].value = &outopen;
+
+       if (flags & O_CREAT) {
+               err = get_create_ext(&args, dir, entry, mode);
+               if (err)
+                       goto out_free_ff;
+       }
+
+       err = fuse_simple_request(fm, &args);

free_ext_value() missing.

Quoted 4 lines

Which also begs the question: can't _fuse_create_open() and _fuse_atomic_open() be consolidated into a common helper? There's just too much duplication between them to warrant completely separate implementations.

Thanks a lot for your review! I'm going to sent out v7 either today or tomorrow, which also adds in revalidate (which includes a modified version of your vfs patch). v7 also adds in a change similar to commit c94c09535c4debcc439f55b5b6d9ebe57bd4665a (what Al had done for NFS) and revalidate also makes things more complex. I think it now doesn't look that similar to _fuse_create_open anymore. We can then decide if we still want to have a common helper function.

Quoted 60 lines
Quoted 60 lines
fs/fuse/dir.c +59 -0
+       if (err == -ENOSYS) {
+               fc->no_open_atomic = 1;
+               fuse_file_free(ff);
+               kfree(forget);
+               goto fallback;
+       }
+       if (err) {
+               if (err == -ENOENT)
+                       fuse_invalidate_entry_cache(entry);
+               goto out_free_ff;
+       }
+
+       err = -EIO;
+       if (invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr))
+               goto out_free_ff;
+
+       ff->fh = outopen.fh;
+       ff->nodeid = outentry.nodeid;
+       ff->open_flags = outopen.open_flags;
+       inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
+                         &outentry.attr, entry_attr_timeout(&outentry), 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);
+               err = -ENOMEM;
+               goto out_err;
+       }
+       if (d_in_lookup(entry)) {
+               res = d_splice_alias(inode, entry);
+               if (res) {
+                       if (IS_ERR(res)) {
+                               /*
+                                * Close the file in user space, but do not unlink it,
+                                * if it was created - with network file systems other
+                                * clients might have already accessed it.
+                                */
+                               fi = get_fuse_inode(inode);
+                               fuse_sync_release(fi, ff, flags);
+                               fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
+                               err = PTR_ERR(res);
+                               goto out_err;
+                       }
+                       entry = res;
+               }
+       } else
+               d_instantiate(entry, inode);
+       fuse_change_entry_timeout(entry, &outentry);
+
+       if (outopen.open_flags & FOPEN_FILE_CREATED) {
+               if (!(flags & O_CREAT)) {
+                       pr_debug("Server side bug, FOPEN_FILE_CREATED set "
+                                "without O_CREAT, ignoring.");
+               } else {
+                       /* This should be always set when the file is created */
+                       fuse_dir_changed(dir);
+                       file->f_mode |= FMODE_CREATED;
+               }
+       }
Quoted 8 lines

fs/fuse/dir.c static int fuse_atomic_open(struct inode *dir, struct dentry *entry, · line 903

Quoted 3 lines
fs/fuse/dir.c +3 -0
+
+       if (!(flags & O_CREAT))
+               fuse_advise_use_readdirplus(dir);

We advise to use readdirplus from lookup, because readdirplus can substitute for a lookup. But readdirplus cannot substitute for the atomic open, so it's not a good idea to advise using readdirpuls in this case. At least that's how I see this.

Yes thanks, it is a long time since the initial patch version and I *think* it came in here, as lookup is now avoided for open and idea was probably that we thought this advise would not be done anymore. I guess the right code path to set it getattr (which currently still does an additional lookup) and not open. Thanks for spotting it!

Bernd