Commit 0304f2d8 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: reloc: pass essential members for alloc_backref_node()

Bytenr and level are essential parameters for backref_node, thus it
makes sense to initialize them at allocation time.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2a979612
...@@ -339,18 +339,24 @@ static void backref_cache_cleanup(struct backref_cache *cache) ...@@ -339,18 +339,24 @@ static void backref_cache_cleanup(struct backref_cache *cache)
ASSERT(!cache->nr_edges); ASSERT(!cache->nr_edges);
} }
static struct backref_node *alloc_backref_node(struct backref_cache *cache) static struct backref_node *alloc_backref_node(struct backref_cache *cache,
u64 bytenr, int level)
{ {
struct backref_node *node; struct backref_node *node;
ASSERT(level >= 0 && level < BTRFS_MAX_LEVEL);
node = kzalloc(sizeof(*node), GFP_NOFS); node = kzalloc(sizeof(*node), GFP_NOFS);
if (node) { if (!node)
INIT_LIST_HEAD(&node->list); return node;
INIT_LIST_HEAD(&node->upper);
INIT_LIST_HEAD(&node->lower); INIT_LIST_HEAD(&node->list);
RB_CLEAR_NODE(&node->rb_node); INIT_LIST_HEAD(&node->upper);
cache->nr_nodes++; INIT_LIST_HEAD(&node->lower);
} RB_CLEAR_NODE(&node->rb_node);
cache->nr_nodes++;
node->level = level;
node->bytenr = bytenr;
return node; return node;
} }
...@@ -775,13 +781,12 @@ static int handle_direct_tree_backref(struct backref_cache *cache, ...@@ -775,13 +781,12 @@ static int handle_direct_tree_backref(struct backref_cache *cache,
rb_node = tree_search(&cache->rb_root, ref_key->offset); rb_node = tree_search(&cache->rb_root, ref_key->offset);
if (!rb_node) { if (!rb_node) {
/* Parent node not yet cached */ /* Parent node not yet cached */
upper = alloc_backref_node(cache); upper = alloc_backref_node(cache, ref_key->offset,
cur->level + 1);
if (!upper) { if (!upper) {
free_backref_edge(cache, edge); free_backref_edge(cache, edge);
return -ENOMEM; return -ENOMEM;
} }
upper->bytenr = ref_key->offset;
upper->level = cur->level + 1;
/* /*
* Backrefs for the upper level block isn't cached, add the * Backrefs for the upper level block isn't cached, add the
...@@ -896,16 +901,15 @@ static int handle_indirect_tree_backref(struct backref_cache *cache, ...@@ -896,16 +901,15 @@ static int handle_indirect_tree_backref(struct backref_cache *cache,
eb = path->nodes[level]; eb = path->nodes[level];
rb_node = tree_search(&cache->rb_root, eb->start); rb_node = tree_search(&cache->rb_root, eb->start);
if (!rb_node) { if (!rb_node) {
upper = alloc_backref_node(cache); upper = alloc_backref_node(cache, eb->start,
lower->level + 1);
if (!upper) { if (!upper) {
btrfs_put_root(root); btrfs_put_root(root);
free_backref_edge(cache, edge); free_backref_edge(cache, edge);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
upper->bytenr = eb->start;
upper->owner = btrfs_header_owner(eb); upper->owner = btrfs_header_owner(eb);
upper->level = lower->level + 1;
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
upper->cowonly = 1; upper->cowonly = 1;
...@@ -996,14 +1000,12 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -996,14 +1000,12 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
goto out; goto out;
} }
node = alloc_backref_node(cache); node = alloc_backref_node(cache, bytenr, level);
if (!node) { if (!node) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
node->bytenr = bytenr;
node->level = level;
node->lowest = 1; node->lowest = 1;
cur = node; cur = node;
again: again:
...@@ -1346,12 +1348,10 @@ static int clone_backref_node(struct btrfs_trans_handle *trans, ...@@ -1346,12 +1348,10 @@ static int clone_backref_node(struct btrfs_trans_handle *trans,
if (!node) if (!node)
return 0; return 0;
new_node = alloc_backref_node(cache); new_node = alloc_backref_node(cache, dest->node->start, node->level);
if (!new_node) if (!new_node)
return -ENOMEM; return -ENOMEM;
new_node->bytenr = dest->node->start;
new_node->level = node->level;
new_node->lowest = node->lowest; new_node->lowest = node->lowest;
new_node->checked = 1; new_node->checked = 1;
new_node->root = btrfs_grab_root(dest); new_node->root = btrfs_grab_root(dest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment