Skip to content

Commit 3522e90

Browse files
Lu Fengqikdave
Lu Fengqi
authored andcommitted
btrfs: remove always true if branch in find_delalloc_range
The @found is always false when it comes to the if branch. Besides, the bool type is more suitable for @found. Change the return value of the function and its caller to bool as well. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 27a7ff5 commit 3522e90

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

fs/btrfs/extent_io.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -1452,16 +1452,16 @@ int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
14521452
* find a contiguous range of bytes in the file marked as delalloc, not
14531453
* more than 'max_bytes'. start and end are used to return the range,
14541454
*
1455-
* 1 is returned if we find something, 0 if nothing was in the tree
1455+
* true is returned if we find something, false if nothing was in the tree
14561456
*/
1457-
static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
1457+
static noinline bool find_delalloc_range(struct extent_io_tree *tree,
14581458
u64 *start, u64 *end, u64 max_bytes,
14591459
struct extent_state **cached_state)
14601460
{
14611461
struct rb_node *node;
14621462
struct extent_state *state;
14631463
u64 cur_start = *start;
1464-
u64 found = 0;
1464+
bool found = false;
14651465
u64 total_bytes = 0;
14661466

14671467
spin_lock(&tree->lock);
@@ -1472,8 +1472,7 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
14721472
*/
14731473
node = tree_search(tree, cur_start);
14741474
if (!node) {
1475-
if (!found)
1476-
*end = (u64)-1;
1475+
*end = (u64)-1;
14771476
goto out;
14781477
}
14791478

@@ -1493,7 +1492,7 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
14931492
*cached_state = state;
14941493
refcount_inc(&state->refs);
14951494
}
1496-
found++;
1495+
found = true;
14971496
*end = state->end;
14981497
cur_start = state->end + 1;
14991498
node = rb_next(node);
@@ -1551,21 +1550,22 @@ static noinline int lock_delalloc_pages(struct inode *inode,
15511550
}
15521551

15531552
/*
1554-
* find a contiguous range of bytes in the file marked as delalloc, not
1555-
* more than 'max_bytes'. start and end are used to return the range,
1553+
* Find and lock a contiguous range of bytes in the file marked as delalloc, no
1554+
* more than @max_bytes. @Start and @end are used to return the range,
15561555
*
1557-
* 1 is returned if we find something, 0 if nothing was in the tree
1556+
* Return: true if we find something
1557+
* false if nothing was in the tree
15581558
*/
15591559
EXPORT_FOR_TESTS
1560-
noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
1560+
noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
15611561
struct extent_io_tree *tree,
15621562
struct page *locked_page, u64 *start,
15631563
u64 *end)
15641564
{
15651565
u64 max_bytes = BTRFS_MAX_EXTENT_SIZE;
15661566
u64 delalloc_start;
15671567
u64 delalloc_end;
1568-
u64 found;
1568+
bool found;
15691569
struct extent_state *cached_state = NULL;
15701570
int ret;
15711571
int loops = 0;
@@ -1580,7 +1580,7 @@ noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
15801580
*start = delalloc_start;
15811581
*end = delalloc_end;
15821582
free_extent_state(cached_state);
1583-
return 0;
1583+
return false;
15841584
}
15851585

15861586
/*
@@ -1612,7 +1612,7 @@ noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
16121612
loops = 1;
16131613
goto again;
16141614
} else {
1615-
found = 0;
1615+
found = false;
16161616
goto out_failed;
16171617
}
16181618
}
@@ -3195,19 +3195,19 @@ static noinline_for_stack int writepage_delalloc(struct inode *inode,
31953195
{
31963196
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
31973197
u64 page_end = delalloc_start + PAGE_SIZE - 1;
3198-
u64 nr_delalloc;
3198+
bool found;
31993199
u64 delalloc_to_write = 0;
32003200
u64 delalloc_end = 0;
32013201
int ret;
32023202
int page_started = 0;
32033203

32043204

32053205
while (delalloc_end < page_end) {
3206-
nr_delalloc = find_lock_delalloc_range(inode, tree,
3206+
found = find_lock_delalloc_range(inode, tree,
32073207
page,
32083208
&delalloc_start,
32093209
&delalloc_end);
3210-
if (nr_delalloc == 0) {
3210+
if (!found) {
32113211
delalloc_start = delalloc_end + 1;
32123212
continue;
32133213
}

fs/btrfs/extent_io.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ int free_io_failure(struct extent_io_tree *failure_tree,
525525
struct extent_io_tree *io_tree,
526526
struct io_failure_record *rec);
527527
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
528-
u64 find_lock_delalloc_range(struct inode *inode, struct extent_io_tree *tree,
528+
bool find_lock_delalloc_range(struct inode *inode, struct extent_io_tree *tree,
529529
struct page *locked_page, u64 *start,
530530
u64 *end);
531531
#endif

fs/btrfs/tests/extent-io-tests.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int test_find_delalloc(u32 sectorsize)
6666
u64 max_bytes = BTRFS_MAX_EXTENT_SIZE;
6767
u64 total_dirty = 2 * max_bytes;
6868
u64 start, end, test_start;
69-
u64 found;
69+
bool found;
7070
int ret = -EINVAL;
7171

7272
test_msg("running find delalloc tests");

0 commit comments

Comments
 (0)