[PATCH v2 09/18] libfs: change scan_positives() to use d_for_each_positive_child_continue()

NeilBrown <[email protected]>
Newsgroups org.kernel.vger.linux-fsdevel,org.kernel.vger.autofs,org.kernel.vger.ceph-devel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs
Message-ID <[email protected]>
From: NeilBrown <[email protected]>

Using d_for_each_positive_child_continue() simplifies this code
slightly and make is easier to read.

Signed-off-by: NeilBrown <[email protected]>
---
 fs/libfs.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index c2b09e72cbd8..398fae675207 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -112,17 +112,9 @@ static struct dentry *scan_positives(struct dentry *cursor,
 				     loff_t count)
 {
 	struct dentry *dentry = cursor->d_parent, *found = NULL;
-	struct dentry *next;
+	struct dentry *d = last;
 
-	spin_lock(&dentry->d_lock);
-	next = last ? d_next_sibling(last) : d_first_child(dentry);
-	while (next) {
-		struct dentry *d = next;
-
-		next = d_next_sibling(next);
-		// we must at least skip cursors, to avoid livelocks
-		if (d->d_flags & DCACHE_DENTRY_CURSOR)
-			continue;
+	d_for_each_positive_child_continue(d, dentry) {
 		if (simple_positive(d) && !--count) {
 			spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
 			if (simple_positive(d))
@@ -134,13 +126,12 @@ static struct dentry *scan_positives(struct dentry *cursor,
 		}
 		if (need_resched()) {
 			hlist_move_behind(&cursor->d_sib, &d->d_sib);
+			d = cursor;
 			spin_unlock(&dentry->d_lock);
 			cond_resched();
 			spin_lock(&dentry->d_lock);
-			next = d_next_sibling(cursor);
 		}
 	}
-	spin_unlock(&dentry->d_lock);
 	dput(last);
 	return found;
 }
-- 
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.