Commit 206983b7 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: use btrfs_read_node_slot in btrfs_realloc_node

We have this open-coded nightmare in btrfs_realloc_node that does
the same thing that the normal read path does, which is to see if we
have the eb in memory already, and if not read it, and verify the eb is
uptodate.  Delete this open coding and simply use btrfs_read_node_slot.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent bfb484d9
...@@ -1570,7 +1570,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1570,7 +1570,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_buffer *cur; struct extent_buffer *cur;
u64 blocknr; u64 blocknr;
u64 gen;
u64 search_start = *last_ret; u64 search_start = *last_ret;
u64 last_block = 0; u64 last_block = 0;
u64 other; u64 other;
...@@ -1578,14 +1577,10 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1578,14 +1577,10 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
int end_slot; int end_slot;
int i; int i;
int err = 0; int err = 0;
int parent_level;
int uptodate;
u32 blocksize; u32 blocksize;
int progress_passed = 0; int progress_passed = 0;
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
parent_level = btrfs_header_level(parent);
WARN_ON(trans->transaction != fs_info->running_transaction); WARN_ON(trans->transaction != fs_info->running_transaction);
WARN_ON(trans->transid != fs_info->generation); WARN_ON(trans->transid != fs_info->generation);
...@@ -1597,7 +1592,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1597,7 +1592,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
return 0; return 0;
for (i = start_slot; i <= end_slot; i++) { for (i = start_slot; i <= end_slot; i++) {
struct btrfs_key first_key;
int close = 1; int close = 1;
btrfs_node_key(parent, &disk_key, i); btrfs_node_key(parent, &disk_key, i);
...@@ -1606,8 +1600,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1606,8 +1600,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
progress_passed = 1; progress_passed = 1;
blocknr = btrfs_node_blockptr(parent, i); blocknr = btrfs_node_blockptr(parent, i);
gen = btrfs_node_ptr_generation(parent, i);
btrfs_node_key_to_cpu(parent, &first_key, i);
if (last_block == 0) if (last_block == 0)
last_block = blocknr; last_block = blocknr;
...@@ -1624,31 +1616,9 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, ...@@ -1624,31 +1616,9 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
continue; continue;
} }
cur = find_extent_buffer(fs_info, blocknr); cur = btrfs_read_node_slot(parent, i);
if (cur) if (IS_ERR(cur))
uptodate = btrfs_buffer_uptodate(cur, gen, 0); return PTR_ERR(cur);
else
uptodate = 0;
if (!cur || !uptodate) {
if (!cur) {
cur = read_tree_block(fs_info, blocknr, gen,
parent_level - 1,
&first_key);
if (IS_ERR(cur)) {
return PTR_ERR(cur);
} else if (!extent_buffer_uptodate(cur)) {
free_extent_buffer(cur);
return -EIO;
}
} else if (!uptodate) {
err = btrfs_read_buffer(cur, gen,
parent_level - 1,&first_key);
if (err) {
free_extent_buffer(cur);
return err;
}
}
}
if (search_start == 0) if (search_start == 0)
search_start = last_block; search_start = last_block;
......
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