Skip to content

Commit 3cdde22

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: btrfs_test_opt and friends should take a btrfs_fs_info
btrfs_test_opt and friends only use the root pointer to access the fs_info. Let's pass the fs_info directly in preparation to eliminate similar patterns all over btrfs. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent bc07452 commit 3cdde22

13 files changed

Lines changed: 135 additions & 130 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,31 +1301,31 @@ struct btrfs_root {
13011301
#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
13021302
#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
13031303
#define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1304-
#define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
1304+
#define btrfs_test_opt(fs_info, opt) ((fs_info)->mount_opt & \
13051305
BTRFS_MOUNT_##opt)
13061306

1307-
#define btrfs_set_and_info(root, opt, fmt, args...) \
1307+
#define btrfs_set_and_info(fs_info, opt, fmt, args...) \
13081308
{ \
1309-
if (!btrfs_test_opt(root, opt)) \
1310-
btrfs_info(root->fs_info, fmt, ##args); \
1311-
btrfs_set_opt(root->fs_info->mount_opt, opt); \
1309+
if (!btrfs_test_opt(fs_info, opt)) \
1310+
btrfs_info(fs_info, fmt, ##args); \
1311+
btrfs_set_opt(fs_info->mount_opt, opt); \
13121312
}
13131313

1314-
#define btrfs_clear_and_info(root, opt, fmt, args...) \
1314+
#define btrfs_clear_and_info(fs_info, opt, fmt, args...) \
13151315
{ \
1316-
if (btrfs_test_opt(root, opt)) \
1317-
btrfs_info(root->fs_info, fmt, ##args); \
1318-
btrfs_clear_opt(root->fs_info->mount_opt, opt); \
1316+
if (btrfs_test_opt(fs_info, opt)) \
1317+
btrfs_info(fs_info, fmt, ##args); \
1318+
btrfs_clear_opt(fs_info->mount_opt, opt); \
13191319
}
13201320

13211321
#ifdef CONFIG_BTRFS_DEBUG
13221322
static inline int
13231323
btrfs_should_fragment_free_space(struct btrfs_root *root,
13241324
struct btrfs_block_group_cache *block_group)
13251325
{
1326-
return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
1326+
return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
13271327
block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
1328-
(btrfs_test_opt(root, FRAGMENT_DATA) &&
1328+
(btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
13291329
block_group->flags & BTRFS_BLOCK_GROUP_DATA);
13301330
}
13311331
#endif

‎fs/btrfs/dev-replace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
142142
* missing
143143
*/
144144
if (!dev_replace->srcdev &&
145-
!btrfs_test_opt(dev_root, DEGRADED)) {
145+
!btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
146146
ret = -EIO;
147147
btrfs_warn(fs_info,
148148
"cannot mount because device replace operation is ongoing and");
@@ -151,7 +151,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
151151
src_devid);
152152
}
153153
if (!dev_replace->tgtdev &&
154-
!btrfs_test_opt(dev_root, DEGRADED)) {
154+
!btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
155155
ret = -EIO;
156156
btrfs_warn(fs_info,
157157
"cannot mount because device replace operation is ongoing and");

‎fs/btrfs/disk-io.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,8 +3019,8 @@ int open_ctree(struct super_block *sb,
30193019
if (IS_ERR(fs_info->transaction_kthread))
30203020
goto fail_cleaner;
30213021

3022-
if (!btrfs_test_opt(tree_root, SSD) &&
3023-
!btrfs_test_opt(tree_root, NOSSD) &&
3022+
if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
3023+
!btrfs_test_opt(tree_root->fs_info, NOSSD) &&
30243024
!fs_info->fs_devices->rotating) {
30253025
btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
30263026
btrfs_set_opt(fs_info->mount_opt, SSD);
@@ -3033,9 +3033,9 @@ int open_ctree(struct super_block *sb,
30333033
btrfs_apply_pending_changes(fs_info);
30343034

30353035
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3036-
if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
3036+
if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
30373037
ret = btrfsic_mount(tree_root, fs_devices,
3038-
btrfs_test_opt(tree_root,
3038+
btrfs_test_opt(tree_root->fs_info,
30393039
CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
30403040
1 : 0,
30413041
fs_info->check_integrity_print_mask);
@@ -3051,7 +3051,7 @@ int open_ctree(struct super_block *sb,
30513051

30523052
/* do not make disk changes in broken FS or nologreplay is given */
30533053
if (btrfs_super_log_root(disk_super) != 0 &&
3054-
!btrfs_test_opt(tree_root, NOLOGREPLAY)) {
3054+
!btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
30553055
ret = btrfs_replay_log(fs_info, fs_devices);
30563056
if (ret) {
30573057
err = ret;
@@ -3092,7 +3092,7 @@ int open_ctree(struct super_block *sb,
30923092
if (sb->s_flags & MS_RDONLY)
30933093
return 0;
30943094

3095-
if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
3095+
if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
30963096
!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
30973097
btrfs_info(fs_info, "creating free space tree");
30983098
ret = btrfs_create_free_space_tree(fs_info);
@@ -3129,7 +3129,7 @@ int open_ctree(struct super_block *sb,
31293129

31303130
btrfs_qgroup_rescan_resume(fs_info);
31313131

3132-
if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
3132+
if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&
31333133
btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
31343134
btrfs_info(fs_info, "clearing free space tree");
31353135
ret = btrfs_clear_free_space_tree(fs_info);
@@ -3150,7 +3150,7 @@ int open_ctree(struct super_block *sb,
31503150
close_ctree(tree_root);
31513151
return ret;
31523152
}
3153-
} else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
3153+
} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
31543154
fs_info->generation !=
31553155
btrfs_super_uuid_tree_generation(disk_super)) {
31563156
btrfs_info(fs_info, "checking UUID tree");
@@ -3227,7 +3227,7 @@ int open_ctree(struct super_block *sb,
32273227
return err;
32283228

32293229
recovery_tree_root:
3230-
if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
3230+
if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
32313231
goto fail_tree_roots;
32323232

32333233
free_root_pointers(fs_info, 0);
@@ -3642,7 +3642,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
36423642
int total_errors = 0;
36433643
u64 flags;
36443644

3645-
do_barriers = !btrfs_test_opt(root, NOBARRIER);
3645+
do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
36463646
backup_super_roots(root->fs_info);
36473647

36483648
sb = root->fs_info->super_for_commit;
@@ -3926,7 +3926,7 @@ void close_ctree(struct btrfs_root *root)
39263926
iput(fs_info->btree_inode);
39273927

39283928
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3929-
if (btrfs_test_opt(root, CHECK_INTEGRITY))
3929+
if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
39303930
btrfsic_unmount(root, fs_info->fs_devices);
39313931
#endif
39323932

‎fs/btrfs/extent-tree.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
34483448

34493449
spin_lock(&block_group->lock);
34503450
if (block_group->cached != BTRFS_CACHE_FINISHED ||
3451-
!btrfs_test_opt(root, SPACE_CACHE)) {
3451+
!btrfs_test_opt(root->fs_info, SPACE_CACHE)) {
34523452
/*
34533453
* don't bother trying to write stuff out _if_
34543454
* a) we're not cached,
@@ -3525,7 +3525,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
35253525
struct btrfs_path *path;
35263526

35273527
if (list_empty(&cur_trans->dirty_bgs) ||
3528-
!btrfs_test_opt(root, SPACE_CACHE))
3528+
!btrfs_test_opt(root->fs_info, SPACE_CACHE))
35293529
return 0;
35303530

35313531
path = btrfs_alloc_path();
@@ -4444,7 +4444,7 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
44444444
thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
44454445
btrfs_calc_trans_metadata_size(root, 1);
44464446

4447-
if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
4447+
if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
44484448
btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
44494449
left, thresh, type);
44504450
dump_space_info(info, 0, 0);
@@ -6216,7 +6216,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
62166216
spin_lock(&cache->space_info->lock);
62176217
spin_lock(&cache->lock);
62186218

6219-
if (btrfs_test_opt(root, SPACE_CACHE) &&
6219+
if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
62206220
cache->disk_cache_state < BTRFS_DC_CLEAR)
62216221
cache->disk_cache_state = BTRFS_DC_CLEAR;
62226222

@@ -6598,7 +6598,7 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info,
65986598
u64 *empty_cluster)
65996599
{
66006600
struct btrfs_free_cluster *ret = NULL;
6601-
bool ssd = btrfs_test_opt(root, SSD);
6601+
bool ssd = btrfs_test_opt(root->fs_info, SSD);
66026602

66036603
*empty_cluster = 0;
66046604
if (btrfs_mixed_space_info(space_info))
@@ -6743,7 +6743,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
67436743
break;
67446744
}
67456745

6746-
if (btrfs_test_opt(root, DISCARD))
6746+
if (btrfs_test_opt(root->fs_info, DISCARD))
67476747
ret = btrfs_discard_extent(root, start,
67486748
end + 1 - start, NULL);
67496749

@@ -7962,7 +7962,7 @@ int btrfs_reserve_extent(struct btrfs_root *root,
79627962
if (num_bytes == min_alloc_size)
79637963
final_tried = true;
79647964
goto again;
7965-
} else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
7965+
} else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
79667966
struct btrfs_space_info *sinfo;
79677967

79687968
sinfo = __find_space_info(root->fs_info, flags);
@@ -7993,7 +7993,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
79937993
if (pin)
79947994
pin_down_extent(root, cache, start, len, 1);
79957995
else {
7996-
if (btrfs_test_opt(root, DISCARD))
7996+
if (btrfs_test_opt(root->fs_info, DISCARD))
79977997
ret = btrfs_discard_extent(root, start, len, NULL);
79987998
btrfs_add_free_space(cache, start, len);
79997999
btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
@@ -8301,7 +8301,7 @@ use_block_rsv(struct btrfs_trans_handle *trans,
83018301
goto again;
83028302
}
83038303

8304-
if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
8304+
if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
83058305
static DEFINE_RATELIMIT_STATE(_rs,
83068306
DEFAULT_RATELIMIT_INTERVAL * 10,
83078307
/*DEFAULT_RATELIMIT_BURST*/ 1);
@@ -9735,7 +9735,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
97359735
int full = 0;
97369736
int ret = 0;
97379737

9738-
debug = btrfs_test_opt(root, ENOSPC_DEBUG);
9738+
debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);
97399739

97409740
block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
97419741

@@ -10148,10 +10148,10 @@ int btrfs_read_block_groups(struct btrfs_root *root)
1014810148
path->reada = READA_FORWARD;
1014910149

1015010150
cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
10151-
if (btrfs_test_opt(root, SPACE_CACHE) &&
10151+
if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
1015210152
btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
1015310153
need_clear = 1;
10154-
if (btrfs_test_opt(root, CLEAR_CACHE))
10154+
if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
1015510155
need_clear = 1;
1015610156

1015710157
while (1) {
@@ -10182,7 +10182,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
1018210182
* b) Setting 'dirty flag' makes sure that we flush
1018310183
* the new space cache info onto disk.
1018410184
*/
10185-
if (btrfs_test_opt(root, SPACE_CACHE))
10185+
if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
1018610186
cache->disk_cache_state = BTRFS_DC_CLEAR;
1018710187
}
1018810188

@@ -10641,7 +10641,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1064110641
spin_lock(&block_group->space_info->lock);
1064210642
list_del_init(&block_group->ro_list);
1064310643

10644-
if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
10644+
if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
1064510645
WARN_ON(block_group->space_info->total_bytes
1064610646
< block_group->key.offset);
1064710647
WARN_ON(block_group->space_info->bytes_readonly
@@ -10909,7 +10909,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
1090910909
spin_unlock(&space_info->lock);
1091010910

1091110911
/* DISCARD can flip during remount */
10912-
trimming = btrfs_test_opt(root, DISCARD);
10912+
trimming = btrfs_test_opt(root->fs_info, DISCARD);
1091310913

1091410914
/* Implicit trim during transaction commit. */
1091510915
if (trimming)

‎fs/btrfs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode,
132132

133133
static inline int __need_auto_defrag(struct btrfs_root *root)
134134
{
135-
if (!btrfs_test_opt(root, AUTO_DEFRAG))
135+
if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
136136
return 0;
137137

138138
if (btrfs_fs_closing(root->fs_info))

‎fs/btrfs/free-space-cache.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ int btrfs_find_space_cluster(struct btrfs_root *root,
30263026
* For metadata, allow allocates with smaller extents. For
30273027
* data, keep it dense.
30283028
*/
3029-
if (btrfs_test_opt(root, SSD_SPREAD)) {
3029+
if (btrfs_test_opt(root->fs_info, SSD_SPREAD)) {
30303030
cont1_bytes = min_bytes = bytes + empty_size;
30313031
} else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
30323032
cont1_bytes = bytes;
@@ -3470,7 +3470,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
34703470
int ret = 0;
34713471
u64 root_gen = btrfs_root_generation(&root->root_item);
34723472

3473-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
3473+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
34743474
return 0;
34753475

34763476
/*
@@ -3514,7 +3514,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
35143514
struct btrfs_io_ctl io_ctl;
35153515
bool release_metadata = true;
35163516

3517-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
3517+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
35183518
return 0;
35193519

35203520
memset(&io_ctl, 0, sizeof(io_ctl));

‎fs/btrfs/inode-map.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int caching_kthread(void *data)
3838
int slot;
3939
int ret;
4040

41-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
41+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
4242
return 0;
4343

4444
path = btrfs_alloc_path();
@@ -141,7 +141,7 @@ static void start_caching(struct btrfs_root *root)
141141
int ret;
142142
u64 objectid;
143143

144-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
144+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
145145
return;
146146

147147
spin_lock(&root->ino_cache_lock);
@@ -185,7 +185,7 @@ static void start_caching(struct btrfs_root *root)
185185

186186
int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid)
187187
{
188-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
188+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
189189
return btrfs_find_free_objectid(root, objectid);
190190

191191
again:
@@ -211,7 +211,7 @@ void btrfs_return_ino(struct btrfs_root *root, u64 objectid)
211211
{
212212
struct btrfs_free_space_ctl *pinned = root->free_ino_pinned;
213213

214-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
214+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
215215
return;
216216
again:
217217
if (root->ino_cache_state == BTRFS_CACHE_FINISHED) {
@@ -251,7 +251,7 @@ void btrfs_unpin_free_ino(struct btrfs_root *root)
251251
struct rb_node *n;
252252
u64 count;
253253

254-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
254+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
255255
return;
256256

257257
while (1) {
@@ -412,7 +412,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
412412
if (btrfs_root_refs(&root->root_item) == 0)
413413
return 0;
414414

415-
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
415+
if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE))
416416
return 0;
417417

418418
path = btrfs_alloc_path();

0 commit comments

Comments
 (0)