Skip to content

Commit

Permalink
btrfs: call functions that always use the same root with fs_info instead
Browse files Browse the repository at this point in the history
There are many functions that are always called with the same root
argument.  Rather than passing the same root every time, we can
pass an fs_info pointer instead and have the function get the root
pointer itself.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Jeff Mahoney authored and David Sterba committed Dec 6, 2016
1 parent 5b4aace commit 6bccf3a
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 102 deletions.
16 changes: 8 additions & 8 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr);
int btrfs_free_block_groups(struct btrfs_fs_info *info);
int btrfs_read_block_groups(struct btrfs_fs_info *info);
int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr);
int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr);
int btrfs_make_block_group(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 bytes_used,
u64 type, u64 chunk_objectid, u64 chunk_offset,
Expand All @@ -2649,7 +2649,7 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
struct btrfs_fs_info *fs_info,
const u64 chunk_offset);
int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 group_start,
struct btrfs_fs_info *fs_info, u64 group_start,
struct extent_map *em);
void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info);
void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache);
Expand Down Expand Up @@ -2935,11 +2935,11 @@ int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq);

/* root-item.c */
int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *tree_root,
struct btrfs_fs_info *fs_info,
u64 root_id, u64 ref_id, u64 dirid, u64 sequence,
const char *name, int name_len);
int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *tree_root,
struct btrfs_fs_info *fs_info,
u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
const char *name, int name_len);
int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Expand All @@ -2954,7 +2954,7 @@ int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key,
struct btrfs_path *path, struct btrfs_root_item *root_item,
struct btrfs_key *root_key);
int btrfs_find_orphan_roots(struct btrfs_root *tree_root);
int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
void btrfs_set_root_node(struct btrfs_root_item *item,
struct extent_buffer *node);
void btrfs_check_and_init_root_item(struct btrfs_root_item *item);
Expand All @@ -2963,10 +2963,10 @@ void btrfs_update_root_times(struct btrfs_trans_handle *trans,

/* uuid-tree.c */
int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans,
struct btrfs_root *uuid_root, u8 *uuid, u8 type,
struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
u64 subid);
int btrfs_uuid_tree_rem(struct btrfs_trans_handle *trans,
struct btrfs_root *uuid_root, u8 *uuid, u8 type,
struct btrfs_fs_info *fs_info, u8 *uuid, u8 type,
u64 subid);
int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info,
int (*check_func)(struct btrfs_fs_info *, u8 *, u8,
Expand Down Expand Up @@ -3613,7 +3613,7 @@ static inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
#endif

/* relocation.c */
int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start);
int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
Expand Down
44 changes: 23 additions & 21 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,8 +2296,7 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
init_waitqueue_head(&fs_info->balance_wait_q);
}

static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
struct btrfs_root *tree_root)
static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
{
fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
set_nlink(fs_info->btree_inode, 1);
Expand All @@ -2317,7 +2316,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,

BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;

BTRFS_I(fs_info->btree_inode)->root = tree_root;
BTRFS_I(fs_info->btree_inode)->root = fs_info->tree_root;
memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
sizeof(struct btrfs_key));
set_bit(BTRFS_INODE_DUMMY,
Expand Down Expand Up @@ -2485,21 +2484,23 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
}

if (fs_info->sb->s_flags & MS_RDONLY) {
ret = btrfs_commit_super(tree_root);
ret = btrfs_commit_super(fs_info);
if (ret)
return ret;
}

return 0;
}

static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
struct btrfs_root *tree_root)
static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
{
struct btrfs_root *tree_root = fs_info->tree_root;
struct btrfs_root *root;
struct btrfs_key location;
int ret;

BUG_ON(!fs_info->tree_root);

location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
location.type = BTRFS_ROOT_ITEM_KEY;
location.offset = 0;
Expand Down Expand Up @@ -2710,7 +2711,7 @@ int open_ctree(struct super_block *sb,
sb->s_blocksize_bits = blksize_bits(4096);
sb->s_bdi = &fs_info->bdi;

btrfs_init_btree_inode(fs_info, tree_root);
btrfs_init_btree_inode(fs_info);

spin_lock_init(&fs_info->block_group_cache_lock);
fs_info->block_group_cache_tree = RB_ROOT;
Expand Down Expand Up @@ -2908,7 +2909,7 @@ int open_ctree(struct super_block *sb,
sb->s_blocksize_bits = blksize_bits(sectorsize);

mutex_lock(&fs_info->chunk_mutex);
ret = btrfs_read_sys_array(tree_root);
ret = btrfs_read_sys_array(fs_info);
mutex_unlock(&fs_info->chunk_mutex);
if (ret) {
btrfs_err(fs_info, "failed to read the system array: %d", ret);
Expand Down Expand Up @@ -2985,7 +2986,7 @@ int open_ctree(struct super_block *sb,

mutex_unlock(&tree_root->objectid_mutex);

ret = btrfs_read_roots(fs_info, tree_root);
ret = btrfs_read_roots(fs_info);
if (ret)
goto recovery_tree_root;

Expand Down Expand Up @@ -3106,7 +3107,7 @@ int open_ctree(struct super_block *sb,
}
}

ret = btrfs_find_orphan_roots(tree_root);
ret = btrfs_find_orphan_roots(fs_info);
if (ret)
goto fail_qgroup;

Expand Down Expand Up @@ -3154,7 +3155,7 @@ int open_ctree(struct super_block *sb,
if (ret) {
btrfs_warn(fs_info,
"failed to clear free space tree: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}
}
Expand All @@ -3166,7 +3167,7 @@ int open_ctree(struct super_block *sb,
if (ret) {
btrfs_warn(fs_info,
"failed to create free space tree: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}
}
Expand All @@ -3175,22 +3176,22 @@ int open_ctree(struct super_block *sb,
if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
(ret = btrfs_orphan_cleanup(fs_info->tree_root))) {
up_read(&fs_info->cleanup_work_sem);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}
up_read(&fs_info->cleanup_work_sem);

ret = btrfs_resume_balance_async(fs_info);
if (ret) {
btrfs_warn(fs_info, "failed to resume balance: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}

ret = btrfs_resume_dev_replace_async(fs_info);
if (ret) {
btrfs_warn(fs_info, "failed to resume device replace: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}

Expand All @@ -3202,7 +3203,7 @@ int open_ctree(struct super_block *sb,
if (ret) {
btrfs_warn(fs_info,
"failed to create the UUID tree: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}
} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
Expand All @@ -3213,7 +3214,7 @@ int open_ctree(struct super_block *sb,
if (ret) {
btrfs_warn(fs_info,
"failed to check the UUID tree: %d", ret);
close_ctree(tree_root);
close_ctree(fs_info);
return ret;
}
} else {
Expand Down Expand Up @@ -3886,8 +3887,9 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
return err;
}

int btrfs_commit_super(struct btrfs_root *root)
int btrfs_commit_super(struct btrfs_fs_info *fs_info)
{
struct btrfs_root *root = fs_info->tree_root;
struct btrfs_trans_handle *trans;

mutex_lock(&root->fs_info->cleaner_mutex);
Expand All @@ -3905,9 +3907,9 @@ int btrfs_commit_super(struct btrfs_root *root)
return btrfs_commit_transaction(trans, root);
}

void close_ctree(struct btrfs_root *root)
void close_ctree(struct btrfs_fs_info *fs_info)
{
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_root *root = fs_info->tree_root;
int ret;

set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags);
Expand Down Expand Up @@ -3944,7 +3946,7 @@ void close_ctree(struct btrfs_root *root)
*/
btrfs_delete_unused_bgs(root->fs_info);

ret = btrfs_commit_super(root);
ret = btrfs_commit_super(fs_info);
if (ret)
btrfs_err(fs_info, "commit super ret %d", ret);
}
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ void clean_tree_block(struct btrfs_trans_handle *trans,
int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices,
char *options);
void close_ctree(struct btrfs_root *root);
void close_ctree(struct btrfs_fs_info *fs_info);
int write_ctree_super(struct btrfs_trans_handle *trans,
struct btrfs_root *root, int max_mirrors);
struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
struct buffer_head **bh_ret);
int btrfs_commit_super(struct btrfs_root *root);
int btrfs_commit_super(struct btrfs_fs_info *fs_info);
struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
struct btrfs_key *location);
int btrfs_init_fs_root(struct btrfs_root *root);
Expand Down
20 changes: 11 additions & 9 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -9514,8 +9514,9 @@ void btrfs_dec_block_group_ro(struct btrfs_root *root,
* @return - -1 if it's not a good idea to relocate this block group, 0 if its
* ok to go ahead and try.
*/
int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
{
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_block_group_cache *block_group;
struct btrfs_space_info *space_info;
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
Expand Down Expand Up @@ -9659,9 +9660,11 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
return ret;
}

static int find_first_block_group(struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_key *key)
static int find_first_block_group(struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
struct btrfs_key *key)
{
struct btrfs_root *root = fs_info->extent_root;
int ret = 0;
struct btrfs_key found_key;
struct extent_buffer *leaf;
Expand Down Expand Up @@ -9961,7 +9964,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
need_clear = 1;

while (1) {
ret = find_first_block_group(root, path, &key);
ret = find_first_block_group(info, path, &key);
if (ret > 0)
break;
if (ret != 0)
Expand Down Expand Up @@ -10140,7 +10143,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans,
sizeof(item));
if (ret)
btrfs_abort_transaction(trans, ret);
ret = btrfs_finish_chunk_alloc(trans, extent_root,
ret = btrfs_finish_chunk_alloc(trans, extent_root->fs_info,
key.objectid, key.offset);
if (ret)
btrfs_abort_transaction(trans, ret);
Expand Down Expand Up @@ -10263,9 +10266,10 @@ static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
}

int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 group_start,
struct btrfs_fs_info *fs_info, u64 group_start,
struct extent_map *em)
{
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_path *path;
struct btrfs_block_group_cache *block_group;
struct btrfs_free_cluster *cluster;
Expand All @@ -10279,9 +10283,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
struct btrfs_caching_control *caching_ctl = NULL;
bool remove_em;

root = root->fs_info->extent_root;

block_group = btrfs_lookup_block_group(root->fs_info, group_start);
block_group = btrfs_lookup_block_group(fs_info, group_start);
BUG_ON(!block_group);
BUG_ON(!block_group->ro);

Expand Down
6 changes: 3 additions & 3 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4179,7 +4179,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
}
btrfs_release_path(path);

ret = btrfs_del_root_ref(trans, root->fs_info->tree_root,
ret = btrfs_del_root_ref(trans, root->fs_info,
objectid, root->root_key.objectid,
dir_ino, &index, name, name_len);
if (ret < 0) {
Expand Down Expand Up @@ -6296,7 +6296,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
}

if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
ret = btrfs_add_root_ref(trans, root->fs_info,
key.objectid, root->root_key.objectid,
parent_ino, index, name, name_len);
} else if (add_backref) {
Expand Down Expand Up @@ -6332,7 +6332,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
u64 local_index;
int err;
err = btrfs_del_root_ref(trans, root->fs_info->tree_root,
err = btrfs_del_root_ref(trans, root->fs_info,
key.objectid, root->root_key.objectid,
parent_ino, &local_index, name, name_len);

Expand Down
Loading

0 comments on commit 6bccf3a

Please sign in to comment.