[PATCH 18/19] btrfs: relocation: Move the target backref node insert code into finish_upper_links()

Qu Wenruo
2020-03-03T07:15:53Z

The snippet of code can be easily merged into finish_upper_links(), thus
make related code more reuseable.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/relocation.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 4cb61165d852..ac3ac0c7ac9e 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -400,8 +400,23 @@ static int finish_upper_links(struct backref_cache *cache,
{
struct list_head *useless_node = &cache->useless_node;
struct backref_edge *edge;
+ struct rb_node *rb_node;
LIST_HEAD(pending_edge);

+ /*
+ * everything goes well, connect backref nodes and insert backref nodes
+ * into the cache.
+ */
+ ASSERT(start->checked);
+ if (!start->cowonly) {
+ rb_node = simple_insert(&cache->rb_root, start->bytenr,
+ &start->rb_node);
+ if (rb_node)
+ backref_cache_panic(cache->fs_info, start->bytenr,
+ -EEXIST);
+ list_add_tail(&start->lower, &cache->leaves);
+ }
+
/*
* Use breadth first search to iterate all related edges.
*
@@ -584,7 +599,6 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
struct backref_node *lower;
struct backref_node *node = NULL;
struct backref_edge *edge;
- struct rb_node *rb_node;
int ret;
int err = 0;

@@ -629,20 +643,6 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
}
}

- /*
- * everything goes well, connect backref nodes and insert backref nodes
- * into the cache.
- */
- ASSERT(node->checked);
- if (!node->cowonly) {
- rb_node = simple_insert(&cache->rb_root, node->bytenr,
- &node->rb_node);
- if (rb_node)
- backref_cache_panic(cache->fs_info, node->bytenr,
- -EEXIST);
- list_add_tail(&node->lower, &cache->leaves);
- }
-
/* Finish the upper linkage of newly added edges/nodes */
ret = finish_upper_links(cache, node);
if (ret < 0) {
--
2.25.1