Commit 7939dd9f authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: stop accessing ->free_space_root directly

We're going to have multiple free space roots in the future, so adjust
all the users of the free space root to use a helper to access the root.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fc28b25e
...@@ -631,7 +631,7 @@ struct btrfs_fs_info { ...@@ -631,7 +631,7 @@ struct btrfs_fs_info {
struct btrfs_root *_csum_root; struct btrfs_root *_csum_root;
struct btrfs_root *quota_root; struct btrfs_root *quota_root;
struct btrfs_root *uuid_root; struct btrfs_root *uuid_root;
struct btrfs_root *free_space_root; struct btrfs_root *_free_space_root;
struct btrfs_root *data_reloc_root; struct btrfs_root *data_reloc_root;
/* the log root tree is a directory of all the other log roots */ /* the log root tree is a directory of all the other log roots */
......
...@@ -1571,8 +1571,8 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, ...@@ -1571,8 +1571,8 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
return btrfs_grab_root(fs_info->uuid_root) ? return btrfs_grab_root(fs_info->uuid_root) ?
fs_info->uuid_root : ERR_PTR(-ENOENT); fs_info->uuid_root : ERR_PTR(-ENOENT);
if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID)
return btrfs_grab_root(fs_info->free_space_root) ? return btrfs_grab_root(fs_info->_free_space_root) ?
fs_info->free_space_root : ERR_PTR(-ENOENT); fs_info->_free_space_root : ERR_PTR(-ENOENT);
return NULL; return NULL;
} }
...@@ -1637,7 +1637,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) ...@@ -1637,7 +1637,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
btrfs_put_root(fs_info->_csum_root); btrfs_put_root(fs_info->_csum_root);
btrfs_put_root(fs_info->quota_root); btrfs_put_root(fs_info->quota_root);
btrfs_put_root(fs_info->uuid_root); btrfs_put_root(fs_info->uuid_root);
btrfs_put_root(fs_info->free_space_root); btrfs_put_root(fs_info->_free_space_root);
btrfs_put_root(fs_info->fs_root); btrfs_put_root(fs_info->fs_root);
btrfs_put_root(fs_info->data_reloc_root); btrfs_put_root(fs_info->data_reloc_root);
btrfs_check_leaked_roots(fs_info); btrfs_check_leaked_roots(fs_info);
...@@ -2176,7 +2176,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root) ...@@ -2176,7 +2176,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
free_root_extent_buffers(info->data_reloc_root); free_root_extent_buffers(info->data_reloc_root);
if (free_chunk_root) if (free_chunk_root)
free_root_extent_buffers(info->chunk_root); free_root_extent_buffers(info->chunk_root);
free_root_extent_buffers(info->free_space_root); free_root_extent_buffers(info->_free_space_root);
} }
void btrfs_put_root(struct btrfs_root *root) void btrfs_put_root(struct btrfs_root *root)
...@@ -2542,7 +2542,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) ...@@ -2542,7 +2542,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
} }
} else { } else {
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
fs_info->free_space_root = root; fs_info->_free_space_root = root;
} }
} }
......
...@@ -16,6 +16,12 @@ static int __add_block_group_free_space(struct btrfs_trans_handle *trans, ...@@ -16,6 +16,12 @@ static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group, struct btrfs_block_group *block_group,
struct btrfs_path *path); struct btrfs_path *path);
static struct btrfs_root *btrfs_free_space_root(
struct btrfs_block_group *block_group)
{
return block_group->fs_info->_free_space_root;
}
void set_free_space_tree_thresholds(struct btrfs_block_group *cache) void set_free_space_tree_thresholds(struct btrfs_block_group *cache)
{ {
u32 bitmap_range; u32 bitmap_range;
...@@ -51,7 +57,7 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans, ...@@ -51,7 +57,7 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group, struct btrfs_block_group *block_group,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_root *root = trans->fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_free_space_info *info; struct btrfs_free_space_info *info;
struct btrfs_key key; struct btrfs_key key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -85,7 +91,7 @@ struct btrfs_free_space_info *search_free_space_info( ...@@ -85,7 +91,7 @@ struct btrfs_free_space_info *search_free_space_info(
struct btrfs_path *path, int cow) struct btrfs_path *path, int cow)
{ {
struct btrfs_fs_info *fs_info = block_group->fs_info; struct btrfs_fs_info *fs_info = block_group->fs_info;
struct btrfs_root *root = fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
...@@ -188,7 +194,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, ...@@ -188,7 +194,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root = fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_free_space_info *info; struct btrfs_free_space_info *info;
struct btrfs_key key, found_key; struct btrfs_key key, found_key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -326,7 +332,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, ...@@ -326,7 +332,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root = fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_free_space_info *info; struct btrfs_free_space_info *info;
struct btrfs_key key, found_key; struct btrfs_key key, found_key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -586,7 +592,7 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans, ...@@ -586,7 +592,7 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
struct btrfs_path *path, struct btrfs_path *path,
u64 start, u64 size, int remove) u64 start, u64 size, int remove)
{ {
struct btrfs_root *root = block_group->fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_key key; struct btrfs_key key;
u64 end = start + size; u64 end = start + size;
u64 cur_start, cur_size; u64 cur_start, cur_size;
...@@ -699,7 +705,7 @@ static int remove_free_space_extent(struct btrfs_trans_handle *trans, ...@@ -699,7 +705,7 @@ static int remove_free_space_extent(struct btrfs_trans_handle *trans,
struct btrfs_path *path, struct btrfs_path *path,
u64 start, u64 size) u64 start, u64 size)
{ {
struct btrfs_root *root = trans->fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_key key; struct btrfs_key key;
u64 found_start, found_end; u64 found_start, found_end;
u64 end = start + size; u64 end = start + size;
...@@ -851,7 +857,7 @@ static int add_free_space_extent(struct btrfs_trans_handle *trans, ...@@ -851,7 +857,7 @@ static int add_free_space_extent(struct btrfs_trans_handle *trans,
struct btrfs_path *path, struct btrfs_path *path,
u64 start, u64 size) u64 start, u64 size)
{ {
struct btrfs_root *root = trans->fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_key key, new_key; struct btrfs_key key, new_key;
u64 found_start, found_end; u64 found_start, found_end;
u64 end = start + size; u64 end = start + size;
...@@ -1158,7 +1164,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1158,7 +1164,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
ret = PTR_ERR(free_space_root); ret = PTR_ERR(free_space_root);
goto abort; goto abort;
} }
fs_info->free_space_root = free_space_root; fs_info->_free_space_root = free_space_root;
node = rb_first(&fs_info->block_group_cache_tree); node = rb_first(&fs_info->block_group_cache_tree);
while (node) { while (node) {
...@@ -1233,7 +1239,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1233,7 +1239,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
{ {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_root *tree_root = fs_info->tree_root; struct btrfs_root *tree_root = fs_info->tree_root;
struct btrfs_root *free_space_root = fs_info->free_space_root; struct btrfs_root *free_space_root = fs_info->_free_space_root;
int ret; int ret;
trans = btrfs_start_transaction(tree_root, 0); trans = btrfs_start_transaction(tree_root, 0);
...@@ -1242,7 +1248,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1242,7 +1248,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE); btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE);
btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID); btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID);
fs_info->free_space_root = NULL; fs_info->_free_space_root = NULL;
ret = clear_free_space_tree(trans, free_space_root); ret = clear_free_space_tree(trans, free_space_root);
if (ret) if (ret)
...@@ -1320,7 +1326,7 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans, ...@@ -1320,7 +1326,7 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
int remove_block_group_free_space(struct btrfs_trans_handle *trans, int remove_block_group_free_space(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group) struct btrfs_block_group *block_group)
{ {
struct btrfs_root *root = trans->fs_info->free_space_root; struct btrfs_root *root = btrfs_free_space_root(block_group);
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_key key, found_key; struct btrfs_key key, found_key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -1411,7 +1417,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl, ...@@ -1411,7 +1417,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
block_group = caching_ctl->block_group; block_group = caching_ctl->block_group;
fs_info = block_group->fs_info; fs_info = block_group->fs_info;
root = fs_info->free_space_root; root = btrfs_free_space_root(block_group);
end = block_group->start + block_group->length; end = block_group->start + block_group->length;
...@@ -1489,7 +1495,7 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl, ...@@ -1489,7 +1495,7 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
block_group = caching_ctl->block_group; block_group = caching_ctl->block_group;
fs_info = block_group->fs_info; fs_info = block_group->fs_info;
root = fs_info->free_space_root; root = btrfs_free_space_root(block_group);
end = block_group->start + block_group->length; end = block_group->start + block_group->length;
......
...@@ -446,7 +446,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize, ...@@ -446,7 +446,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
btrfs_set_super_compat_ro_flags(root->fs_info->super_copy, btrfs_set_super_compat_ro_flags(root->fs_info->super_copy,
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE); BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE);
root->fs_info->free_space_root = root; root->fs_info->_free_space_root = root;
root->fs_info->tree_root = root; root->fs_info->tree_root = root;
root->node = alloc_test_extent_buffer(root->fs_info, nodesize); root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment