Skip to content

Commit 41108cf

Browse files
fdmananakdave
authored andcommitted
btrfs: make btrfs_find_contiguous_extent_bit() return bool instead of int
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 <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 18d71b1 commit 41108cf

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

fs/btrfs/extent-io-tree.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,12 +928,15 @@ bool btrfs_find_first_extent_bit(struct extent_io_tree *tree, u64 start,
928928
* contiguous area for given bits. We will search to the first bit we find, and
929929
* then walk down the tree until we find a non-contiguous area. The area
930930
* returned will be the full contiguous area with the bits set.
931+
*
932+
* Returns true if we found a range with the given bits set, in which case
933+
* @start_ret and @end_ret are updated, or false if no range was found.
931934
*/
932-
int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
933-
u64 *start_ret, u64 *end_ret, u32 bits)
935+
bool btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
936+
u64 *start_ret, u64 *end_ret, u32 bits)
934937
{
935938
struct extent_state *state;
936-
int ret = 1;
939+
bool ret = false;
937940

938941
ASSERT(!btrfs_fs_incompat(btrfs_extent_io_tree_to_fs_info(tree), NO_HOLES));
939942

@@ -947,7 +950,7 @@ int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
947950
break;
948951
*end_ret = state->end;
949952
}
950-
ret = 0;
953+
ret = true;
951954
}
952955
spin_unlock(&tree->lock);
953956
return ret;

fs/btrfs/extent-io-tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ bool btrfs_find_first_extent_bit(struct extent_io_tree *tree, u64 start,
219219
struct extent_state **cached_state);
220220
void btrfs_find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
221221
u64 *start_ret, u64 *end_ret, u32 bits);
222-
int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
223-
u64 *start_ret, u64 *end_ret, u32 bits);
222+
bool btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
223+
u64 *start_ret, u64 *end_ret, u32 bits);
224224
bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
225225
u64 *end, u64 max_bytes,
226226
struct extent_state **cached_state);

fs/btrfs/file-item.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size)
4747
{
4848
u64 start, end, i_size;
49-
int ret;
49+
bool found;
5050

5151
spin_lock(&inode->lock);
5252
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
5555
goto out_unlock;
5656
}
5757

58-
ret = btrfs_find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
59-
&end, EXTENT_DIRTY);
60-
if (!ret && start == 0)
58+
found = btrfs_find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
59+
&end, EXTENT_DIRTY);
60+
if (found && start == 0)
6161
i_size = min(i_size, end + 1);
6262
else
6363
i_size = 0;

0 commit comments

Comments
 (0)