Skip to content

Commit

Permalink
Btrfs: Reorder tests in set_extent_bit to properly find holes
Browse files Browse the repository at this point in the history
Yan Zheng noticed that set_extent_bit was exiting too early when there
was a hole in the map.  The fix is to reorder the tests to check for the
hole first.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason authored and David Woodhouse committed Sep 11, 2007
1 parent 011410b commit a8c450b
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions fs/btrfs/extent_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,28 +712,6 @@ int set_extent_bit(struct extent_map_tree *tree, u64 start, u64 end, int bits,
}
goto search_again;
}
/*
* | ---- desired range ---- |
* | state |
* We need to split the extent, and set the bit
* on the first half
*/
if (state->start <= end && state->end > end) {
set = state->state & bits;
if (exclusive && set) {
*failed_start = start;
err = -EEXIST;
goto out;
}
err = split_state(tree, state, prealloc, end + 1);
BUG_ON(err == -EEXIST);

prealloc->state |= bits;
merge_state(tree, prealloc);
prealloc = NULL;
goto out;
}

/*
* | ---- desired range ---- |
* | state | or | state |
Expand All @@ -756,6 +734,28 @@ int set_extent_bit(struct extent_map_tree *tree, u64 start, u64 end, int bits,
start = this_end + 1;
goto search_again;
}
/*
* | ---- desired range ---- |
* | state |
* We need to split the extent, and set the bit
* on the first half
*/
if (state->start <= end && state->end > end) {
set = state->state & bits;
if (exclusive && set) {
*failed_start = start;
err = -EEXIST;
goto out;
}
err = split_state(tree, state, prealloc, end + 1);
BUG_ON(err == -EEXIST);

prealloc->state |= bits;
merge_state(tree, prealloc);
prealloc = NULL;
goto out;
}

goto search_again;

out:
Expand Down

0 comments on commit a8c450b

Please sign in to comment.