fuse: prepare for VFS locking changes.
Subsystems (2)
cover fuse: prepare for VFS locking changes.
I am working on changes to directory locking. The medium term goal is to lift d_alloc_parallel() locking above i_rwsem, so d_alloc_paralle() can be run unlocked, and consequently cannot be called when ->i_rwsem is held.
The requires:
1/ the d_alloc_parallel() not be called while i_rwsem is held. fuse
does this when priming the dcache from readdir results. A new interface d_alloc_trylock() is now available and can be used instead.
2/ a dentry must not be d_drop()ed while an operation is ongoing, as an
unlocked d_alloc_parallel() would then be able to create a new dentry with the same name. Now that d_splice_alias() is able to splice a hashed alias, create_new_entry() doesn't need to d_drop() any more
The patches depend on patches recently added to the vfs tree. I would prefer these land in that tree too with an Acked-by or similar from fuse maintainers.
Thanks,
NeilBrown
[PATCH 1/2] fuse: don't d_drop() before d_splice_alias() [PATCH 2/2] fuse: Use d_alloc_trylock() in fuse_direntplus_link()
PATCH 1/2 fuse: don't d_drop() before d_splice_alias()
From: NeilBrown <[email protected]>
create_new_entry() is used to finalise the creation of various objects (mknod, mkdir, symlink etc).
It currently uses d_drop() which will be a problem for a proposed new locking scheme.
d_splice_alias() now works on hashed dentries so the d_drop() isn't needed. Drop it.
--- fs/fuse/dir.c | 1 - 1 file changed, 1 deletion(-)
fs/fuse/dir.c +0 -1
@@ -1031,7 +1031,6 @@ static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_moun }kfree (forget); -d_drop (entry); d =d_splice_alias (inode, entry);if (IS_ERR (d))return d;
base-commit: 3879f51857325da9bf3cfb073280257cd16ae067
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 1/2] fuse: don't d_drop() before d_splice_alias()
Quoted 2 lines · NeilBrown
d_splice_alias()now works on hashed dentries so thed_drop()isn't needed. Drop it.
Applied, thanks.
Miklos
PATCH 2/2 fuse: Use d_alloc_trylock() in fuse_direntplus_link()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
fuse uses the results of readdir to prime the dcache. Using d_alloc_parallel() can block if there is a concurrent lookup. Blocking in that case is pointless as the lookup will add info to the dcache and there is no value in the readdir waiting to see if it should add the info too.
Also this call to d_alloc_parallel() is made while the parent directory is locked. A proposed change to locking will lock the parent later, after d_alloc_parallel(). This means it won't be safe to wait in d_alloc_parallel() while holding the directory lock.
So change to use d_alloc_trylock(), which doesn't require full_name_hash and d_lookup to be called first.
--- fs/fuse/readdir.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/fuse/readdir.c +8 -6
@@ -11,6 +11,7 @@#include <linux/pagemap.h> #include <linux/highmem.h> #include <linux/vmalloc.h> +#include <linux/namei.h> static bool fuse_use_readdirplus (struct inode *dir,struct dir_context *ctx) {
@@ -195,14 +196,15 @@ static int fuse_direntplus_link(struct file *file, fc =get_fuse_conn (dir); epoch =atomic_read (&fc->epoch); - name.hash =full_name_hash (parent, name.name, name.len); - dentry =d_lookup (parent, &name); -if (!dentry) { retry: - dentry =d_alloc_parallel (parent, &name); -if (IS_ERR (dentry)) -return PTR_ERR (dentry); + dentry =d_alloc_trylock (parent, &name); +if (IS_ERR (dentry)) { +if (PTR_ERR (dentry) == -EWOULDBLOCK ) +/* harmless */ +return 0 ; +return PTR_ERR (dentry); } +if (!d_in_lookup (dentry)) {struct fuse_inode *fi; inode =d_inode (dentry);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Miklos Szeredi
maintainerRe: [PATCH 2/2] fuse: Use d_alloc_trylock() in fuse_direntplus_link()
Quoted 8 lines · NeilBrown
From: NeilBrown <[email protected]>
fuse uses the results of readdir to prime the dcache. Using
d_alloc_parallel()can block if there is a concurrent lookup. Blocking in that case is pointless as the lookup will add info to the dcache and there is no value in the readdir waiting to see if it should add the info too.
Need to send FORGET in that case. See this sashiko review:
https://sashiko.dev/#/patchset/20260929032927.1451259-1-neilb%40ownmail.net
Thanks,
Miklos