Skip to content

Commit c8c2c65

Browse files
fdmananakdave
authored andcommitted
btrfs: make free_space_test_bit() return a boolean instead
The function returns the result of another function that returns a boolean (extent_buffer_test_bit()), and all the callers need is a boolean an not an integer. So change its return type from int to bool, and modify the callers to store results in booleans instead of integers, which also makes them simpler. Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c0e2b25 commit c8c2c65

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

fs/btrfs/free-space-tree.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ static int update_free_space_extent_count(struct btrfs_trans_handle *trans,
513513
}
514514

515515
EXPORT_FOR_TESTS
516-
int free_space_test_bit(struct btrfs_block_group *block_group,
517-
struct btrfs_path *path, u64 offset)
516+
bool free_space_test_bit(struct btrfs_block_group *block_group,
517+
struct btrfs_path *path, u64 offset)
518518
{
519519
struct extent_buffer *leaf;
520520
struct btrfs_key key;
@@ -612,7 +612,8 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
612612
struct btrfs_key key;
613613
u64 end = start + size;
614614
u64 cur_start, cur_size;
615-
int prev_bit, next_bit;
615+
bool prev_bit_set = false;
616+
bool next_bit_set = false;
616617
int new_extents;
617618
int ret;
618619

@@ -631,7 +632,7 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
631632
if (ret)
632633
goto out;
633634

634-
prev_bit = free_space_test_bit(block_group, path, prev_block);
635+
prev_bit_set = free_space_test_bit(block_group, path, prev_block);
635636

636637
/* The previous block may have been in the previous bitmap. */
637638
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
@@ -648,8 +649,6 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
648649
ret = btrfs_search_prev_slot(trans, root, &key, path, 0, 1);
649650
if (ret)
650651
goto out;
651-
652-
prev_bit = -1;
653652
}
654653

655654
/*
@@ -681,28 +680,26 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
681680
goto out;
682681
}
683682

684-
next_bit = free_space_test_bit(block_group, path, end);
685-
} else {
686-
next_bit = -1;
683+
next_bit_set = free_space_test_bit(block_group, path, end);
687684
}
688685

689686
if (remove) {
690687
new_extents = -1;
691-
if (prev_bit == 1) {
688+
if (prev_bit_set) {
692689
/* Leftover on the left. */
693690
new_extents++;
694691
}
695-
if (next_bit == 1) {
692+
if (next_bit_set) {
696693
/* Leftover on the right. */
697694
new_extents++;
698695
}
699696
} else {
700697
new_extents = 1;
701-
if (prev_bit == 1) {
698+
if (prev_bit_set) {
702699
/* Merging with neighbor on the left. */
703700
new_extents--;
704701
}
705-
if (next_bit == 1) {
702+
if (next_bit_set) {
706703
/* Merging with neighbor on the right. */
707704
new_extents--;
708705
}
@@ -1552,7 +1549,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
15521549
struct btrfs_fs_info *fs_info;
15531550
struct btrfs_root *root;
15541551
struct btrfs_key key;
1555-
int prev_bit = 0, bit;
1552+
bool prev_bit_set = false;
15561553
/* Initialize to silence GCC. */
15571554
u64 extent_start = 0;
15581555
u64 end, offset;
@@ -1583,10 +1580,12 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
15831580

15841581
offset = key.objectid;
15851582
while (offset < key.objectid + key.offset) {
1586-
bit = free_space_test_bit(block_group, path, offset);
1587-
if (prev_bit == 0 && bit == 1) {
1583+
bool bit_set;
1584+
1585+
bit_set = free_space_test_bit(block_group, path, offset);
1586+
if (!prev_bit_set && bit_set) {
15881587
extent_start = offset;
1589-
} else if (prev_bit == 1 && bit == 0) {
1588+
} else if (prev_bit_set && !bit_set) {
15901589
u64 space_added;
15911590

15921591
ret = btrfs_add_new_free_space(block_group,
@@ -1602,11 +1601,11 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
16021601
}
16031602
extent_count++;
16041603
}
1605-
prev_bit = bit;
1604+
prev_bit_set = bit_set;
16061605
offset += fs_info->sectorsize;
16071606
}
16081607
}
1609-
if (prev_bit == 1) {
1608+
if (prev_bit_set) {
16101609
ret = btrfs_add_new_free_space(block_group, extent_start, end, NULL);
16111610
if (ret)
16121611
goto out;

fs/btrfs/free-space-tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
5353
int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
5454
struct btrfs_block_group *block_group,
5555
struct btrfs_path *path);
56-
int free_space_test_bit(struct btrfs_block_group *block_group,
57-
struct btrfs_path *path, u64 offset);
56+
bool free_space_test_bit(struct btrfs_block_group *block_group,
57+
struct btrfs_path *path, u64 offset);
5858
#endif
5959

6060
#endif

0 commit comments

Comments
 (0)