RFC: removing extra lookup in fuse_atomic_open()
Subsystems (2)
Hi,
I’ve been analyzing FUSE operation counts for various file operations, and noticed that open() with O_CREAT always results in two FUSE operations:FUSE_LOOKUP + FUSE_CREATE. It’s not clear what the FUSE_LOOKUP is accomplishing in this case.
I’ve been running with the patch below successfully, inspired by how the NFS client handles atomic_open() with O_CREAT set.
Is this a suitable optimization to submit? Or are there parts of the FUSE protocol that I’m missing, where certain FUSE devices depend on this extra lookup?
Thanks,
Jim
commit 316b8517982fc3933554c4620513a819d606852f
Author: Jim Harris <[email protected]> Date: Wed Jan 7 19:37:22 2026 -0700
fuse: skip lookup during atomic_open() when O_CREAT is set
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.
fs/fuse/dir.c +9 -8
@@ -702,7 +702,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);
@@ -743,14 +744,14 @@ 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 (!(flags &O_CREAT )) { +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); + }return finish_no_open (file,NULL ); + }/* Only creates */ file->f_mode |=FMODE_CREATED ;