Clean-up of __tree_search() in extent_map.c
diff mbox

Message ID 1345767980-7165-1-git-send-email-clinew@linux.vnet.ibm.com
State New, archived
Headers show

Commit Message

clinew@linux.vnet.ibm.com Aug. 24, 2012, 12:26 a.m. UTC
From: Wade Cline <wcline@us.ibm.com>

Removed extra variables orig_prev and prev_entry. Clarified variable
names. Added function documentation and code comments.

Signed-off-by: Wade Cline <wcline@us.ibm.com>
---
 fs/btrfs/extent_map.c |   60 +++++++++++++++++++++++++++---------------------
 1 files changed, 34 insertions(+), 26 deletions(-)

Patch
diff mbox

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 7c97b33..b1ac153 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -104,53 +104,61 @@  static struct rb_node *tree_insert(struct rb_root *root, u64 offset,
 	return NULL;
 }
 
-/*
- * search through the tree for an extent_map with a given offset.  If
- * it can't be found, try to find some neighboring extents
+/**
+ * __tree_search - Search for an extent_map with the given offset.
+ * @root:	The root of the tree to search.
+ * @offset:	Offset in bytes to search for.
+ * @prev_ret:	extent_map before the given offset.
+ * @next_ret:	extent_map after the given offset.
+ *
+ * Search through the tree for an extent_map with a given offset.  If
+ * it can't be found, try to find some neighboring extents.
  */
 static struct rb_node *__tree_search(struct rb_root *root, u64 offset,
 				     struct rb_node **prev_ret,
 				     struct rb_node **next_ret)
 {
-	struct rb_node *n = root->rb_node;
-	struct rb_node *prev = NULL;
-	struct rb_node *orig_prev = NULL;
-	struct extent_map *entry;
-	struct extent_map *prev_entry = NULL;
+	struct rb_node *node = root->rb_node;
+	struct rb_node *prev_node = NULL;
+	struct extent_map *entry = NULL;
 
-	while (n) {
-		entry = rb_entry(n, struct extent_map, rb_node);
-		prev = n;
-		prev_entry = entry;
+	/* Search for an extent map with the given offset. */
+	while (node) {
+		entry = rb_entry(node, struct extent_map, rb_node);
+		prev_node = node;
 
 		WARN_ON(!entry->in_tree);
 
 		if (offset < entry->start)
-			n = n->rb_left;
+			node = node->rb_left;
 		else if (offset >= extent_map_end(entry))
-			n = n->rb_right;
+			node = node->rb_right;
 		else
-			return n;
+			return node;
 	}
 
+	/* Search for an extent map before the given offset. */
 	if (prev_ret) {
-		orig_prev = prev;
-		while (prev && offset >= extent_map_end(prev_entry)) {
-			prev = rb_next(prev);
-			prev_entry = rb_entry(prev, struct extent_map, rb_node);
+		node = prev_node;
+		while (node && offset >= extent_map_end(entry)) {
+			node = rb_next(node);
+			entry = rb_entry(node, struct extent_map, rb_node);
 		}
-		*prev_ret = prev;
-		prev = orig_prev;
+		*prev_ret = node;
 	}
 
+	/* Search for an extent map after the given offset. */
 	if (next_ret) {
-		prev_entry = rb_entry(prev, struct extent_map, rb_node);
-		while (prev && offset < prev_entry->start) {
-			prev = rb_prev(prev);
-			prev_entry = rb_entry(prev, struct extent_map, rb_node);
+		node = prev_node;
+		entry = rb_entry(node, struct extent_map, rb_node);
+		while (node && offset < entry->start) {
+			node = rb_prev(node);
+			entry = rb_entry(node, struct extent_map, rb_node);
 		}
-		*next_ret = prev;
+		*next_ret = node;
 	}
+
+	/* None found. */
 	return NULL;
 }