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

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
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -527,11 +527,10 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start,
		*total_added_ret = 0;

	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_DIRTY | EXTENT_UPTODATE,
					    NULL);
		if (ret)
					   NULL))
			break;

		if (extent_start <= start) {
+3 −3
Original line number Diff line number Diff line
@@ -792,7 +792,7 @@ static int btrfs_set_target_alloc_state(struct btrfs_device *srcdev,

	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,
				     CHUNK_ALLOCATED, &cached_state)) {
		ret = set_extent_bit(&tgtdev->alloc_state, found_start,
+5 −5
Original line number Diff line number Diff line
@@ -4228,7 +4228,7 @@ static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info)
		u64 found_end;

		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)) {
			dirty_bytes += found_end + 1 - found_start;
			cur = found_end + 1;
@@ -4724,7 +4724,7 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
	u64 start = 0;
	u64 end;

	while (!find_first_extent_bit(dirty_pages, start, &start, &end,
	while (find_first_extent_bit(dirty_pages, start, &start, &end,
				     mark, NULL)) {
		clear_extent_bits(dirty_pages, start, end, mark);
		while (start <= end) {
@@ -4759,7 +4759,7 @@ static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
		 * the same extent range.
		 */
		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)) {
			mutex_unlock(&fs_info->unused_bg_unpin_mutex);
			break;
+7 −7
Original line number Diff line number Diff line
@@ -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.
 *
 * Return 0 if we find something, and update @start_ret and @end_ret.
 * Return 1 if we found nothing.
 * Return true if we find something, and update @start_ret and @end_ret.
 * 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,
			   struct extent_state **cached_state)
{
	struct extent_state *state;
	int ret = 1;
	bool ret = false;

	spin_lock(&tree->lock);
	if (cached_state && *cached_state) {
@@ -863,7 +863,7 @@ int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
		cache_state_if_flags(state, cached_state, 0);
		*start_ret = state->start;
		*end_ret = state->end;
		ret = 0;
		ret = true;
	}
out:
	spin_unlock(&tree->lock);
+3 −3
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
		       u32 bits, u32 clear_bits,
		       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,
			   struct extent_state **cached_state);
void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
Loading