Commit 98ff7b94 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: relocation: Cleanup while loop using rbtree_postorder_for_each_entry_safe

And add one line comment explaining what we're doing for each loop.
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 3628b4ca
...@@ -2991,7 +2991,7 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, ...@@ -2991,7 +2991,7 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
struct backref_node *node; struct backref_node *node;
struct btrfs_path *path; struct btrfs_path *path;
struct tree_block *block; struct tree_block *block;
struct rb_node *rb_node; struct tree_block *next;
int ret; int ret;
int err = 0; int err = 0;
...@@ -3001,29 +3001,23 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, ...@@ -3001,29 +3001,23 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
goto out_free_blocks; goto out_free_blocks;
} }
rb_node = rb_first(blocks); /* Kick in readahead for tree blocks with missing keys */
while (rb_node) { rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
block = rb_entry(rb_node, struct tree_block, rb_node);
if (!block->key_ready) if (!block->key_ready)
readahead_tree_block(fs_info, block->bytenr); readahead_tree_block(fs_info, block->bytenr);
rb_node = rb_next(rb_node);
} }
rb_node = rb_first(blocks); /* Get first keys */
while (rb_node) { rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
block = rb_entry(rb_node, struct tree_block, rb_node);
if (!block->key_ready) { if (!block->key_ready) {
err = get_tree_block_key(fs_info, block); err = get_tree_block_key(fs_info, block);
if (err) if (err)
goto out_free_path; goto out_free_path;
} }
rb_node = rb_next(rb_node);
} }
rb_node = rb_first(blocks); /* Do tree relocation */
while (rb_node) { rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
block = rb_entry(rb_node, struct tree_block, rb_node);
node = build_backref_tree(rc, &block->key, node = build_backref_tree(rc, &block->key,
block->level, block->bytenr); block->level, block->bytenr);
if (IS_ERR(node)) { if (IS_ERR(node)) {
...@@ -3034,11 +3028,10 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, ...@@ -3034,11 +3028,10 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
ret = relocate_tree_block(trans, rc, node, &block->key, ret = relocate_tree_block(trans, rc, node, &block->key,
path); path);
if (ret < 0) { if (ret < 0) {
if (ret != -EAGAIN || rb_node == rb_first(blocks)) if (ret != -EAGAIN || &block->rb_node == rb_first(blocks))
err = ret; err = ret;
goto out; goto out;
} }
rb_node = rb_next(rb_node);
} }
out: out:
err = finish_pending_nodes(trans, rc, path, err); err = finish_pending_nodes(trans, rc, path, err);
......
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