[PATCH RFC 7/8] dcache: push releasing dentry lock into sweep_negative

From: Konstantin Khlebnikov
Date: Fri May 08 2020 - 08:23:42 EST


This is preparation for the next patch.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
---
fs/dcache.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 0fd2e02e507b..60158065891e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -636,15 +636,17 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
* Move cached negative dentry to the tail of parent->d_subdirs.
* This lets walkers skip them all together at first sight.
* Must be called at dput of negative dentry.
+ * dentry->d_lock must be held, returns with it unlocked.
*/
static void sweep_negative(struct dentry *dentry)
+ __releases(dentry->d_lock)
{
struct dentry *parent;

if (!d_is_tail_negative(dentry)) {
parent = lock_parent(dentry);
if (!parent)
- return;
+ goto out;

if (!d_count(dentry) && d_is_negative(dentry) &&
!d_is_tail_negative(dentry)) {
@@ -654,6 +656,8 @@ static void sweep_negative(struct dentry *dentry)

spin_unlock(&parent->d_lock);
}
+out:
+ spin_unlock(&dentry->d_lock);
}

/*
@@ -747,7 +751,8 @@ static struct dentry *dentry_kill(struct dentry *dentry)
spin_unlock(&parent->d_lock);
if (d_is_negative(dentry))
sweep_negative(dentry);
- spin_unlock(&dentry->d_lock);
+ else
+ spin_unlock(&dentry->d_lock);
return NULL;
}

@@ -905,7 +910,8 @@ void dput(struct dentry *dentry)
if (likely(retain_dentry(dentry))) {
if (d_is_negative(dentry))
sweep_negative(dentry);
- spin_unlock(&dentry->d_lock);
+ else
+ spin_unlock(&dentry->d_lock);
return;
}