aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2011-11-17 00:46:16 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2012-01-08 19:34:38 -0500
commit6f07e42ee6fcc252a210781d7262f4051e9fd8f6 (patch)
tree70686d28678c69586570032c47ecdc4636c7a4f3 /fs/btrfs
parent38a77db49ad8f78369dcdfb693b8e5a818a60104 (diff)
btrfs: sanitizing ->fs_info, part 4
A new helper: btrfs_alloc_root(fs_info); allocates btrfs_root and sets ->fs_info. All places allocating the suckers converted to it. At that point we *never* reassign ->fs_info of btrfs_root; it's set before anyone sees the address of newly allocated struct btrfs_root and never assigned anywhere else. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/disk-io.c33
-rw-r--r--fs/btrfs/disk-io.h2
-rw-r--r--fs/btrfs/super.c3
3 files changed, 18 insertions, 20 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 06480fcf0fb3..ee846ce58846 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1215,6 +1215,14 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
1215 return 0; 1215 return 0;
1216} 1216}
1217 1217
1218struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1219{
1220 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS);
1221 if (root)
1222 root->fs_info = fs_info;
1223 return root;
1224}
1225
1218static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, 1226static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1219 struct btrfs_fs_info *fs_info) 1227 struct btrfs_fs_info *fs_info)
1220{ 1228{
@@ -1222,11 +1230,10 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1222 struct btrfs_root *tree_root = fs_info->tree_root; 1230 struct btrfs_root *tree_root = fs_info->tree_root;
1223 struct extent_buffer *leaf; 1231 struct extent_buffer *leaf;
1224 1232
1225 root = kzalloc(sizeof(*root), GFP_NOFS); 1233 root = btrfs_alloc_root(fs_info);
1226 if (!root) 1234 if (!root)
1227 return ERR_PTR(-ENOMEM); 1235 return ERR_PTR(-ENOMEM);
1228 1236
1229 root->fs_info = fs_info;
1230 __setup_root(tree_root->nodesize, tree_root->leafsize, 1237 __setup_root(tree_root->nodesize, tree_root->leafsize,
1231 tree_root->sectorsize, tree_root->stripesize, 1238 tree_root->sectorsize, tree_root->stripesize,
1232 root, fs_info, BTRFS_TREE_LOG_OBJECTID); 1239 root, fs_info, BTRFS_TREE_LOG_OBJECTID);
@@ -1317,10 +1324,9 @@ struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root,
1317 u32 blocksize; 1324 u32 blocksize;
1318 int ret = 0; 1325 int ret = 0;
1319 1326
1320 root = kzalloc(sizeof(*root), GFP_NOFS); 1327 root = btrfs_alloc_root(fs_info);
1321 if (!root) 1328 if (!root)
1322 return ERR_PTR(-ENOMEM); 1329 return ERR_PTR(-ENOMEM);
1323 root->fs_info = fs_info;
1324 if (location->offset == (u64)-1) { 1330 if (location->offset == (u64)-1) {
1325 ret = find_and_setup_root(tree_root, fs_info, 1331 ret = find_and_setup_root(tree_root, fs_info,
1326 location->objectid, root); 1332 location->objectid, root);
@@ -1900,23 +1906,15 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1900 int num_backups_tried = 0; 1906 int num_backups_tried = 0;
1901 int backup_index = 0; 1907 int backup_index = 0;
1902 1908
1903 extent_root = fs_info->extent_root = 1909 extent_root = fs_info->extent_root = btrfs_alloc_root(fs_info);
1904 kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1910 csum_root = fs_info->csum_root = btrfs_alloc_root(fs_info);
1905 csum_root = fs_info->csum_root = 1911 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
1906 kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 1912 dev_root = fs_info->dev_root = btrfs_alloc_root(fs_info);
1907 chunk_root = fs_info->chunk_root =
1908 kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
1909 dev_root = fs_info->dev_root =
1910 kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
1911 1913
1912 if (!extent_root || !csum_root || !chunk_root || !dev_root) { 1914 if (!extent_root || !csum_root || !chunk_root || !dev_root) {
1913 err = -ENOMEM; 1915 err = -ENOMEM;
1914 goto fail; 1916 goto fail;
1915 } 1917 }
1916 chunk_root->fs_info = fs_info;
1917 extent_root->fs_info = fs_info;
1918 dev_root->fs_info = fs_info;
1919 csum_root->fs_info = fs_info;
1920 1918
1921 ret = init_srcu_struct(&fs_info->subvol_srcu); 1919 ret = init_srcu_struct(&fs_info->subvol_srcu);
1922 if (ret) { 1920 if (ret) {
@@ -2372,13 +2370,12 @@ retry_root_backup:
2372 btrfs_level_size(tree_root, 2370 btrfs_level_size(tree_root,
2373 btrfs_super_log_root_level(disk_super)); 2371 btrfs_super_log_root_level(disk_super));
2374 2372
2375 log_tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 2373 log_tree_root = btrfs_alloc_root(fs_info);
2376 if (!log_tree_root) { 2374 if (!log_tree_root) {
2377 err = -ENOMEM; 2375 err = -ENOMEM;
2378 goto fail_trans_kthread; 2376 goto fail_trans_kthread;
2379 } 2377 }
2380 2378
2381 log_tree_root->fs_info = fs_info;
2382 __setup_root(nodesize, leafsize, sectorsize, stripesize, 2379 __setup_root(nodesize, leafsize, sectorsize, stripesize,
2383 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); 2380 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2384 2381
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index c99d0a8f13fa..2bb5f59ddf95 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -86,6 +86,8 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
86int btrfs_add_log_tree(struct btrfs_trans_handle *trans, 86int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
87 struct btrfs_root *root); 87 struct btrfs_root *root);
88 88
89struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info);
90
89#ifdef CONFIG_DEBUG_LOCK_ALLOC 91#ifdef CONFIG_DEBUG_LOCK_ALLOC
90void btrfs_init_lockdep(void); 92void btrfs_init_lockdep(void);
91void btrfs_set_buffer_lockdep_class(u64 objectid, 93void btrfs_set_buffer_lockdep_class(u64 objectid,
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index b9fd62a0fca2..e9f876a1655b 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -901,12 +901,11 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
901 if (!fs_info) 901 if (!fs_info)
902 return ERR_PTR(-ENOMEM); 902 return ERR_PTR(-ENOMEM);
903 903
904 fs_info->tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); 904 fs_info->tree_root = btrfs_alloc_root(fs_info);
905 if (!fs_info->tree_root) { 905 if (!fs_info->tree_root) {
906 error = -ENOMEM; 906 error = -ENOMEM;
907 goto error_fs_info; 907 goto error_fs_info;
908 } 908 }
909 fs_info->tree_root->fs_info = fs_info;
910 fs_info->fs_devices = fs_devices; 909 fs_info->fs_devices = fs_devices;
911 910
912 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS); 911 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);