Re: [PATCH] fuse: skip lookup during atomic_open() when O_CREAT is set

From: Horst Birthelmer

Date: Sat Feb 21 2026 - 10:20:18 EST


Hi Jim,

On Fri, Feb 20, 2026 at 01:41:02PM -0700, Jim Harris wrote:
> From: Jim Harris <jim.harris@xxxxxxxxxx>
>
> When O_CREAT is set, we don't need the lookup. The lookup doesn't
> harm anything, but it's an extra FUSE operation that's not required.
>
> Signed-off-by: Jim Harris <jim.harris@xxxxxxxxxx>
> ---
> fs/fuse/dir.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index f25ee47822ad..35f65d49ed2a 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -895,7 +895,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
> goto out_err;
> }
> kfree(forget);
> - d_instantiate(entry, inode);
> + d_drop(entry);
> + d_splice_alias(inode, entry);
> entry->d_time = epoch;
> fuse_change_entry_timeout(entry, &outentry);
> fuse_dir_changed(dir);
> @@ -936,14 +937,15 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
> if (fuse_is_bad(dir))
> return -EIO;
>
> - if (d_in_lookup(entry)) {
> - struct dentry *res = fuse_lookup(dir, entry, 0);
> - if (res || d_really_is_positive(entry))
> - return finish_no_open(file, res);
> - }
> + if (!(flags & O_CREAT)) {
> + if (d_in_lookup(entry)) {
> + struct dentry *res = fuse_lookup(dir, entry, 0);
>
> - if (!(flags & O_CREAT))
> + if (res || d_really_is_positive(entry))
> + return finish_no_open(file, res);
> + }
> return finish_no_open(file, NULL);
> + }
>
> /* Only creates */
> file->f_mode |= FMODE_CREATED;
> --
> 2.43.0
>
>

I have been looking at that code lately a lot since I was planning to
replace it with a compound.
I'm not entirely convinced that your proposal is the right direction.
I would involve O_EXCL as well, since that lookup could actually
help in that case.

Take a look at what Miklos wrote here:
https://lore.kernel.org/linux-fsdevel/CAJfpegsDxsMsyfP4a_5H1q91xFtwcEdu9-WBnzWKwjUSrPNdmw@xxxxxxxxxxxxxx/

Cheers,
Horst