aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2016-06-21 21:16:51 -0400
committerDavid Sterba <dsterba@suse.com>2016-12-06 10:06:57 -0500
commit6bccf3ab1e1f0913268bfcd1c09cadb1f4f2857d (patch)
treea7eae4bb4dec1cd2f7b21f5010549bfaa9aaa08c /fs/btrfs/disk-io.c
parent5b4aacefb8fbfc996e68b9b083d30f8bc0972449 (diff)
btrfs: call functions that always use the same root with fs_info instead
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>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 92c2aea5118b..1db5f0304c6b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2296,8 +2296,7 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
2296 init_waitqueue_head(&fs_info->balance_wait_q); 2296 init_waitqueue_head(&fs_info->balance_wait_q);
2297} 2297}
2298 2298
2299static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info, 2299static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
2300 struct btrfs_root *tree_root)
2301{ 2300{
2302 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID; 2301 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
2303 set_nlink(fs_info->btree_inode, 1); 2302 set_nlink(fs_info->btree_inode, 1);
@@ -2317,7 +2316,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
2317 2316
2318 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops; 2317 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
2319 2318
2320 BTRFS_I(fs_info->btree_inode)->root = tree_root; 2319 BTRFS_I(fs_info->btree_inode)->root = fs_info->tree_root;
2321 memset(&BTRFS_I(fs_info->btree_inode)->location, 0, 2320 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2322 sizeof(struct btrfs_key)); 2321 sizeof(struct btrfs_key));
2323 set_bit(BTRFS_INODE_DUMMY, 2322 set_bit(BTRFS_INODE_DUMMY,
@@ -2485,7 +2484,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2485 } 2484 }
2486 2485
2487 if (fs_info->sb->s_flags & MS_RDONLY) { 2486 if (fs_info->sb->s_flags & MS_RDONLY) {
2488 ret = btrfs_commit_super(tree_root); 2487 ret = btrfs_commit_super(fs_info);
2489 if (ret) 2488 if (ret)
2490 return ret; 2489 return ret;
2491 } 2490 }
@@ -2493,13 +2492,15 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2493 return 0; 2492 return 0;
2494} 2493}
2495 2494
2496static int btrfs_read_roots(struct btrfs_fs_info *fs_info, 2495static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
2497 struct btrfs_root *tree_root)
2498{ 2496{
2497 struct btrfs_root *tree_root = fs_info->tree_root;
2499 struct btrfs_root *root; 2498 struct btrfs_root *root;
2500 struct btrfs_key location; 2499 struct btrfs_key location;
2501 int ret; 2500 int ret;
2502 2501
2502 BUG_ON(!fs_info->tree_root);
2503
2503 location.objectid = BTRFS_EXTENT_TREE_OBJECTID; 2504 location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
2504 location.type = BTRFS_ROOT_ITEM_KEY; 2505 location.type = BTRFS_ROOT_ITEM_KEY;
2505 location.offset = 0; 2506 location.offset = 0;
@@ -2710,7 +2711,7 @@ int open_ctree(struct super_block *sb,
2710 sb->s_blocksize_bits = blksize_bits(4096); 2711 sb->s_blocksize_bits = blksize_bits(4096);
2711 sb->s_bdi = &fs_info->bdi; 2712 sb->s_bdi = &fs_info->bdi;
2712 2713
2713 btrfs_init_btree_inode(fs_info, tree_root); 2714 btrfs_init_btree_inode(fs_info);
2714 2715
2715 spin_lock_init(&fs_info->block_group_cache_lock); 2716 spin_lock_init(&fs_info->block_group_cache_lock);
2716 fs_info->block_group_cache_tree = RB_ROOT; 2717 fs_info->block_group_cache_tree = RB_ROOT;
@@ -2908,7 +2909,7 @@ int open_ctree(struct super_block *sb,
2908 sb->s_blocksize_bits = blksize_bits(sectorsize); 2909 sb->s_blocksize_bits = blksize_bits(sectorsize);
2909 2910
2910 mutex_lock(&fs_info->chunk_mutex); 2911 mutex_lock(&fs_info->chunk_mutex);
2911 ret = btrfs_read_sys_array(tree_root); 2912 ret = btrfs_read_sys_array(fs_info);
2912 mutex_unlock(&fs_info->chunk_mutex); 2913 mutex_unlock(&fs_info->chunk_mutex);
2913 if (ret) { 2914 if (ret) {
2914 btrfs_err(fs_info, "failed to read the system array: %d", ret); 2915 btrfs_err(fs_info, "failed to read the system array: %d", ret);
@@ -2985,7 +2986,7 @@ retry_root_backup:
2985 2986
2986 mutex_unlock(&tree_root->objectid_mutex); 2987 mutex_unlock(&tree_root->objectid_mutex);
2987 2988
2988 ret = btrfs_read_roots(fs_info, tree_root); 2989 ret = btrfs_read_roots(fs_info);
2989 if (ret) 2990 if (ret)
2990 goto recovery_tree_root; 2991 goto recovery_tree_root;
2991 2992
@@ -3106,7 +3107,7 @@ retry_root_backup:
3106 } 3107 }
3107 } 3108 }
3108 3109
3109 ret = btrfs_find_orphan_roots(tree_root); 3110 ret = btrfs_find_orphan_roots(fs_info);
3110 if (ret) 3111 if (ret)
3111 goto fail_qgroup; 3112 goto fail_qgroup;
3112 3113
@@ -3154,7 +3155,7 @@ retry_root_backup:
3154 if (ret) { 3155 if (ret) {
3155 btrfs_warn(fs_info, 3156 btrfs_warn(fs_info,
3156 "failed to clear free space tree: %d", ret); 3157 "failed to clear free space tree: %d", ret);
3157 close_ctree(tree_root); 3158 close_ctree(fs_info);
3158 return ret; 3159 return ret;
3159 } 3160 }
3160 } 3161 }
@@ -3166,7 +3167,7 @@ retry_root_backup:
3166 if (ret) { 3167 if (ret) {
3167 btrfs_warn(fs_info, 3168 btrfs_warn(fs_info,
3168 "failed to create free space tree: %d", ret); 3169 "failed to create free space tree: %d", ret);
3169 close_ctree(tree_root); 3170 close_ctree(fs_info);
3170 return ret; 3171 return ret;
3171 } 3172 }
3172 } 3173 }
@@ -3175,7 +3176,7 @@ retry_root_backup:
3175 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || 3176 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
3176 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { 3177 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) {
3177 up_read(&fs_info->cleanup_work_sem); 3178 up_read(&fs_info->cleanup_work_sem);
3178 close_ctree(tree_root); 3179 close_ctree(fs_info);
3179 return ret; 3180 return ret;
3180 } 3181 }
3181 up_read(&fs_info->cleanup_work_sem); 3182 up_read(&fs_info->cleanup_work_sem);
@@ -3183,14 +3184,14 @@ retry_root_backup:
3183 ret = btrfs_resume_balance_async(fs_info); 3184 ret = btrfs_resume_balance_async(fs_info);
3184 if (ret) { 3185 if (ret) {
3185 btrfs_warn(fs_info, "failed to resume balance: %d", ret); 3186 btrfs_warn(fs_info, "failed to resume balance: %d", ret);
3186 close_ctree(tree_root); 3187 close_ctree(fs_info);
3187 return ret; 3188 return ret;
3188 } 3189 }
3189 3190
3190 ret = btrfs_resume_dev_replace_async(fs_info); 3191 ret = btrfs_resume_dev_replace_async(fs_info);
3191 if (ret) { 3192 if (ret) {
3192 btrfs_warn(fs_info, "failed to resume device replace: %d", ret); 3193 btrfs_warn(fs_info, "failed to resume device replace: %d", ret);
3193 close_ctree(tree_root); 3194 close_ctree(fs_info);
3194 return ret; 3195 return ret;
3195 } 3196 }
3196 3197
@@ -3202,7 +3203,7 @@ retry_root_backup:
3202 if (ret) { 3203 if (ret) {
3203 btrfs_warn(fs_info, 3204 btrfs_warn(fs_info,
3204 "failed to create the UUID tree: %d", ret); 3205 "failed to create the UUID tree: %d", ret);
3205 close_ctree(tree_root); 3206 close_ctree(fs_info);
3206 return ret; 3207 return ret;
3207 } 3208 }
3208 } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) || 3209 } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
@@ -3213,7 +3214,7 @@ retry_root_backup:
3213 if (ret) { 3214 if (ret) {
3214 btrfs_warn(fs_info, 3215 btrfs_warn(fs_info,
3215 "failed to check the UUID tree: %d", ret); 3216 "failed to check the UUID tree: %d", ret);
3216 close_ctree(tree_root); 3217 close_ctree(fs_info);
3217 return ret; 3218 return ret;
3218 } 3219 }
3219 } else { 3220 } else {
@@ -3886,8 +3887,9 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
3886 return err; 3887 return err;
3887} 3888}
3888 3889
3889int btrfs_commit_super(struct btrfs_root *root) 3890int btrfs_commit_super(struct btrfs_fs_info *fs_info)
3890{ 3891{
3892 struct btrfs_root *root = fs_info->tree_root;
3891 struct btrfs_trans_handle *trans; 3893 struct btrfs_trans_handle *trans;
3892 3894
3893 mutex_lock(&root->fs_info->cleaner_mutex); 3895 mutex_lock(&root->fs_info->cleaner_mutex);
@@ -3905,9 +3907,9 @@ int btrfs_commit_super(struct btrfs_root *root)
3905 return btrfs_commit_transaction(trans, root); 3907 return btrfs_commit_transaction(trans, root);
3906} 3908}
3907 3909
3908void close_ctree(struct btrfs_root *root) 3910void close_ctree(struct btrfs_fs_info *fs_info)
3909{ 3911{
3910 struct btrfs_fs_info *fs_info = root->fs_info; 3912 struct btrfs_root *root = fs_info->tree_root;
3911 int ret; 3913 int ret;
3912 3914
3913 set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags); 3915 set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags);
@@ -3944,7 +3946,7 @@ void close_ctree(struct btrfs_root *root)
3944 */ 3946 */
3945 btrfs_delete_unused_bgs(root->fs_info); 3947 btrfs_delete_unused_bgs(root->fs_info);
3946 3948
3947 ret = btrfs_commit_super(root); 3949 ret = btrfs_commit_super(fs_info);
3948 if (ret) 3950 if (ret)
3949 btrfs_err(fs_info, "commit super ret %d", ret); 3951 btrfs_err(fs_info, "commit super ret %d", ret);
3950 } 3952 }