Skip to content

Commit 7939dd9

Browse files
josefbacikkdave
authored andcommitted
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: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent fc28b25 commit 7939dd9

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ struct btrfs_fs_info {
631631
struct btrfs_root *_csum_root;
632632
struct btrfs_root *quota_root;
633633
struct btrfs_root *uuid_root;
634-
struct btrfs_root *free_space_root;
634+
struct btrfs_root *_free_space_root;
635635
struct btrfs_root *data_reloc_root;
636636

637637
/* the log root tree is a directory of all the other log roots */

fs/btrfs/disk-io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
15711571
return btrfs_grab_root(fs_info->uuid_root) ?
15721572
fs_info->uuid_root : ERR_PTR(-ENOENT);
15731573
if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID)
1574-
return btrfs_grab_root(fs_info->free_space_root) ?
1575-
fs_info->free_space_root : ERR_PTR(-ENOENT);
1574+
return btrfs_grab_root(fs_info->_free_space_root) ?
1575+
fs_info->_free_space_root : ERR_PTR(-ENOENT);
15761576
return NULL;
15771577
}
15781578

@@ -1637,7 +1637,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
16371637
btrfs_put_root(fs_info->_csum_root);
16381638
btrfs_put_root(fs_info->quota_root);
16391639
btrfs_put_root(fs_info->uuid_root);
1640-
btrfs_put_root(fs_info->free_space_root);
1640+
btrfs_put_root(fs_info->_free_space_root);
16411641
btrfs_put_root(fs_info->fs_root);
16421642
btrfs_put_root(fs_info->data_reloc_root);
16431643
btrfs_check_leaked_roots(fs_info);
@@ -2176,7 +2176,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
21762176
free_root_extent_buffers(info->data_reloc_root);
21772177
if (free_chunk_root)
21782178
free_root_extent_buffers(info->chunk_root);
2179-
free_root_extent_buffers(info->free_space_root);
2179+
free_root_extent_buffers(info->_free_space_root);
21802180
}
21812181

21822182
void btrfs_put_root(struct btrfs_root *root)
@@ -2542,7 +2542,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
25422542
}
25432543
} else {
25442544
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2545-
fs_info->free_space_root = root;
2545+
fs_info->_free_space_root = root;
25462546
}
25472547
}
25482548

fs/btrfs/free-space-tree.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
1616
struct btrfs_block_group *block_group,
1717
struct btrfs_path *path);
1818

19+
static struct btrfs_root *btrfs_free_space_root(
20+
struct btrfs_block_group *block_group)
21+
{
22+
return block_group->fs_info->_free_space_root;
23+
}
24+
1925
void set_free_space_tree_thresholds(struct btrfs_block_group *cache)
2026
{
2127
u32 bitmap_range;
@@ -51,7 +57,7 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans,
5157
struct btrfs_block_group *block_group,
5258
struct btrfs_path *path)
5359
{
54-
struct btrfs_root *root = trans->fs_info->free_space_root;
60+
struct btrfs_root *root = btrfs_free_space_root(block_group);
5561
struct btrfs_free_space_info *info;
5662
struct btrfs_key key;
5763
struct extent_buffer *leaf;
@@ -85,7 +91,7 @@ struct btrfs_free_space_info *search_free_space_info(
8591
struct btrfs_path *path, int cow)
8692
{
8793
struct btrfs_fs_info *fs_info = block_group->fs_info;
88-
struct btrfs_root *root = fs_info->free_space_root;
94+
struct btrfs_root *root = btrfs_free_space_root(block_group);
8995
struct btrfs_key key;
9096
int ret;
9197

@@ -188,7 +194,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
188194
struct btrfs_path *path)
189195
{
190196
struct btrfs_fs_info *fs_info = trans->fs_info;
191-
struct btrfs_root *root = fs_info->free_space_root;
197+
struct btrfs_root *root = btrfs_free_space_root(block_group);
192198
struct btrfs_free_space_info *info;
193199
struct btrfs_key key, found_key;
194200
struct extent_buffer *leaf;
@@ -326,7 +332,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
326332
struct btrfs_path *path)
327333
{
328334
struct btrfs_fs_info *fs_info = trans->fs_info;
329-
struct btrfs_root *root = fs_info->free_space_root;
335+
struct btrfs_root *root = btrfs_free_space_root(block_group);
330336
struct btrfs_free_space_info *info;
331337
struct btrfs_key key, found_key;
332338
struct extent_buffer *leaf;
@@ -586,7 +592,7 @@ static int modify_free_space_bitmap(struct btrfs_trans_handle *trans,
586592
struct btrfs_path *path,
587593
u64 start, u64 size, int remove)
588594
{
589-
struct btrfs_root *root = block_group->fs_info->free_space_root;
595+
struct btrfs_root *root = btrfs_free_space_root(block_group);
590596
struct btrfs_key key;
591597
u64 end = start + size;
592598
u64 cur_start, cur_size;
@@ -699,7 +705,7 @@ static int remove_free_space_extent(struct btrfs_trans_handle *trans,
699705
struct btrfs_path *path,
700706
u64 start, u64 size)
701707
{
702-
struct btrfs_root *root = trans->fs_info->free_space_root;
708+
struct btrfs_root *root = btrfs_free_space_root(block_group);
703709
struct btrfs_key key;
704710
u64 found_start, found_end;
705711
u64 end = start + size;
@@ -851,7 +857,7 @@ static int add_free_space_extent(struct btrfs_trans_handle *trans,
851857
struct btrfs_path *path,
852858
u64 start, u64 size)
853859
{
854-
struct btrfs_root *root = trans->fs_info->free_space_root;
860+
struct btrfs_root *root = btrfs_free_space_root(block_group);
855861
struct btrfs_key key, new_key;
856862
u64 found_start, found_end;
857863
u64 end = start + size;
@@ -1158,7 +1164,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
11581164
ret = PTR_ERR(free_space_root);
11591165
goto abort;
11601166
}
1161-
fs_info->free_space_root = free_space_root;
1167+
fs_info->_free_space_root = free_space_root;
11621168

11631169
node = rb_first(&fs_info->block_group_cache_tree);
11641170
while (node) {
@@ -1233,7 +1239,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
12331239
{
12341240
struct btrfs_trans_handle *trans;
12351241
struct btrfs_root *tree_root = fs_info->tree_root;
1236-
struct btrfs_root *free_space_root = fs_info->free_space_root;
1242+
struct btrfs_root *free_space_root = fs_info->_free_space_root;
12371243
int ret;
12381244

12391245
trans = btrfs_start_transaction(tree_root, 0);
@@ -1242,7 +1248,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
12421248

12431249
btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE);
12441250
btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID);
1245-
fs_info->free_space_root = NULL;
1251+
fs_info->_free_space_root = NULL;
12461252

12471253
ret = clear_free_space_tree(trans, free_space_root);
12481254
if (ret)
@@ -1320,7 +1326,7 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
13201326
int remove_block_group_free_space(struct btrfs_trans_handle *trans,
13211327
struct btrfs_block_group *block_group)
13221328
{
1323-
struct btrfs_root *root = trans->fs_info->free_space_root;
1329+
struct btrfs_root *root = btrfs_free_space_root(block_group);
13241330
struct btrfs_path *path;
13251331
struct btrfs_key key, found_key;
13261332
struct extent_buffer *leaf;
@@ -1411,7 +1417,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
14111417

14121418
block_group = caching_ctl->block_group;
14131419
fs_info = block_group->fs_info;
1414-
root = fs_info->free_space_root;
1420+
root = btrfs_free_space_root(block_group);
14151421

14161422
end = block_group->start + block_group->length;
14171423

@@ -1489,7 +1495,7 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
14891495

14901496
block_group = caching_ctl->block_group;
14911497
fs_info = block_group->fs_info;
1492-
root = fs_info->free_space_root;
1498+
root = btrfs_free_space_root(block_group);
14931499

14941500
end = block_group->start + block_group->length;
14951501

fs/btrfs/tests/free-space-tree-tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
446446

447447
btrfs_set_super_compat_ro_flags(root->fs_info->super_copy,
448448
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE);
449-
root->fs_info->free_space_root = root;
449+
root->fs_info->_free_space_root = root;
450450
root->fs_info->tree_root = root;
451451

452452
root->node = alloc_test_extent_buffer(root->fs_info, nodesize);

0 commit comments

Comments
 (0)