From: NeilBrown 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 --- fs/afs/dir.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 1edaa7323428..b8773adc4e3e 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -911,7 +911,8 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry) /* * Look up an entry in a directory with @sys substitution. */ -static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry) +static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry, + unsigned int flags) { struct afs_sysnames *subs; struct afs_net *net = afs_i2net(dir); @@ -936,6 +937,15 @@ 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. + */ + if (flags & LOOKUP_SHARED) + inode_unlock_shared(dir); + else + inode_unlock(dir); for (i = 0; i < subs->nr; i++) { name = subs->subs[i]; len = dentry->d_name.len - 4 + strlen(name); @@ -945,7 +955,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); @@ -956,6 +966,15 @@ 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); + if (flags & LOOKUP_SHARED) + inode_lock_shared(dir); + else + inode_lock_nested(dir, I_MUTEX_PARENT); afs_put_sysnames(subs); kfree(buf); out_p: @@ -1001,7 +1020,7 @@ struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, dentry->d_name.name[dentry->d_name.len - 3] == 's' && dentry->d_name.name[dentry->d_name.len - 2] == 'y' && dentry->d_name.name[dentry->d_name.len - 1] == 's') - return afs_lookup_atsys(dir, dentry); + return afs_lookup_atsys(dir, dentry, flags); afs_stat_v(dvnode, n_lookup); inode = afs_do_lookup(dir, dentry); -- 2.50.0.107.gf914562f5916.dirty