mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
46d81ebd4a
commit
e5860f8207
10 changed files with 40 additions and 41 deletions
|
@ -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,7 +792,7 @@ 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,
|
||||||
|
|
|
@ -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,7 +4724,7 @@ 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) {
|
||||||
|
@ -4759,7 +4759,7 @@ 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
|
||||||
*
|
*
|
||||||
* 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 @@ got_it:
|
||||||
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,7 +182,7 @@ 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,
|
||||||
|
|
|
@ -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(
|
||||||
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,
|
||||||
|
|
||||||
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 @@ next:
|
||||||
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,7 +1060,7 @@ 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;
|
||||||
|
|
||||||
|
@ -1114,7 +1114,7 @@ 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().
|
||||||
|
|
|
@ -1424,7 +1424,7 @@ 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)) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue