Skip to content

Commit fc28b25

Browse files
josefbacikkdave
authored andcommitted
btrfs: stop accessing ->csum_root directly
We are going to have multiple csum roots in the future, so convert all users of ->csum_root to btrfs_csum_root() and rename ->csum_root to ->_csum_root so we can easily find remaining users 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 056c831 commit fc28b25

File tree

10 files changed

+60
-27
lines changed

10 files changed

+60
-27
lines changed

fs/btrfs/block-rsv.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
353353
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
354354
struct btrfs_space_info *sinfo = block_rsv->space_info;
355355
struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
356+
struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0);
356357
u64 num_bytes;
357358
unsigned min_items;
358359

@@ -362,7 +363,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
362363
* it to a minimal amount for safety.
363364
*/
364365
num_bytes = btrfs_root_used(&extent_root->root_item) +
365-
btrfs_root_used(&fs_info->csum_root->root_item) +
366+
btrfs_root_used(&csum_root->root_item) +
366367
btrfs_root_used(&fs_info->tree_root->root_item);
367368

368369
/*
@@ -476,8 +477,9 @@ static struct btrfs_block_rsv *get_block_rsv(
476477
struct btrfs_block_rsv *block_rsv = NULL;
477478

478479
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
479-
(root == fs_info->csum_root && trans->adding_csums) ||
480-
(root == fs_info->uuid_root))
480+
(root == fs_info->uuid_root) ||
481+
(trans->adding_csums &&
482+
root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID))
481483
block_rsv = trans->block_rsv;
482484

483485
if (!block_rsv)

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ struct btrfs_fs_info {
628628
struct btrfs_root *chunk_root;
629629
struct btrfs_root *dev_root;
630630
struct btrfs_root *fs_root;
631-
struct btrfs_root *csum_root;
631+
struct btrfs_root *_csum_root;
632632
struct btrfs_root *quota_root;
633633
struct btrfs_root *uuid_root;
634634
struct btrfs_root *free_space_root;

fs/btrfs/disk-io.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
15631563
if (objectid == BTRFS_DEV_TREE_OBJECTID)
15641564
return btrfs_grab_root(fs_info->dev_root);
15651565
if (objectid == BTRFS_CSUM_TREE_OBJECTID)
1566-
return btrfs_grab_root(fs_info->csum_root);
1566+
return btrfs_grab_root(fs_info->_csum_root);
15671567
if (objectid == BTRFS_QUOTA_TREE_OBJECTID)
15681568
return btrfs_grab_root(fs_info->quota_root) ?
15691569
fs_info->quota_root : ERR_PTR(-ENOENT);
@@ -1634,7 +1634,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
16341634
btrfs_put_root(fs_info->tree_root);
16351635
btrfs_put_root(fs_info->chunk_root);
16361636
btrfs_put_root(fs_info->dev_root);
1637-
btrfs_put_root(fs_info->csum_root);
1637+
btrfs_put_root(fs_info->_csum_root);
16381638
btrfs_put_root(fs_info->quota_root);
16391639
btrfs_put_root(fs_info->uuid_root);
16401640
btrfs_put_root(fs_info->free_space_root);
@@ -2009,6 +2009,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
20092009
const int next_backup = info->backup_root_index;
20102010
struct btrfs_root_backup *root_backup;
20112011
struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
2012+
struct btrfs_root *csum_root = btrfs_csum_root(info, 0);
20122013

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

@@ -2058,11 +2059,11 @@ static void backup_super_roots(struct btrfs_fs_info *info)
20582059
btrfs_set_backup_dev_root_level(root_backup,
20592060
btrfs_header_level(info->dev_root->node));
20602061

2061-
btrfs_set_backup_csum_root(root_backup, info->csum_root->node->start);
2062+
btrfs_set_backup_csum_root(root_backup, csum_root->node->start);
20622063
btrfs_set_backup_csum_root_gen(root_backup,
2063-
btrfs_header_generation(info->csum_root->node));
2064+
btrfs_header_generation(csum_root->node));
20642065
btrfs_set_backup_csum_root_level(root_backup,
2065-
btrfs_header_level(info->csum_root->node));
2066+
btrfs_header_level(csum_root->node));
20662067

20672068
btrfs_set_backup_total_bytes(root_backup,
20682069
btrfs_super_total_bytes(info->super_copy));
@@ -2168,7 +2169,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
21682169

21692170
free_root_extent_buffers(info->dev_root);
21702171
free_root_extent_buffers(info->_extent_root);
2171-
free_root_extent_buffers(info->csum_root);
2172+
free_root_extent_buffers(info->_csum_root);
21722173
free_root_extent_buffers(info->quota_root);
21732174
free_root_extent_buffers(info->uuid_root);
21742175
free_root_extent_buffers(info->fs_root);
@@ -2488,7 +2489,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
24882489
}
24892490
} else {
24902491
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2491-
fs_info->csum_root = root;
2492+
fs_info->_csum_root = root;
24922493
}
24932494
} else {
24942495
set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);

fs/btrfs/disk-io.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ static inline struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info
109109
return fs_info->_extent_root;
110110
}
111111

112+
static inline struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info,
113+
u64 bytenr)
114+
{
115+
return fs_info->_csum_root;
116+
}
117+
112118
static inline struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info)
113119
{
114120
return btrfs_extent_root(fs_info, 0);

fs/btrfs/extent-tree.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,8 +1851,11 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
18511851
if (head->must_insert_reserved) {
18521852
btrfs_pin_extent(trans, head->bytenr, head->num_bytes, 1);
18531853
if (head->is_data) {
1854-
ret = btrfs_del_csums(trans, fs_info->csum_root,
1855-
head->bytenr, head->num_bytes);
1854+
struct btrfs_root *csum_root;
1855+
1856+
csum_root = btrfs_csum_root(fs_info, head->bytenr);
1857+
ret = btrfs_del_csums(trans, csum_root, head->bytenr,
1858+
head->num_bytes);
18561859
}
18571860
}
18581861

@@ -3188,7 +3191,9 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
31883191
btrfs_release_path(path);
31893192

31903193
if (is_data) {
3191-
ret = btrfs_del_csums(trans, info->csum_root, bytenr,
3194+
struct btrfs_root *csum_root;
3195+
csum_root = btrfs_csum_root(info, bytenr);
3196+
ret = btrfs_del_csums(trans, csum_root, bytenr,
31923197
num_bytes);
31933198
if (ret) {
31943199
btrfs_abort_transaction(trans, ret);

fs/btrfs/file-item.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info,
257257
struct btrfs_path *path, u64 disk_bytenr,
258258
u64 len, u8 *dst)
259259
{
260+
struct btrfs_root *csum_root;
260261
struct btrfs_csum_item *item = NULL;
261262
struct btrfs_key key;
262263
const u32 sectorsize = fs_info->sectorsize;
@@ -285,7 +286,8 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info,
285286

286287
/* Current item doesn't contain the desired range, search again */
287288
btrfs_release_path(path);
288-
item = btrfs_lookup_csum(NULL, fs_info->csum_root, path, disk_bytenr, 0);
289+
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
290+
item = btrfs_lookup_csum(NULL, csum_root, path, disk_bytenr, 0);
289291
if (IS_ERR(item)) {
290292
ret = PTR_ERR(item);
291293
goto out;

fs/btrfs/inode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,11 +1530,12 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
15301530
static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info,
15311531
u64 bytenr, u64 num_bytes)
15321532
{
1533-
int ret;
1533+
struct btrfs_root *csum_root = btrfs_csum_root(fs_info, bytenr);
15341534
struct btrfs_ordered_sum *sums;
1535+
int ret;
15351536
LIST_HEAD(list);
15361537

1537-
ret = btrfs_lookup_csums_range(fs_info->csum_root, bytenr,
1538+
ret = btrfs_lookup_csums_range(csum_root, bytenr,
15381539
bytenr + num_bytes - 1, &list, 0);
15391540
if (ret == 0 && list_empty(&list))
15401541
return 0;
@@ -2584,11 +2585,15 @@ static int add_pending_csums(struct btrfs_trans_handle *trans,
25842585
struct list_head *list)
25852586
{
25862587
struct btrfs_ordered_sum *sum;
2588+
struct btrfs_root *csum_root = NULL;
25872589
int ret;
25882590

25892591
list_for_each_entry(sum, list, list) {
25902592
trans->adding_csums = true;
2591-
ret = btrfs_csum_file_blocks(trans, trans->fs_info->csum_root, sum);
2593+
if (!csum_root)
2594+
csum_root = btrfs_csum_root(trans->fs_info,
2595+
sum->bytenr);
2596+
ret = btrfs_csum_file_blocks(trans, csum_root, sum);
25922597
trans->adding_csums = false;
25932598
if (ret)
25942599
return ret;

fs/btrfs/relocation.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4306,6 +4306,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
43064306
int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
43074307
{
43084308
struct btrfs_fs_info *fs_info = inode->root->fs_info;
4309+
struct btrfs_root *csum_root;
43094310
struct btrfs_ordered_sum *sums;
43104311
struct btrfs_ordered_extent *ordered;
43114312
int ret;
@@ -4317,7 +4318,8 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
43174318
BUG_ON(ordered->file_offset != file_pos || ordered->num_bytes != len);
43184319

43194320
disk_bytenr = file_pos + inode->index_cnt;
4320-
ret = btrfs_lookup_csums_range(fs_info->csum_root, disk_bytenr,
4321+
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
4322+
ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
43214323
disk_bytenr + len - 1, &list, 0);
43224324
if (ret)
43234325
goto out;

fs/btrfs/scrub.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
28982898
{
28992899
struct btrfs_fs_info *fs_info = sctx->fs_info;
29002900
struct btrfs_root *root = btrfs_extent_root(fs_info, logic_start);
2901-
struct btrfs_root *csum_root = fs_info->csum_root;
2901+
struct btrfs_root *csum_root;
29022902
struct btrfs_extent_item *extent;
29032903
struct btrfs_io_context *bioc = NULL;
29042904
u64 flags;
@@ -3060,6 +3060,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
30603060
extent_dev = bioc->stripes[0].dev;
30613061
btrfs_put_bioc(bioc);
30623062

3063+
csum_root = btrfs_csum_root(fs_info, extent_logical);
30633064
ret = btrfs_lookup_csums_range(csum_root,
30643065
extent_logical,
30653066
extent_logical + extent_len - 1,
@@ -3169,7 +3170,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
31693170
struct btrfs_path *path, *ppath;
31703171
struct btrfs_fs_info *fs_info = sctx->fs_info;
31713172
struct btrfs_root *root;
3172-
struct btrfs_root *csum_root = fs_info->csum_root;
3173+
struct btrfs_root *csum_root;
31733174
struct btrfs_extent_item *extent;
31743175
struct blk_plug plug;
31753176
u64 flags;
@@ -3273,6 +3274,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32733274
key_end.offset = (u64)-1;
32743275
reada1 = btrfs_reada_add(root, &key, &key_end);
32753276

3277+
csum_root = btrfs_csum_root(fs_info, logical);
3278+
32763279
if (cache->flags & BTRFS_BLOCK_GROUP_DATA) {
32773280
key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
32783281
key.type = BTRFS_EXTENT_CSUM_KEY;

fs/btrfs/tree-log.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,21 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
872872
*/
873873
while (!list_empty(&ordered_sums)) {
874874
struct btrfs_ordered_sum *sums;
875+
struct btrfs_root *csum_root;
876+
875877
sums = list_entry(ordered_sums.next,
876878
struct btrfs_ordered_sum,
877879
list);
880+
csum_root = btrfs_csum_root(fs_info,
881+
sums->bytenr);
878882
if (!ret)
879-
ret = btrfs_del_csums(trans,
880-
fs_info->csum_root,
883+
ret = btrfs_del_csums(trans, csum_root,
881884
sums->bytenr,
882885
sums->len);
883886
if (!ret)
884887
ret = btrfs_csum_file_blocks(trans,
885-
fs_info->csum_root, sums);
888+
csum_root,
889+
sums);
886890
list_del(&sums->list);
887891
kfree(sums);
888892
}
@@ -4340,6 +4344,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
43404344

43414345
found_type = btrfs_file_extent_type(src, extent);
43424346
if (found_type == BTRFS_FILE_EXTENT_REG) {
4347+
struct btrfs_root *csum_root;
43434348
u64 ds, dl, cs, cl;
43444349
ds = btrfs_file_extent_disk_bytenr(src,
43454350
extent);
@@ -4358,8 +4363,8 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
43584363
cl = dl;
43594364
}
43604365

4361-
ret = btrfs_lookup_csums_range(
4362-
fs_info->csum_root,
4366+
csum_root = btrfs_csum_root(fs_info, ds);
4367+
ret = btrfs_lookup_csums_range(csum_root,
43634368
ds + cs, ds + cs + cl - 1,
43644369
&ordered_sums, 0);
43654370
if (ret)
@@ -4411,6 +4416,7 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
44114416
struct btrfs_log_ctx *ctx)
44124417
{
44134418
struct btrfs_ordered_extent *ordered;
4419+
struct btrfs_root *csum_root;
44144420
u64 csum_offset;
44154421
u64 csum_len;
44164422
u64 mod_start = em->mod_start;
@@ -4491,7 +4497,8 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
44914497
}
44924498

44934499
/* block start is already adjusted for the file extent offset. */
4494-
ret = btrfs_lookup_csums_range(trans->fs_info->csum_root,
4500+
csum_root = btrfs_csum_root(trans->fs_info, em->block_start);
4501+
ret = btrfs_lookup_csums_range(csum_root,
44954502
em->block_start + csum_offset,
44964503
em->block_start + csum_offset +
44974504
csum_len - 1, &ordered_sums, 0);

0 commit comments

Comments
 (0)