[PATCH v2 02/18] autofs: change positive_after() so it takes d_lock rather than the caller

NeilBrown <[email protected]>
Newsgroups gmane.linux.file-systems,gmane.linux.kernel.autofs,gmane.linux.kernel,gmane.comp.file-systems.ceph.devel,gmane.comp.file-systems.coda.general,gmane.linux.nfs
Message-ID <[email protected]>
From: NeilBrown <[email protected]>

Moving the d_lock from caller to callee simplifies the code.

The only non-trivial code that is no longer locked is
		parent = p->d_parent;
and as autofs doesn't support rename, ->d_parent is stable
and this doesn't need to be protected.

Signed-off-by: NeilBrown <[email protected]>
---
 fs/autofs/expire.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/fs/autofs/expire.c b/fs/autofs/expire.c
index 5c2d459e1e48..909622eeb8a0 100644
--- a/fs/autofs/expire.c
+++ b/fs/autofs/expire.c
@@ -70,9 +70,9 @@ static int autofs_mount_busy(struct vfsmount *mnt,
 	return status;
 }
 
-/* p->d_lock held */
 static struct dentry *positive_after(struct dentry *p, struct dentry *child)
 {
+	spin_lock(&p->d_lock);
 	child = child ? d_next_sibling(child) : d_first_child(p);
 
 	hlist_for_each_entry_from(child, d_sib) {
@@ -84,6 +84,7 @@ static struct dentry *positive_after(struct dentry *p, struct dentry *child)
 		}
 		spin_unlock(&child->d_lock);
 	}
+	spin_unlock(&p->d_lock);
 
 	return NULL;
 }
@@ -98,9 +99,7 @@ static struct dentry *get_next_positive_subdir(struct dentry *prev,
 	struct dentry *q;
 
 	spin_lock(&sbi->lookup_lock);
-	spin_lock(&root->d_lock);
 	q = positive_after(root, prev);
-	spin_unlock(&root->d_lock);
 	spin_unlock(&sbi->lookup_lock);
 	dput(prev);
 	return q;
@@ -119,7 +118,6 @@ static struct dentry *get_next_positive_dentry(struct dentry *prev,
 		return dget(root);
 
 	spin_lock(&sbi->lookup_lock);
-	spin_lock(&p->d_lock);
 	while (1) {
 		struct dentry *parent;
 
@@ -127,12 +125,9 @@ static struct dentry *get_next_positive_dentry(struct dentry *prev,
 		if (ret || p == root)
 			break;
 		parent = p->d_parent;
-		spin_unlock(&p->d_lock);
-		spin_lock(&parent->d_lock);
 		d = p;
 		p = parent;
 	}
-	spin_unlock(&p->d_lock);
 	spin_unlock(&sbi->lookup_lock);
 	dput(prev);
 	return ret;
-- 
2.50.0.107.gf914562f5916.dirty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.