btrfs: make find_first_extent_bit() return a boolean
authorFilipe Manana <fdmanana@suse.com>
Fri, 30 Jun 2023 15:03:49 +0000 (16:03 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2023 12:52:12 +0000 (14:52 +0200)
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>
fs/btrfs/block-group.c
fs/btrfs/dev-replace.c
fs/btrfs/disk-io.c
fs/btrfs/extent-io-tree.c
fs/btrfs/extent-io-tree.h
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/relocation.c
fs/btrfs/transaction.c
fs/btrfs/volumes.c

index 7bd1eee..9479c9e 100644 (file)
@@ -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,
-                                           &extent_start, &extent_end,
-                                           EXTENT_DIRTY | EXTENT_UPTODATE,
-                                           NULL);
-               if (ret)
+               if (!find_first_extent_bit(&info->excluded_extents, start,
+                                          &extent_start, &extent_end,
+                                          EXTENT_DIRTY | EXTENT_UPTODATE,
+                                          NULL))
                        break;
 
                if (extent_start <= start) {
index 5f10965..fff22ed 100644 (file)
@@ -792,9 +792,9 @@ 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,
-                                     &found_start, &found_end,
-                                     CHUNK_ALLOCATED, &cached_state)) {
+       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,
                                     found_end, CHUNK_ALLOCATED, NULL);
                if (ret)
index f7b678b..e7a096a 100644 (file)
@@ -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,8 +4724,8 @@ 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,
-                                     mark, NULL)) {
+       while (find_first_extent_bit(dirty_pages, start, &start, &end,
+                                    mark, NULL)) {
                clear_extent_bits(dirty_pages, start, end, mark);
                while (start <= end) {
                        eb = find_extent_buffer(fs_info, start);
@@ -4759,8 +4759,8 @@ 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,
-                                         EXTENT_DIRTY, &cached_state)) {
+               if (!find_first_extent_bit(unpin, 0, &start, &end,
+                                          EXTENT_DIRTY, &cached_state)) {
                        mutex_unlock(&fs_info->unused_bg_unpin_mutex);
                        break;
                }
index a2315a4..ff8e117 100644 (file)
@@ -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,
-                         u64 *start_ret, u64 *end_ret, u32 bits,
-                         struct extent_state **cached_state)
+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 @@ got_it:
                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);
index fbd3b27..28c23a2 100644 (file)
@@ -182,9 +182,9 @@ 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,
-                         u64 *start_ret, u64 *end_ret, u32 bits,
-                         struct extent_state **cached_state);
+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,
                                 u64 *start_ret, u64 *end_ret, u32 bits);
 int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
index f396a9a..ab7b588 100644 (file)
@@ -2751,9 +2751,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
                struct extent_state *cached_state = NULL;
 
                mutex_lock(&fs_info->unused_bg_unpin_mutex);
-               ret = find_first_extent_bit(unpin, 0, &start, &end,
-                                           EXTENT_DIRTY, &cached_state);
-               if (ret) {
+               if (!find_first_extent_bit(unpin, 0, &start, &end,
+                                          EXTENT_DIRTY, &cached_state)) {
                        mutex_unlock(&fs_info->unused_bg_unpin_mutex);
                        break;
                }
index 8808004..bfc0135 100644 (file)
@@ -1219,10 +1219,9 @@ static noinline_for_stack int write_pinned_extent_entries(
        start = block_group->start;
 
        while (start < block_group->start + block_group->length) {
-               ret = find_first_extent_bit(unpin, start,
-                                           &extent_start, &extent_end,
-                                           EXTENT_DIRTY, NULL);
-               if (ret)
+               if (!find_first_extent_bit(unpin, start,
+                                          &extent_start, &extent_end,
+                                          EXTENT_DIRTY, NULL))
                        return 0;
 
                /* This pinned extent is out of our range */
index 46c3c1d..8ff0e9d 100644 (file)
@@ -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;
        while (1) {
+               bool block_found;
+
                cond_resched();
                if (rc->search_start >= last) {
                        ret = 1;
@@ -3548,11 +3550,11 @@ next:
                        goto next;
                }
 
-               ret = find_first_extent_bit(&rc->processed_blocks,
-                                           key.objectid, &start, &end,
-                                           EXTENT_DIRTY, NULL);
+               block_found = find_first_extent_bit(&rc->processed_blocks,
+                                                   key.objectid, &start, &end,
+                                                   EXTENT_DIRTY, NULL);
 
-               if (ret == 0 && start <= key.objectid) {
+               if (block_found && start <= key.objectid) {
                        btrfs_release_path(path);
                        rc->search_start = end + 1;
                } else {
index 91b6c2f..4bb9716 100644 (file)
@@ -1060,8 +1060,8 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
        u64 start = 0;
        u64 end;
 
-       while (!find_first_extent_bit(dirty_pages, start, &start, &end,
-                                     mark, &cached_state)) {
+       while (find_first_extent_bit(dirty_pages, start, &start, &end,
+                                    mark, &cached_state)) {
                bool wait_writeback = false;
 
                err = convert_extent_bit(dirty_pages, start, end,
@@ -1114,8 +1114,8 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info,
        u64 start = 0;
        u64 end;
 
-       while (!find_first_extent_bit(dirty_pages, start, &start, &end,
-                                     EXTENT_NEED_WAIT, &cached_state)) {
+       while (find_first_extent_bit(dirty_pages, start, &start, &end,
+                                    EXTENT_NEED_WAIT, &cached_state)) {
                /*
                 * Ignore -ENOMEM errors returned by clear_extent_bit().
                 * When committing the transaction, we'll remove any entries
index f47a9c4..6d3aa26 100644 (file)
@@ -1424,9 +1424,9 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
 
        lockdep_assert_held(&device->fs_info->chunk_mutex);
 
-       if (!find_first_extent_bit(&device->alloc_state, *start,
-                                  &physical_start, &physical_end,
-                                  CHUNK_ALLOCATED, NULL)) {
+       if (find_first_extent_bit(&device->alloc_state, *start,
+                                 &physical_start, &physical_end,
+                                 CHUNK_ALLOCATED, NULL)) {
 
                if (in_range(physical_start, *start, len) ||
                    in_range(*start, physical_start,