diff mbox series

[3/3] btrfs: use btrfs_find_inode in find_next_inode

Message ID 20220721135006.3345302-4-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Remove duplicate code in btrfs_prune_dentries/find_next_inode | expand

Commit Message

Nikolay Borisov July 21, 2022, 1:50 p.m. UTC
Start using btrfs_find_inode in find_next_inode, now that the common
logic has been encapsulated in the former function. This simplifies the
body of find_next_inode.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/relocation.c | 54 +++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a6dc827e75af..fdb99e2ce949 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -951,52 +951,36 @@  int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
  */
 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
 {
-	struct rb_node *node;
-	struct rb_node *prev;
-	struct btrfs_inode *entry;
-	struct inode *inode;
+	struct rb_node *node = NULL;
+	struct inode *inode = NULL;
 
 	spin_lock(&root->inode_lock);
-again:
-	node = root->inode_tree.rb_node;
-	prev = NULL;
-	while (node) {
-		prev = node;
-		entry = rb_entry(node, struct btrfs_inode, rb_node);
 
-		if (objectid < btrfs_ino(entry))
-			node = node->rb_left;
-		else if (objectid > btrfs_ino(entry))
-			node = node->rb_right;
-		else
-			break;
-	}
-	if (!node) {
-		while (prev) {
-			entry = rb_entry(prev, struct btrfs_inode, rb_node);
-			if (objectid <= btrfs_ino(entry)) {
-				node = prev;
+	do {
+		struct btrfs_inode *entry;
+
+		if (!node) {
+			node = btrfs_find_inode(root, objectid);
+			if (!node)
 				break;
-			}
-			prev = rb_next(prev);
 		}
-	}
-	while (node) {
+
 		entry = rb_entry(node, struct btrfs_inode, rb_node);
+		objectid = btrfs_ino(entry) + 1;
 		inode = igrab(&entry->vfs_inode);
-		if (inode) {
-			spin_unlock(&root->inode_lock);
-			return inode;
-		}
+		if (inode)
+			break;
 
-		objectid = btrfs_ino(entry) + 1;
-		if (cond_resched_lock(&root->inode_lock))
-			goto again;
+		if (cond_resched_lock(&root->inode_lock)) {
+			node = NULL;
+			continue;
+		}
 
 		node = rb_next(node);
-	}
+	} while(node);
+
 	spin_unlock(&root->inode_lock);
-	return NULL;
+	return inode;
 }
 
 /*