aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 89e99eb384db..7aa9cd36bf1b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1144,7 +1144,6 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
1144 root->orphan_item_inserted = 0; 1144 root->orphan_item_inserted = 0;
1145 root->orphan_cleanup_state = 0; 1145 root->orphan_cleanup_state = 0;
1146 1146
1147 root->fs_info = fs_info;
1148 root->objectid = objectid; 1147 root->objectid = objectid;
1149 root->last_trans = 0; 1148 root->last_trans = 0;
1150 root->highest_objectid = 0; 1149 root->highest_objectid = 0;
@@ -1218,6 +1217,14 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
1218 return 0; 1217 return 0;
1219} 1218}
1220 1219
1220static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1221{
1222 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS);
1223 if (root)
1224 root->fs_info = fs_info;
1225 return root;
1226}
1227
1221static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, 1228static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1222 struct btrfs_fs_info *fs_info) 1229 struct btrfs_fs_info *fs_info)
1223{ 1230{
@@ -1225,7 +1232,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1225 struct btrfs_root *tree_root = fs_info->tree_root; 1232 struct btrfs_root *tree_root = fs_info->tree_root;
1226 struct extent_buffer *leaf; 1233 struct extent_buffer *leaf;
1227 1234
1228 root = kzalloc(sizeof(*root), GFP_NOFS); 1235 root = btrfs_alloc_root(fs_info);
1229 if (!root) 1236 if (!root)
1230 return ERR_PTR(-ENOMEM); 1237 return ERR_PTR(-ENOMEM);
1231 1238
@@ -1320,7 +1327,7 @@ struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root,
1320 u32 blocksize; 1327 u32 blocksize;
1321 int ret = 0; 1328 int ret = 0;
1322 1329
1323 root = kzalloc(sizeof(*root), GFP_NOFS); 1330 root = btrfs_alloc_root(fs_info);
1324 if (!root) 1331 if (!root)
1325 return ERR_PTR(-ENOMEM); 1332 return ERR_PTR(-ENOMEM);
1326 if (location->offset == (u64)-1) { 1333 if (location->offset == (u64)-1) {
@@ -1876,9 +1883,9 @@ static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
1876} 1883}
1877 1884
1878 1885
1879struct btrfs_root *open_ctree(struct super_block *sb, 1886int open_ctree(struct super_block *sb,
1880 struct btrfs_fs_devices *fs_devices, 1887 struct btrfs_fs_devices *fs_devices,
1881 char *options) 1888 char *options)
1882{ 1889{
1883 u32 sectorsize; 1890 u32 sectorsize;
1884 u32 nodesize; 1891 u32 nodesize;
@@ -1890,8 +1897,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1890 struct btrfs_key location; 1897 struct btrfs_key location;
1891 struct buffer_head *bh; 1898 struct buffer_head *bh;
1892 struct btrfs_super_block *disk_super; 1899 struct btrfs_super_block *disk_super;
1893 struct btrfs_root *tree_root = btrfs_sb(sb); 1900 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1894 struct btrfs_fs_info *fs_info = tree_root->fs_info; 1901 struct btrfs_root *tree_root;
1895 struct btrfs_root *extent_root; 1902 struct btrfs_root *extent_root;
1896 struct btrfs_root *csum_root; 1903 struct btrfs_root *csum_root;
1897 struct btrfs_root *chunk_root; 1904 struct btrfs_root *chunk_root;
@@ -1902,16 +1909,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1902 int num_backups_tried = 0; 1909 int num_backups_tried = 0;
1903 int backup_index = 0; 1910 int backup_index = 0;
1904 1911
1905 extent_root = fs_info->extent_root = 1912 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
1906 kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1913 extent_root = fs_info->extent_root = btrfs_alloc_root(fs_info);
1907 csum_root = fs_info->csum_root = 1914 csum_root = fs_info->csum_root = btrfs_alloc_root(fs_info);
1908 kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1915 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
1909 chunk_root = fs_info->chunk_root = 1916 dev_root = fs_info->dev_root = btrfs_alloc_root(fs_info);
1910 kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
1911 dev_root = fs_info->dev_root =
1912 kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
1913 1917
1914 if (!extent_root || !csum_root || !chunk_root || !dev_root) { 1918 if (!tree_root || !extent_root || !csum_root ||
1919 !chunk_root || !dev_root) {
1915 err = -ENOMEM; 1920 err = -ENOMEM;
1916 goto fail; 1921 goto fail;
1917 } 1922 }
@@ -2389,7 +2394,7 @@ retry_root_backup:
2389 btrfs_level_size(tree_root, 2394 btrfs_level_size(tree_root,
2390 btrfs_super_log_root_level(disk_super)); 2395 btrfs_super_log_root_level(disk_super));
2391 2396
2392 log_tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 2397 log_tree_root = btrfs_alloc_root(fs_info);
2393 if (!log_tree_root) { 2398 if (!log_tree_root) {
2394 err = -ENOMEM; 2399 err = -ENOMEM;
2395 goto fail_trans_kthread; 2400 goto fail_trans_kthread;
@@ -2450,11 +2455,11 @@ retry_root_backup:
2450 2455
2451 if (err) { 2456 if (err) {
2452 close_ctree(tree_root); 2457 close_ctree(tree_root);
2453 return ERR_PTR(err); 2458 return err;
2454 } 2459 }
2455 } 2460 }
2456 2461
2457 return tree_root; 2462 return 0;
2458 2463
2459fail_trans_kthread: 2464fail_trans_kthread:
2460 kthread_stop(fs_info->transaction_kthread); 2465 kthread_stop(fs_info->transaction_kthread);
@@ -2500,8 +2505,7 @@ fail_srcu:
2500 cleanup_srcu_struct(&fs_info->subvol_srcu); 2505 cleanup_srcu_struct(&fs_info->subvol_srcu);
2501fail: 2506fail:
2502 btrfs_close_devices(fs_info->fs_devices); 2507 btrfs_close_devices(fs_info->fs_devices);
2503 free_fs_info(fs_info); 2508 return err;
2504 return ERR_PTR(err);
2505 2509
2506recovery_tree_root: 2510recovery_tree_root:
2507 if (!btrfs_test_opt(tree_root, RECOVERY)) 2511 if (!btrfs_test_opt(tree_root, RECOVERY))
@@ -3007,7 +3011,7 @@ int close_ctree(struct btrfs_root *root)
3007 (atomic_read(&fs_info->defrag_running) == 0)); 3011 (atomic_read(&fs_info->defrag_running) == 0));
3008 3012
3009 /* clear out the rbtree of defraggable inodes */ 3013 /* clear out the rbtree of defraggable inodes */
3010 btrfs_run_defrag_inodes(root->fs_info); 3014 btrfs_run_defrag_inodes(fs_info);
3011 3015
3012 /* 3016 /*
3013 * Here come 2 situations when btrfs is broken to flip readonly: 3017 * Here come 2 situations when btrfs is broken to flip readonly:
@@ -3036,8 +3040,8 @@ int close_ctree(struct btrfs_root *root)
3036 3040
3037 btrfs_put_block_group_cache(fs_info); 3041 btrfs_put_block_group_cache(fs_info);
3038 3042
3039 kthread_stop(root->fs_info->transaction_kthread); 3043 kthread_stop(fs_info->transaction_kthread);
3040 kthread_stop(root->fs_info->cleaner_kthread); 3044 kthread_stop(fs_info->cleaner_kthread);
3041 3045
3042 fs_info->closing = 2; 3046 fs_info->closing = 2;
3043 smp_mb(); 3047 smp_mb();
@@ -3055,14 +3059,14 @@ int close_ctree(struct btrfs_root *root)
3055 free_extent_buffer(fs_info->extent_root->commit_root); 3059 free_extent_buffer(fs_info->extent_root->commit_root);
3056 free_extent_buffer(fs_info->tree_root->node); 3060 free_extent_buffer(fs_info->tree_root->node);
3057 free_extent_buffer(fs_info->tree_root->commit_root); 3061 free_extent_buffer(fs_info->tree_root->commit_root);
3058 free_extent_buffer(root->fs_info->chunk_root->node); 3062 free_extent_buffer(fs_info->chunk_root->node);
3059 free_extent_buffer(root->fs_info->chunk_root->commit_root); 3063 free_extent_buffer(fs_info->chunk_root->commit_root);
3060 free_extent_buffer(root->fs_info->dev_root->node); 3064 free_extent_buffer(fs_info->dev_root->node);
3061 free_extent_buffer(root->fs_info->dev_root->commit_root); 3065 free_extent_buffer(fs_info->dev_root->commit_root);
3062 free_extent_buffer(root->fs_info->csum_root->node); 3066 free_extent_buffer(fs_info->csum_root->node);
3063 free_extent_buffer(root->fs_info->csum_root->commit_root); 3067 free_extent_buffer(fs_info->csum_root->commit_root);
3064 3068
3065 btrfs_free_block_groups(root->fs_info); 3069 btrfs_free_block_groups(fs_info);
3066 3070
3067 del_fs_roots(fs_info); 3071 del_fs_roots(fs_info);
3068 3072
@@ -3093,8 +3097,6 @@ int close_ctree(struct btrfs_root *root)
3093 bdi_destroy(&fs_info->bdi); 3097 bdi_destroy(&fs_info->bdi);
3094 cleanup_srcu_struct(&fs_info->subvol_srcu); 3098 cleanup_srcu_struct(&fs_info->subvol_srcu);
3095 3099
3096 free_fs_info(fs_info);
3097
3098 return 0; 3100 return 0;
3099} 3101}
3100 3102