Commit e5860f82 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: make find_first_extent_bit() return a boolean

Currently find_first_extent_bit() returns a 0 if it found a range in the
given io tree and 1 if it didn't find any. There's no need to return any
errors, so make the return value a boolean and invert the logic to make
more sense: return true if it found a range and false if it didn't find
any range.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 46d81ebd
...@@ -527,11 +527,10 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start, ...@@ -527,11 +527,10 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start,
*total_added_ret = 0; *total_added_ret = 0;
while (start < end) { while (start < end) {
ret = find_first_extent_bit(&info->excluded_extents, start, if (!find_first_extent_bit(&info->excluded_extents, start,
&extent_start, &extent_end, &extent_start, &extent_end,
EXTENT_DIRTY | EXTENT_UPTODATE, EXTENT_DIRTY | EXTENT_UPTODATE,
NULL); NULL))
if (ret)
break; break;
if (extent_start <= start) { if (extent_start <= start) {
......
...@@ -792,9 +792,9 @@ static int btrfs_set_target_alloc_state(struct btrfs_device *srcdev, ...@@ -792,9 +792,9 @@ static int btrfs_set_target_alloc_state(struct btrfs_device *srcdev,
lockdep_assert_held(&srcdev->fs_info->chunk_mutex); lockdep_assert_held(&srcdev->fs_info->chunk_mutex);
while (!find_first_extent_bit(&srcdev->alloc_state, start, while (find_first_extent_bit(&srcdev->alloc_state, start,
&found_start, &found_end, &found_start, &found_end,
CHUNK_ALLOCATED, &cached_state)) { CHUNK_ALLOCATED, &cached_state)) {
ret = set_extent_bit(&tgtdev->alloc_state, found_start, ret = set_extent_bit(&tgtdev->alloc_state, found_start,
found_end, CHUNK_ALLOCATED, NULL); found_end, CHUNK_ALLOCATED, NULL);
if (ret) if (ret)
......
...@@ -4228,7 +4228,7 @@ static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info) ...@@ -4228,7 +4228,7 @@ static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info)
u64 found_end; u64 found_end;
found = true; found = true;
while (!find_first_extent_bit(&trans->dirty_pages, cur, while (find_first_extent_bit(&trans->dirty_pages, cur,
&found_start, &found_end, EXTENT_DIRTY, &cached)) { &found_start, &found_end, EXTENT_DIRTY, &cached)) {
dirty_bytes += found_end + 1 - found_start; dirty_bytes += found_end + 1 - found_start;
cur = found_end + 1; cur = found_end + 1;
...@@ -4724,8 +4724,8 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, ...@@ -4724,8 +4724,8 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
u64 start = 0; u64 start = 0;
u64 end; u64 end;
while (!find_first_extent_bit(dirty_pages, start, &start, &end, while (find_first_extent_bit(dirty_pages, start, &start, &end,
mark, NULL)) { mark, NULL)) {
clear_extent_bits(dirty_pages, start, end, mark); clear_extent_bits(dirty_pages, start, end, mark);
while (start <= end) { while (start <= end) {
eb = find_extent_buffer(fs_info, start); eb = find_extent_buffer(fs_info, start);
...@@ -4759,8 +4759,8 @@ static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, ...@@ -4759,8 +4759,8 @@ static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
* the same extent range. * the same extent range.
*/ */
mutex_lock(&fs_info->unused_bg_unpin_mutex); mutex_lock(&fs_info->unused_bg_unpin_mutex);
if (find_first_extent_bit(unpin, 0, &start, &end, if (!find_first_extent_bit(unpin, 0, &start, &end,
EXTENT_DIRTY, &cached_state)) { EXTENT_DIRTY, &cached_state)) {
mutex_unlock(&fs_info->unused_bg_unpin_mutex); mutex_unlock(&fs_info->unused_bg_unpin_mutex);
break; break;
} }
......
...@@ -831,15 +831,15 @@ static struct extent_state *find_first_extent_bit_state(struct extent_io_tree *t ...@@ -831,15 +831,15 @@ static struct extent_state *find_first_extent_bit_state(struct extent_io_tree *t
* *
* Note: If there are multiple bits set in @bits, any of them will match. * Note: If there are multiple bits set in @bits, any of them will match.
* *
* Return 0 if we find something, and update @start_ret and @end_ret. * Return true if we find something, and update @start_ret and @end_ret.
* Return 1 if we found nothing. * Return false if we found nothing.
*/ */
int find_first_extent_bit(struct extent_io_tree *tree, u64 start, bool find_first_extent_bit(struct extent_io_tree *tree, u64 start,
u64 *start_ret, u64 *end_ret, u32 bits, u64 *start_ret, u64 *end_ret, u32 bits,
struct extent_state **cached_state) struct extent_state **cached_state)
{ {
struct extent_state *state; struct extent_state *state;
int ret = 1; bool ret = false;
spin_lock(&tree->lock); spin_lock(&tree->lock);
if (cached_state && *cached_state) { if (cached_state && *cached_state) {
...@@ -863,7 +863,7 @@ int find_first_extent_bit(struct extent_io_tree *tree, u64 start, ...@@ -863,7 +863,7 @@ int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
cache_state_if_flags(state, cached_state, 0); cache_state_if_flags(state, cached_state, 0);
*start_ret = state->start; *start_ret = state->start;
*end_ret = state->end; *end_ret = state->end;
ret = 0; ret = true;
} }
out: out:
spin_unlock(&tree->lock); spin_unlock(&tree->lock);
......
...@@ -182,9 +182,9 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, ...@@ -182,9 +182,9 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
u32 bits, u32 clear_bits, u32 bits, u32 clear_bits,
struct extent_state **cached_state); struct extent_state **cached_state);
int find_first_extent_bit(struct extent_io_tree *tree, u64 start, bool find_first_extent_bit(struct extent_io_tree *tree, u64 start,
u64 *start_ret, u64 *end_ret, u32 bits, u64 *start_ret, u64 *end_ret, u32 bits,
struct extent_state **cached_state); struct extent_state **cached_state);
void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
u64 *start_ret, u64 *end_ret, u32 bits); u64 *start_ret, u64 *end_ret, u32 bits);
int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start, int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
......
...@@ -2751,9 +2751,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans) ...@@ -2751,9 +2751,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
mutex_lock(&fs_info->unused_bg_unpin_mutex); mutex_lock(&fs_info->unused_bg_unpin_mutex);
ret = find_first_extent_bit(unpin, 0, &start, &end, if (!find_first_extent_bit(unpin, 0, &start, &end,
EXTENT_DIRTY, &cached_state); EXTENT_DIRTY, &cached_state)) {
if (ret) {
mutex_unlock(&fs_info->unused_bg_unpin_mutex); mutex_unlock(&fs_info->unused_bg_unpin_mutex);
break; break;
} }
......
...@@ -1219,10 +1219,9 @@ static noinline_for_stack int write_pinned_extent_entries( ...@@ -1219,10 +1219,9 @@ static noinline_for_stack int write_pinned_extent_entries(
start = block_group->start; start = block_group->start;
while (start < block_group->start + block_group->length) { while (start < block_group->start + block_group->length) {
ret = find_first_extent_bit(unpin, start, if (!find_first_extent_bit(unpin, start,
&extent_start, &extent_end, &extent_start, &extent_end,
EXTENT_DIRTY, NULL); EXTENT_DIRTY, NULL))
if (ret)
return 0; return 0;
/* This pinned extent is out of our range */ /* This pinned extent is out of our range */
......
...@@ -3498,6 +3498,8 @@ int find_next_extent(struct reloc_control *rc, struct btrfs_path *path, ...@@ -3498,6 +3498,8 @@ int find_next_extent(struct reloc_control *rc, struct btrfs_path *path,
last = rc->block_group->start + rc->block_group->length; last = rc->block_group->start + rc->block_group->length;
while (1) { while (1) {
bool block_found;
cond_resched(); cond_resched();
if (rc->search_start >= last) { if (rc->search_start >= last) {
ret = 1; ret = 1;
...@@ -3548,11 +3550,11 @@ int find_next_extent(struct reloc_control *rc, struct btrfs_path *path, ...@@ -3548,11 +3550,11 @@ int find_next_extent(struct reloc_control *rc, struct btrfs_path *path,
goto next; goto next;
} }
ret = find_first_extent_bit(&rc->processed_blocks, block_found = find_first_extent_bit(&rc->processed_blocks,
key.objectid, &start, &end, key.objectid, &start, &end,
EXTENT_DIRTY, NULL); EXTENT_DIRTY, NULL);
if (ret == 0 && start <= key.objectid) { if (block_found && start <= key.objectid) {
btrfs_release_path(path); btrfs_release_path(path);
rc->search_start = end + 1; rc->search_start = end + 1;
} else { } else {
......
...@@ -1060,8 +1060,8 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info, ...@@ -1060,8 +1060,8 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
u64 start = 0; u64 start = 0;
u64 end; u64 end;
while (!find_first_extent_bit(dirty_pages, start, &start, &end, while (find_first_extent_bit(dirty_pages, start, &start, &end,
mark, &cached_state)) { mark, &cached_state)) {
bool wait_writeback = false; bool wait_writeback = false;
err = convert_extent_bit(dirty_pages, start, end, err = convert_extent_bit(dirty_pages, start, end,
...@@ -1114,8 +1114,8 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info, ...@@ -1114,8 +1114,8 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info,
u64 start = 0; u64 start = 0;
u64 end; u64 end;
while (!find_first_extent_bit(dirty_pages, start, &start, &end, while (find_first_extent_bit(dirty_pages, start, &start, &end,
EXTENT_NEED_WAIT, &cached_state)) { EXTENT_NEED_WAIT, &cached_state)) {
/* /*
* Ignore -ENOMEM errors returned by clear_extent_bit(). * Ignore -ENOMEM errors returned by clear_extent_bit().
* When committing the transaction, we'll remove any entries * When committing the transaction, we'll remove any entries
......
...@@ -1424,9 +1424,9 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start, ...@@ -1424,9 +1424,9 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
lockdep_assert_held(&device->fs_info->chunk_mutex); lockdep_assert_held(&device->fs_info->chunk_mutex);
if (!find_first_extent_bit(&device->alloc_state, *start, if (find_first_extent_bit(&device->alloc_state, *start,
&physical_start, &physical_end, &physical_start, &physical_end,
CHUNK_ALLOCATED, NULL)) { CHUNK_ALLOCATED, NULL)) {
if (in_range(physical_start, *start, len) || if (in_range(physical_start, *start, len) ||
in_range(*start, physical_start, in_range(*start, physical_start,
......
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