Skip to content

Commit 1693d54

Browse files
fdmananakdave
authored andcommitted
btrfs: add and use helper to check if block group is used
Add a helper function to determine if a block group is being used and make use of it at btrfs_delete_unused_bgs(). This helper will also be used in future code changes. Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Josef Bacik <[email protected]> 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 5571e41 commit 1693d54

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

fs/btrfs/block-group.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
15121512
}
15131513

15141514
spin_lock(&block_group->lock);
1515-
if (block_group->reserved || block_group->pinned ||
1516-
block_group->used || block_group->ro ||
1515+
if (btrfs_is_block_group_used(block_group) || block_group->ro ||
15171516
list_is_singular(&block_group->list)) {
15181517
/*
15191518
* We want to bail if we made new allocations or have

fs/btrfs/block-group.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group)
257257
return (block_group->start + block_group->length);
258258
}
259259

260+
static inline bool btrfs_is_block_group_used(const struct btrfs_block_group *bg)
261+
{
262+
lockdep_assert_held(&bg->lock);
263+
264+
return (bg->used > 0 || bg->reserved > 0 || bg->pinned > 0);
265+
}
266+
260267
static inline bool btrfs_is_block_group_data_only(
261268
struct btrfs_block_group *block_group)
262269
{

0 commit comments

Comments
 (0)