btrfs: make btrfs_find_contiguous_extent_bit() return bool instead of int
authorFilipe Manana <fdmanana@suse.com>
Mon, 7 Apr 2025 11:15:25 +0000 (12:15 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:44 +0000 (14:30 +0200)
The function needs only to return true or false, so there's no need to
return an integer. Currently it returns 0 when a range with the given
bits is set and 1 when not found, which is a bit counter intuitive too.
So change the function to return a bool instead, returning true when a
range is found and false otherwise. Update the function's documentation
to mention the return value too.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
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/extent-io-tree.c
fs/btrfs/extent-io-tree.h
fs/btrfs/file-item.c

index 11f2e195ef8d06aa380c034ccc30d0877b4fc0a5..cae3980f4291c006648f974b21a51b07e607c76b 100644 (file)
@@ -928,12 +928,15 @@ out:
  * contiguous area for given bits.  We will search to the first bit we find, and
  * then walk down the tree until we find a non-contiguous area.  The area
  * returned will be the full contiguous area with the bits set.
+ *
+ * Returns true if we found a range with the given bits set, in which case
+ * @start_ret and @end_ret are updated, or false if no range was found.
  */
-int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
-                                    u64 *start_ret, u64 *end_ret, u32 bits)
+bool btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
+                                     u64 *start_ret, u64 *end_ret, u32 bits)
 {
        struct extent_state *state;
-       int ret = 1;
+       bool ret = false;
 
        ASSERT(!btrfs_fs_incompat(btrfs_extent_io_tree_to_fs_info(tree), NO_HOLES));
 
@@ -947,7 +950,7 @@ int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
                                break;
                        *end_ret = state->end;
                }
-               ret = 0;
+               ret = true;
        }
        spin_unlock(&tree->lock);
        return ret;
index 625f4cd3debd4c63784e2994f5a50611c9029ec1..d8c01d8576674d1a4e0f9d521f18e7e17e3feb4a 100644 (file)
@@ -219,8 +219,8 @@ bool btrfs_find_first_extent_bit(struct extent_io_tree *tree, u64 start,
                                 struct extent_state **cached_state);
 void btrfs_find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
                                       u64 *start_ret, u64 *end_ret, u32 bits);
-int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
-                                    u64 *start_ret, u64 *end_ret, u32 bits);
+bool btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
+                                     u64 *start_ret, u64 *end_ret, u32 bits);
 bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
                               u64 *end, u64 max_bytes,
                               struct extent_state **cached_state);
index d2ea830ad2448261d43e4fc7e8592fc19e28aa9c..c5fb4b357100d2bc94e007e9de2c2fe04863d116 100644 (file)
@@ -46,7 +46,7 @@
 void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size)
 {
        u64 start, end, i_size;
-       int ret;
+       bool found;
 
        spin_lock(&inode->lock);
        i_size = new_i_size ?: i_size_read(&inode->vfs_inode);
@@ -55,9 +55,9 @@ void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_siz
                goto out_unlock;
        }
 
-       ret = btrfs_find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
-                                              &end, EXTENT_DIRTY);
-       if (!ret && start == 0)
+       found = btrfs_find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
+                                                &end, EXTENT_DIRTY);
+       if (found && start == 0)
                i_size = min(i_size, end + 1);
        else
                i_size = 0;