Skip to content

Commit 29cbcf4

Browse files
josefbacikkdave
authored andcommitted
btrfs: stop accessing ->extent_root directly
When we start having multiple extent roots we'll need to use a helper to get to the correct extent_root. Rename fs_info->extent_root to _extent_root and convert all of the users of the extent root to using the btrfs_extent_root() helper. This will allow us to easily clean up the remaining direct accesses in the future. Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2e608bd commit 29cbcf4

16 files changed

+77
-44
lines changed

fs/btrfs/backref.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
11701170
struct ulist *roots, const u64 *extent_item_pos,
11711171
struct share_check *sc, bool ignore_offset)
11721172
{
1173-
struct btrfs_root *root = fs_info->extent_root;
1173+
struct btrfs_root *root = btrfs_extent_root(fs_info, bytenr);
11741174
struct btrfs_key key;
11751175
struct btrfs_path *path;
11761176
struct btrfs_delayed_ref_root *delayed_refs = NULL;
@@ -1747,6 +1747,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
17471747
struct btrfs_path *path, struct btrfs_key *found_key,
17481748
u64 *flags_ret)
17491749
{
1750+
struct btrfs_root *extent_root = btrfs_extent_root(fs_info, logical);
17501751
int ret;
17511752
u64 flags;
17521753
u64 size = 0;
@@ -1762,11 +1763,11 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
17621763
key.objectid = logical;
17631764
key.offset = (u64)-1;
17641765

1765-
ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
1766+
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
17661767
if (ret < 0)
17671768
return ret;
17681769

1769-
ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0);
1770+
ret = btrfs_previous_extent_item(extent_root, path, 0);
17701771
if (ret) {
17711772
if (ret > 0)
17721773
ret = -ENOENT;
@@ -2335,6 +2336,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(
23352336
int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
23362337
{
23372338
struct btrfs_fs_info *fs_info = iter->fs_info;
2339+
struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
23382340
struct btrfs_path *path = iter->path;
23392341
struct btrfs_extent_item *ei;
23402342
struct btrfs_key key;
@@ -2345,7 +2347,7 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
23452347
key.offset = (u64)-1;
23462348
iter->bytenr = bytenr;
23472349

2348-
ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
2350+
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
23492351
if (ret < 0)
23502352
return ret;
23512353
if (ret == 0) {
@@ -2388,7 +2390,7 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
23882390

23892391
/* If there is no inline backref, go search for keyed backref */
23902392
if (iter->cur_ptr >= iter->end_ptr) {
2391-
ret = btrfs_next_item(fs_info->extent_root, path);
2393+
ret = btrfs_next_item(extent_root, path);
23922394

23932395
/* No inline nor keyed ref */
23942396
if (ret > 0) {
@@ -2432,6 +2434,7 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
24322434
int btrfs_backref_iter_next(struct btrfs_backref_iter *iter)
24332435
{
24342436
struct extent_buffer *eb = btrfs_backref_get_eb(iter);
2437+
struct btrfs_root *extent_root;
24352438
struct btrfs_path *path = iter->path;
24362439
struct btrfs_extent_inline_ref *iref;
24372440
int ret;
@@ -2462,7 +2465,8 @@ int btrfs_backref_iter_next(struct btrfs_backref_iter *iter)
24622465
}
24632466

24642467
/* We're at keyed items, there is no inline item, go to the next one */
2465-
ret = btrfs_next_item(iter->fs_info->extent_root, iter->path);
2468+
extent_root = btrfs_extent_root(iter->fs_info, iter->bytenr);
2469+
ret = btrfs_next_item(extent_root, iter->path);
24662470
if (ret)
24672471
return ret;
24682472

fs/btrfs/block-group.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
514514
{
515515
struct btrfs_block_group *block_group = caching_ctl->block_group;
516516
struct btrfs_fs_info *fs_info = block_group->fs_info;
517-
struct btrfs_root *extent_root = fs_info->extent_root;
517+
struct btrfs_root *extent_root;
518518
struct btrfs_path *path;
519519
struct extent_buffer *leaf;
520520
struct btrfs_key key;
@@ -529,6 +529,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
529529
return -ENOMEM;
530530

531531
last = max_t(u64, block_group->start, BTRFS_SUPER_INFO_OFFSET);
532+
extent_root = btrfs_extent_root(fs_info, last);
532533

533534
#ifdef CONFIG_BTRFS_DEBUG
534535
/*

fs/btrfs/block-rsv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "space-info.h"
77
#include "transaction.h"
88
#include "block-group.h"
9+
#include "disk-io.h"
910

1011
/*
1112
* HOW DO BLOCK RESERVES WORK
@@ -351,6 +352,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
351352
{
352353
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
353354
struct btrfs_space_info *sinfo = block_rsv->space_info;
355+
struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
354356
u64 num_bytes;
355357
unsigned min_items;
356358

@@ -359,7 +361,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
359361
* checksum tree and the root tree. If the fs is empty we want to set
360362
* it to a minimal amount for safety.
361363
*/
362-
num_bytes = btrfs_root_used(&fs_info->extent_root->root_item) +
364+
num_bytes = btrfs_root_used(&extent_root->root_item) +
363365
btrfs_root_used(&fs_info->csum_root->root_item) +
364366
btrfs_root_used(&fs_info->tree_root->root_item);
365367

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ enum btrfs_exclusive_operation {
621621
struct btrfs_fs_info {
622622
u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
623623
unsigned long flags;
624-
struct btrfs_root *extent_root;
624+
struct btrfs_root *_extent_root;
625625
struct btrfs_root *tree_root;
626626
struct btrfs_root *chunk_root;
627627
struct btrfs_root *dev_root;

fs/btrfs/disk-io.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
15571557
if (objectid == BTRFS_ROOT_TREE_OBJECTID)
15581558
return btrfs_grab_root(fs_info->tree_root);
15591559
if (objectid == BTRFS_EXTENT_TREE_OBJECTID)
1560-
return btrfs_grab_root(fs_info->extent_root);
1560+
return btrfs_grab_root(fs_info->_extent_root);
15611561
if (objectid == BTRFS_CHUNK_TREE_OBJECTID)
15621562
return btrfs_grab_root(fs_info->chunk_root);
15631563
if (objectid == BTRFS_DEV_TREE_OBJECTID)
@@ -1630,7 +1630,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
16301630
btrfs_free_ref_cache(fs_info);
16311631
kfree(fs_info->balance_ctl);
16321632
kfree(fs_info->delayed_root);
1633-
btrfs_put_root(fs_info->extent_root);
1633+
btrfs_put_root(fs_info->_extent_root);
16341634
btrfs_put_root(fs_info->tree_root);
16351635
btrfs_put_root(fs_info->chunk_root);
16361636
btrfs_put_root(fs_info->dev_root);
@@ -2008,6 +2008,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
20082008
{
20092009
const int next_backup = info->backup_root_index;
20102010
struct btrfs_root_backup *root_backup;
2011+
struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
20112012

20122013
root_backup = info->super_for_commit->super_roots + next_backup;
20132014

@@ -2032,11 +2033,11 @@ static void backup_super_roots(struct btrfs_fs_info *info)
20322033
btrfs_set_backup_chunk_root_level(root_backup,
20332034
btrfs_header_level(info->chunk_root->node));
20342035

2035-
btrfs_set_backup_extent_root(root_backup, info->extent_root->node->start);
2036+
btrfs_set_backup_extent_root(root_backup, extent_root->node->start);
20362037
btrfs_set_backup_extent_root_gen(root_backup,
2037-
btrfs_header_generation(info->extent_root->node));
2038+
btrfs_header_generation(extent_root->node));
20382039
btrfs_set_backup_extent_root_level(root_backup,
2039-
btrfs_header_level(info->extent_root->node));
2040+
btrfs_header_level(extent_root->node));
20402041

20412042
/*
20422043
* we might commit during log recovery, which happens before we set
@@ -2166,7 +2167,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
21662167
free_root_extent_buffers(info->tree_root);
21672168

21682169
free_root_extent_buffers(info->dev_root);
2169-
free_root_extent_buffers(info->extent_root);
2170+
free_root_extent_buffers(info->_extent_root);
21702171
free_root_extent_buffers(info->csum_root);
21712172
free_root_extent_buffers(info->quota_root);
21722173
free_root_extent_buffers(info->uuid_root);
@@ -2456,7 +2457,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
24562457
}
24572458
} else {
24582459
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2459-
fs_info->extent_root = root;
2460+
fs_info->_extent_root = root;
24602461
}
24612462

24622463
location.objectid = BTRFS_DEV_TREE_OBJECTID;

fs/btrfs/disk-io.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,15 @@ static inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root)
103103
return NULL;
104104
}
105105

106+
static inline struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info,
107+
u64 bytenr)
108+
{
109+
return fs_info->_extent_root;
110+
}
111+
106112
static inline struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info)
107113
{
108-
return fs_info->extent_root;
114+
return btrfs_extent_root(fs_info, 0);
109115
}
110116

111117
void btrfs_put_root(struct btrfs_root *root);

fs/btrfs/extent-tree.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void btrfs_free_excluded_extents(struct btrfs_block_group *cache)
8787
/* simple helper to search for an existing data extent at a given offset */
8888
int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
8989
{
90+
struct btrfs_root *root = btrfs_extent_root(fs_info, start);
9091
int ret;
9192
struct btrfs_key key;
9293
struct btrfs_path *path;
@@ -98,7 +99,7 @@ int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
9899
key.objectid = start;
99100
key.offset = len;
100101
key.type = BTRFS_EXTENT_ITEM_KEY;
101-
ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
102+
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
102103
btrfs_free_path(path);
103104
return ret;
104105
}
@@ -116,6 +117,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
116117
struct btrfs_fs_info *fs_info, u64 bytenr,
117118
u64 offset, int metadata, u64 *refs, u64 *flags)
118119
{
120+
struct btrfs_root *extent_root;
119121
struct btrfs_delayed_ref_head *head;
120122
struct btrfs_delayed_ref_root *delayed_refs;
121123
struct btrfs_path *path;
@@ -153,7 +155,8 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
153155
else
154156
key.type = BTRFS_EXTENT_ITEM_KEY;
155157

156-
ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
158+
extent_root = btrfs_extent_root(fs_info, bytenr);
159+
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
157160
if (ret < 0)
158161
goto out_free;
159162

@@ -443,7 +446,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
443446
u64 root_objectid,
444447
u64 owner, u64 offset)
445448
{
446-
struct btrfs_root *root = trans->fs_info->extent_root;
449+
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
447450
struct btrfs_key key;
448451
struct btrfs_extent_data_ref *ref;
449452
struct extent_buffer *leaf;
@@ -519,7 +522,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
519522
u64 root_objectid, u64 owner,
520523
u64 offset, int refs_to_add)
521524
{
522-
struct btrfs_root *root = trans->fs_info->extent_root;
525+
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
523526
struct btrfs_key key;
524527
struct extent_buffer *leaf;
525528
u32 size;
@@ -686,7 +689,7 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
686689
u64 bytenr, u64 parent,
687690
u64 root_objectid)
688691
{
689-
struct btrfs_root *root = trans->fs_info->extent_root;
692+
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
690693
struct btrfs_key key;
691694
int ret;
692695

@@ -710,6 +713,7 @@ static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
710713
u64 bytenr, u64 parent,
711714
u64 root_objectid)
712715
{
716+
struct btrfs_root *root = btrfs_extent_root(trans->fs_info, bytenr);
713717
struct btrfs_key key;
714718
int ret;
715719

@@ -722,8 +726,7 @@ static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
722726
key.offset = root_objectid;
723727
}
724728

725-
ret = btrfs_insert_empty_item(trans, trans->fs_info->extent_root,
726-
path, &key, 0);
729+
ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
727730
btrfs_release_path(path);
728731
return ret;
729732
}
@@ -788,7 +791,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
788791
u64 owner, u64 offset, int insert)
789792
{
790793
struct btrfs_fs_info *fs_info = trans->fs_info;
791-
struct btrfs_root *root = fs_info->extent_root;
794+
struct btrfs_root *root = btrfs_extent_root(fs_info, bytenr);
792795
struct btrfs_key key;
793796
struct extent_buffer *leaf;
794797
struct btrfs_extent_item *ei;
@@ -1574,6 +1577,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
15741577
struct btrfs_delayed_extent_op *extent_op)
15751578
{
15761579
struct btrfs_fs_info *fs_info = trans->fs_info;
1580+
struct btrfs_root *root;
15771581
struct btrfs_key key;
15781582
struct btrfs_path *path;
15791583
struct btrfs_extent_item *ei;
@@ -1603,8 +1607,9 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
16031607
key.offset = head->num_bytes;
16041608
}
16051609

1610+
root = btrfs_extent_root(fs_info, key.objectid);
16061611
again:
1607-
ret = btrfs_search_slot(trans, fs_info->extent_root, &key, path, 0, 1);
1612+
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
16081613
if (ret < 0) {
16091614
err = ret;
16101615
goto out;
@@ -2287,7 +2292,7 @@ static noinline int check_committed_ref(struct btrfs_root *root,
22872292
bool strict)
22882293
{
22892294
struct btrfs_fs_info *fs_info = root->fs_info;
2290-
struct btrfs_root *extent_root = fs_info->extent_root;
2295+
struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
22912296
struct extent_buffer *leaf;
22922297
struct btrfs_extent_data_ref *ref;
22932298
struct btrfs_extent_inline_ref *iref;
@@ -2922,7 +2927,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
29222927
struct btrfs_fs_info *info = trans->fs_info;
29232928
struct btrfs_key key;
29242929
struct btrfs_path *path;
2925-
struct btrfs_root *extent_root = info->extent_root;
2930+
struct btrfs_root *extent_root;
29262931
struct extent_buffer *leaf;
29272932
struct btrfs_extent_item *ei;
29282933
struct btrfs_extent_inline_ref *iref;
@@ -2938,6 +2943,8 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
29382943
int last_ref = 0;
29392944
bool skinny_metadata = btrfs_fs_incompat(info, SKINNY_METADATA);
29402945

2946+
extent_root = btrfs_extent_root(info, bytenr);
2947+
29412948
path = btrfs_alloc_path();
29422949
if (!path)
29432950
return -ENOMEM;
@@ -4572,6 +4579,7 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
45724579
struct btrfs_key *ins, int ref_mod)
45734580
{
45744581
struct btrfs_fs_info *fs_info = trans->fs_info;
4582+
struct btrfs_root *extent_root;
45754583
int ret;
45764584
struct btrfs_extent_item *extent_item;
45774585
struct btrfs_extent_inline_ref *iref;
@@ -4591,8 +4599,8 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
45914599
if (!path)
45924600
return -ENOMEM;
45934601

4594-
ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
4595-
ins, size);
4602+
extent_root = btrfs_extent_root(fs_info, ins->objectid);
4603+
ret = btrfs_insert_empty_item(trans, extent_root, path, ins, size);
45964604
if (ret) {
45974605
btrfs_free_path(path);
45984606
return ret;
@@ -4644,6 +4652,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
46444652
struct btrfs_delayed_extent_op *extent_op)
46454653
{
46464654
struct btrfs_fs_info *fs_info = trans->fs_info;
4655+
struct btrfs_root *extent_root;
46474656
int ret;
46484657
struct btrfs_extent_item *extent_item;
46494658
struct btrfs_key extent_key;
@@ -4675,8 +4684,9 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
46754684
if (!path)
46764685
return -ENOMEM;
46774686

4678-
ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
4679-
&extent_key, size);
4687+
extent_root = btrfs_extent_root(fs_info, extent_key.objectid);
4688+
ret = btrfs_insert_empty_item(trans, extent_root, path, &extent_key,
4689+
size);
46804690
if (ret) {
46814691
btrfs_free_path(path);
46824692
return ret;

fs/btrfs/free-space-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans,
10461046
static int populate_free_space_tree(struct btrfs_trans_handle *trans,
10471047
struct btrfs_block_group *block_group)
10481048
{
1049-
struct btrfs_root *extent_root = trans->fs_info->extent_root;
1049+
struct btrfs_root *extent_root;
10501050
struct btrfs_path *path, *path2;
10511051
struct btrfs_key key;
10521052
u64 start, end;
@@ -1080,6 +1080,7 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
10801080
key.type = BTRFS_EXTENT_ITEM_KEY;
10811081
key.offset = 0;
10821082

1083+
extent_root = btrfs_extent_root(trans->fs_info, key.objectid);
10831084
ret = btrfs_search_slot_for_read(extent_root, &key, path, 1, 0);
10841085
if (ret < 0)
10851086
goto out_locked;

0 commit comments

Comments
 (0)