[PATCH v3 11/11] afs: lookup_atsys to drop and reclaim lock.

From: NeilBrown

Date: Tue Nov 24 2026 - 22:47:26 EST


From: NeilBrown <neil@xxxxxxxxxx>

If afs is asked to lookup a name ending with @sys, it needs to look up
a different name for which it might need to allocate a dentry with
d_alloc_parallel().
This is done while the parent lock is held which will be a problem in
a future patch where the ordering of the parent lock and
d_alloc_parallel() locking is reversed.

There is no actual need to hold the lock during this nested lookup, so
with this patch we drop the lock and reclaim it, and use
lookup_noperm_unlocked().

Signed-off-by: NeilBrown <neil@xxxxxxxxxx>
---
fs/afs/dir.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index bc90b30d8b57..7ed5ff63c90e 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -938,6 +938,12 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
refcount_inc(&subs->usage);
read_unlock(&net->sysnames_lock);

+ /*
+ * We need the directory to be unlocked so we can perform other lookups.
+ * We don't really need the lock any more. The in-lookup status of
+ * dentry gives us sufficient exclusion.
+ */
+ inode_unlock_shared(dir);
for (i = 0; i < subs->nr; i++) {
name = subs->subs[i];
len = dentry->d_name.len - 4 + strlen(name);
@@ -947,7 +953,7 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
}

strcpy(p, name);
- ret = lookup_noperm(&QSTR(buf), dentry->d_parent);
+ ret = lookup_noperm_unlocked(&QSTR(buf), dentry->d_parent);
if (IS_ERR(ret) || d_is_positive(ret))
goto out_s;
dput(ret);
@@ -958,6 +964,12 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
*/
ret = NULL;
out_s:
+ /*
+ * Cannot take parent lock while we hold an in-lookup dentry so
+ * must make sure that lookup is done.
+ */
+ d_lookup_done(dentry);
+ inode_lock_shared(dir);
afs_put_sysnames(subs);
kfree(buf);
out_p:
--
2.50.0.107.gf914562f5916.dirty