mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
btrfs: replace btrfs_set_free_space_cache_v1_active() with a cleanup helper
The only caller passes active = false. Turn it into btrfs_cleanup_free_space_cache_v1() and fold the block group loop into it. Assisted-by: LLM Signed-off-by: Tal Zussman <tz2294@columbia.edu> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
3d10f3cc05
commit
9fb023c34f
|
|
@ -3152,7 +3152,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
|
|||
}
|
||||
|
||||
if (btrfs_free_space_cache_v1_active(fs_info)) {
|
||||
ret = btrfs_set_free_space_cache_v1_active(fs_info, false);
|
||||
ret = btrfs_cleanup_free_space_cache_v1(fs_info);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2901,47 +2901,29 @@ bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info)
|
|||
return btrfs_super_cache_generation(fs_info->super_copy);
|
||||
}
|
||||
|
||||
static int cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_trans_handle *trans)
|
||||
int btrfs_cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info)
|
||||
{
|
||||
struct btrfs_block_group *block_group;
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct rb_node *node;
|
||||
int ret;
|
||||
|
||||
btrfs_info(fs_info, "cleaning free space cache v1");
|
||||
|
||||
node = rb_first_cached(&fs_info->block_group_cache_tree);
|
||||
while (node) {
|
||||
int ret;
|
||||
|
||||
block_group = rb_entry(node, struct btrfs_block_group, cache_node);
|
||||
ret = btrfs_remove_free_space_inode(trans, NULL, block_group);
|
||||
if (ret)
|
||||
return ret;
|
||||
node = rb_next(node);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, bool active)
|
||||
{
|
||||
struct btrfs_trans_handle *trans;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* update_super_roots will appropriately set or unset
|
||||
* super_copy->cache_generation based on SPACE_CACHE and
|
||||
* BTRFS_FS_CLEANUP_SPACE_CACHE_V1. For this reason, we need a
|
||||
* transaction commit whether we are enabling space cache v1 and don't
|
||||
* have any other work to do, or are disabling it and removing free
|
||||
* space inodes.
|
||||
* update_super_roots() zeroes super_copy->cache_generation while
|
||||
* BTRFS_FS_CLEANUP_SPACE_CACHE_V1 is set, so this needs a commit.
|
||||
*/
|
||||
trans = btrfs_start_transaction(fs_info->tree_root, 0);
|
||||
if (IS_ERR(trans))
|
||||
return PTR_ERR(trans);
|
||||
|
||||
if (!active) {
|
||||
set_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags);
|
||||
ret = cleanup_free_space_cache_v1(fs_info, trans);
|
||||
set_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags);
|
||||
for (node = rb_first_cached(&fs_info->block_group_cache_tree); node;
|
||||
node = rb_next(node)) {
|
||||
struct btrfs_block_group *block_group;
|
||||
|
||||
block_group = rb_entry(node, struct btrfs_block_group, cache_node);
|
||||
ret = btrfs_remove_free_space_inode(trans, NULL, block_group);
|
||||
if (unlikely(ret)) {
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
btrfs_end_transaction(trans);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group,
|
|||
void btrfs_trim_fully_remapped_block_group(struct btrfs_block_group *bg);
|
||||
|
||||
bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info);
|
||||
int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, bool active);
|
||||
int btrfs_cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info);
|
||||
/* Support functions for running our sanity tests */
|
||||
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
|
||||
bool btrfs_use_bitmap(struct btrfs_free_space_ctl *ctl,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user