mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
btrfs: use next_state/prev_state in merge_state
We use rb_next/rb_prev and then get the entry for the adjacent items in an extent io tree. We have helpers for this, so convert merge_state to use next_state/prev_state and simplify the code. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
43b068cad5
commit
e63b81aef2
1 changed files with 20 additions and 29 deletions
|
@ -340,18 +340,14 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
|
||||||
static void merge_state(struct extent_io_tree *tree, struct extent_state *state)
|
static void merge_state(struct extent_io_tree *tree, struct extent_state *state)
|
||||||
{
|
{
|
||||||
struct extent_state *other;
|
struct extent_state *other;
|
||||||
struct rb_node *other_node;
|
|
||||||
|
|
||||||
if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY))
|
if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
other_node = rb_prev(&state->rb_node);
|
other = prev_state(state);
|
||||||
if (other_node) {
|
if (other && other->end == state->start - 1 &&
|
||||||
other = rb_entry(other_node, struct extent_state, rb_node);
|
|
||||||
if (other->end == state->start - 1 &&
|
|
||||||
other->state == state->state) {
|
other->state == state->state) {
|
||||||
if (tree->private_data &&
|
if (tree->private_data && is_data_inode(tree->private_data))
|
||||||
is_data_inode(tree->private_data))
|
|
||||||
btrfs_merge_delalloc_extent(tree->private_data,
|
btrfs_merge_delalloc_extent(tree->private_data,
|
||||||
state, other);
|
state, other);
|
||||||
state->start = other->start;
|
state->start = other->start;
|
||||||
|
@ -359,23 +355,18 @@ static void merge_state(struct extent_io_tree *tree, struct extent_state *state)
|
||||||
RB_CLEAR_NODE(&other->rb_node);
|
RB_CLEAR_NODE(&other->rb_node);
|
||||||
free_extent_state(other);
|
free_extent_state(other);
|
||||||
}
|
}
|
||||||
}
|
other = next_state(state);
|
||||||
other_node = rb_next(&state->rb_node);
|
if (other && other->start == state->end + 1 &&
|
||||||
if (other_node) {
|
|
||||||
other = rb_entry(other_node, struct extent_state, rb_node);
|
|
||||||
if (other->start == state->end + 1 &&
|
|
||||||
other->state == state->state) {
|
other->state == state->state) {
|
||||||
if (tree->private_data &&
|
if (tree->private_data && is_data_inode(tree->private_data))
|
||||||
is_data_inode(tree->private_data))
|
btrfs_merge_delalloc_extent(tree->private_data, state,
|
||||||
btrfs_merge_delalloc_extent(tree->private_data,
|
other);
|
||||||
state, other);
|
|
||||||
state->end = other->end;
|
state->end = other->end;
|
||||||
rb_erase(&other->rb_node, &tree->state);
|
rb_erase(&other->rb_node, &tree->state);
|
||||||
RB_CLEAR_NODE(&other->rb_node);
|
RB_CLEAR_NODE(&other->rb_node);
|
||||||
free_extent_state(other);
|
free_extent_state(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void set_state_bits(struct extent_io_tree *tree,
|
static void set_state_bits(struct extent_io_tree *tree,
|
||||||
struct extent_state *state,
|
struct extent_state *state,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue