aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/disk-io.c15
-rw-r--r--fs/btrfs/disk-io.h3
-rw-r--r--fs/btrfs/tests/btrfs-tests.c20
-rw-r--r--fs/btrfs/tests/btrfs-tests.h1
-rw-r--r--fs/btrfs/tests/extent-buffer-tests.c23
-rw-r--r--fs/btrfs/tests/free-space-tests.c14
-rw-r--r--fs/btrfs/tests/free-space-tree-tests.c18
-rw-r--r--fs/btrfs/tests/inode-tests.c46
-rw-r--r--fs/btrfs/tests/qgroup-tests.c23
10 files changed, 103 insertions, 61 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 61a53cca5963..1cb84e01f2fd 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
117#define BTRFS_FS_STATE_REMOUNTING 1 117#define BTRFS_FS_STATE_REMOUNTING 1
118#define BTRFS_FS_STATE_TRANS_ABORTED 2 118#define BTRFS_FS_STATE_TRANS_ABORTED 2
119#define BTRFS_FS_STATE_DEV_REPLACING 3 119#define BTRFS_FS_STATE_DEV_REPLACING 3
120#define BTRFS_FS_STATE_DUMMY_FS_INFO 4
120 121
121#define BTRFS_BACKREF_REV_MAX 256 122#define BTRFS_BACKREF_REV_MAX 256
122#define BTRFS_BACKREF_REV_SHIFT 56 123#define BTRFS_BACKREF_REV_SHIFT 56
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 802a3113854f..8e838b1cc806 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
1233 struct btrfs_root *root, struct btrfs_fs_info *fs_info, 1233 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
1234 u64 objectid) 1234 u64 objectid)
1235{ 1235{
1236 bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
1236 root->node = NULL; 1237 root->node = NULL;
1237 root->commit_root = NULL; 1238 root->commit_root = NULL;
1238 root->sectorsize = sectorsize; 1239 root->sectorsize = sectorsize;
@@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
1287 root->log_transid = 0; 1288 root->log_transid = 0;
1288 root->log_transid_committed = -1; 1289 root->log_transid_committed = -1;
1289 root->last_log_commit = 0; 1290 root->last_log_commit = 0;
1290 if (fs_info) 1291 if (!dummy)
1291 extent_io_tree_init(&root->dirty_log_pages, 1292 extent_io_tree_init(&root->dirty_log_pages,
1292 fs_info->btree_inode->i_mapping); 1293 fs_info->btree_inode->i_mapping);
1293 1294
1294 memset(&root->root_key, 0, sizeof(root->root_key)); 1295 memset(&root->root_key, 0, sizeof(root->root_key));
1295 memset(&root->root_item, 0, sizeof(root->root_item)); 1296 memset(&root->root_item, 0, sizeof(root->root_item));
1296 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); 1297 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
1297 if (fs_info) 1298 if (!dummy)
1298 root->defrag_trans_start = fs_info->generation; 1299 root->defrag_trans_start = fs_info->generation;
1299 else 1300 else
1300 root->defrag_trans_start = 0; 1301 root->defrag_trans_start = 0;
@@ -1315,15 +1316,19 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
1315 1316
1316#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 1317#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1317/* Should only be used by the testing infrastructure */ 1318/* Should only be used by the testing infrastructure */
1318struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize) 1319struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
1320 u32 sectorsize, u32 nodesize)
1319{ 1321{
1320 struct btrfs_root *root; 1322 struct btrfs_root *root;
1321 1323
1322 root = btrfs_alloc_root(NULL, GFP_KERNEL); 1324 if (!fs_info)
1325 return ERR_PTR(-EINVAL);
1326
1327 root = btrfs_alloc_root(fs_info, GFP_KERNEL);
1323 if (!root) 1328 if (!root)
1324 return ERR_PTR(-ENOMEM); 1329 return ERR_PTR(-ENOMEM);
1325 /* We don't use the stripesize in selftest, set it as sectorsize */ 1330 /* We don't use the stripesize in selftest, set it as sectorsize */
1326 __setup_root(nodesize, sectorsize, sectorsize, root, NULL, 1331 __setup_root(nodesize, sectorsize, sectorsize, root, fs_info,
1327 BTRFS_ROOT_TREE_OBJECTID); 1332 BTRFS_ROOT_TREE_OBJECTID);
1328 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); 1333 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
1329 root->alloc_bytenr = 0; 1334 root->alloc_bytenr = 0;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index acba821499a9..c9d42c92da2b 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -90,7 +90,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
90void btrfs_free_fs_root(struct btrfs_root *root); 90void btrfs_free_fs_root(struct btrfs_root *root);
91 91
92#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 92#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
93struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize); 93struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
94 u32 sectorsize, u32 nodesize);
94#endif 95#endif
95 96
96/* 97/*
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 71d9a0129347..bf62ad919a95 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -128,14 +128,27 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void)
128 extent_io_tree_init(&fs_info->freed_extents[0], NULL); 128 extent_io_tree_init(&fs_info->freed_extents[0], NULL);
129 extent_io_tree_init(&fs_info->freed_extents[1], NULL); 129 extent_io_tree_init(&fs_info->freed_extents[1], NULL);
130 fs_info->pinned_extents = &fs_info->freed_extents[0]; 130 fs_info->pinned_extents = &fs_info->freed_extents[0];
131 set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
132
133 test_mnt->mnt_sb->s_fs_info = fs_info;
134
131 return fs_info; 135 return fs_info;
132} 136}
133 137
134static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info) 138void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
135{ 139{
136 struct radix_tree_iter iter; 140 struct radix_tree_iter iter;
137 void **slot; 141 void **slot;
138 142
143 if (!fs_info)
144 return;
145
146 if (WARN_ON(!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
147 &fs_info->fs_state)))
148 return;
149
150 test_mnt->mnt_sb->s_fs_info = NULL;
151
139 spin_lock(&fs_info->buffer_lock); 152 spin_lock(&fs_info->buffer_lock);
140 radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) { 153 radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
141 struct extent_buffer *eb; 154 struct extent_buffer *eb;
@@ -167,10 +180,11 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
167{ 180{
168 if (!root) 181 if (!root)
169 return; 182 return;
183 /* Will be freed by btrfs_free_fs_roots */
184 if (WARN_ON(test_bit(BTRFS_ROOT_IN_RADIX, &root->state)))
185 return;
170 if (root->node) 186 if (root->node)
171 free_extent_buffer(root->node); 187 free_extent_buffer(root->node);
172 if (root->fs_info)
173 btrfs_free_dummy_fs_info(root->fs_info);
174 kfree(root); 188 kfree(root);
175} 189}
176 190
diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
index e7d364f315db..b17ffbe8f9f3 100644
--- a/fs/btrfs/tests/btrfs-tests.h
+++ b/fs/btrfs/tests/btrfs-tests.h
@@ -35,6 +35,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
35int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); 35int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
36struct inode *btrfs_new_test_inode(void); 36struct inode *btrfs_new_test_inode(void);
37struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void); 37struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
38void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info);
38void btrfs_free_dummy_root(struct btrfs_root *root); 39void btrfs_free_dummy_root(struct btrfs_root *root);
39struct btrfs_block_group_cache * 40struct btrfs_block_group_cache *
40btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize); 41btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
diff --git a/fs/btrfs/tests/extent-buffer-tests.c b/fs/btrfs/tests/extent-buffer-tests.c
index 4f8cbd1ec5ee..199569174637 100644
--- a/fs/btrfs/tests/extent-buffer-tests.c
+++ b/fs/btrfs/tests/extent-buffer-tests.c
@@ -24,8 +24,9 @@
24 24
25static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) 25static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
26{ 26{
27 struct btrfs_path *path; 27 struct btrfs_fs_info *fs_info;
28 struct btrfs_root *root; 28 struct btrfs_path *path = NULL;
29 struct btrfs_root *root = NULL;
29 struct extent_buffer *eb; 30 struct extent_buffer *eb;
30 struct btrfs_item *item; 31 struct btrfs_item *item;
31 char *value = "mary had a little lamb"; 32 char *value = "mary had a little lamb";
@@ -40,17 +41,24 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
40 41
41 test_msg("Running btrfs_split_item tests\n"); 42 test_msg("Running btrfs_split_item tests\n");
42 43
43 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 44 fs_info = btrfs_alloc_dummy_fs_info();
45 if (!fs_info) {
46 test_msg("Could not allocate fs_info\n");
47 return -ENOMEM;
48 }
49
50 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
44 if (IS_ERR(root)) { 51 if (IS_ERR(root)) {
45 test_msg("Could not allocate root\n"); 52 test_msg("Could not allocate root\n");
46 return PTR_ERR(root); 53 ret = PTR_ERR(root);
54 goto out;
47 } 55 }
48 56
49 path = btrfs_alloc_path(); 57 path = btrfs_alloc_path();
50 if (!path) { 58 if (!path) {
51 test_msg("Could not allocate path\n"); 59 test_msg("Could not allocate path\n");
52 kfree(root); 60 ret = -ENOMEM;
53 return -ENOMEM; 61 goto out;
54 } 62 }
55 63
56 path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize, 64 path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize,
@@ -219,7 +227,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
219 } 227 }
220out: 228out:
221 btrfs_free_path(path); 229 btrfs_free_path(path);
222 kfree(root); 230 btrfs_free_dummy_root(root);
231 btrfs_free_dummy_fs_info(fs_info);
223 return ret; 232 return ret;
224} 233}
225 234
diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
index 3956bb2ff84c..3221c8dee272 100644
--- a/fs/btrfs/tests/free-space-tests.c
+++ b/fs/btrfs/tests/free-space-tests.c
@@ -837,6 +837,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache,
837 837
838int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize) 838int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
839{ 839{
840 struct btrfs_fs_info *fs_info;
840 struct btrfs_block_group_cache *cache; 841 struct btrfs_block_group_cache *cache;
841 struct btrfs_root *root = NULL; 842 struct btrfs_root *root = NULL;
842 int ret = -ENOMEM; 843 int ret = -ENOMEM;
@@ -855,15 +856,17 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
855 return 0; 856 return 0;
856 } 857 }
857 858
858 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 859 fs_info = btrfs_alloc_dummy_fs_info();
859 if (IS_ERR(root)) { 860 if (!fs_info) {
860 ret = PTR_ERR(root); 861 ret = -ENOMEM;
861 goto out; 862 goto out;
862 } 863 }
863 864
864 root->fs_info = btrfs_alloc_dummy_fs_info(); 865 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
865 if (!root->fs_info) 866 if (IS_ERR(root)) {
867 ret = PTR_ERR(root);
866 goto out; 868 goto out;
869 }
867 870
868 root->fs_info->extent_root = root; 871 root->fs_info->extent_root = root;
869 cache->fs_info = root->fs_info; 872 cache->fs_info = root->fs_info;
@@ -882,6 +885,7 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
882out: 885out:
883 btrfs_free_dummy_block_group(cache); 886 btrfs_free_dummy_block_group(cache);
884 btrfs_free_dummy_root(root); 887 btrfs_free_dummy_root(root);
888 btrfs_free_dummy_fs_info(fs_info);
885 test_msg("Free space cache tests finished\n"); 889 test_msg("Free space cache tests finished\n");
886 return ret; 890 return ret;
887} 891}
diff --git a/fs/btrfs/tests/free-space-tree-tests.c b/fs/btrfs/tests/free-space-tree-tests.c
index aac507085ab0..7508d3b42780 100644
--- a/fs/btrfs/tests/free-space-tree-tests.c
+++ b/fs/btrfs/tests/free-space-tree-tests.c
@@ -443,23 +443,24 @@ typedef int (*test_func_t)(struct btrfs_trans_handle *,
443static int run_test(test_func_t test_func, int bitmaps, 443static int run_test(test_func_t test_func, int bitmaps,
444 u32 sectorsize, u32 nodesize) 444 u32 sectorsize, u32 nodesize)
445{ 445{
446 struct btrfs_fs_info *fs_info;
446 struct btrfs_root *root = NULL; 447 struct btrfs_root *root = NULL;
447 struct btrfs_block_group_cache *cache = NULL; 448 struct btrfs_block_group_cache *cache = NULL;
448 struct btrfs_trans_handle trans; 449 struct btrfs_trans_handle trans;
449 struct btrfs_path *path = NULL; 450 struct btrfs_path *path = NULL;
450 int ret; 451 int ret;
451 452
452 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 453 fs_info = btrfs_alloc_dummy_fs_info();
453 if (IS_ERR(root)) { 454 if (!fs_info) {
454 test_msg("Couldn't allocate dummy root\n"); 455 test_msg("Couldn't allocate dummy fs info\n");
455 ret = PTR_ERR(root); 456 ret = -ENOMEM;
456 goto out; 457 goto out;
457 } 458 }
458 459
459 root->fs_info = btrfs_alloc_dummy_fs_info(); 460 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
460 if (!root->fs_info) { 461 if (IS_ERR(root)) {
461 test_msg("Couldn't allocate dummy fs info\n"); 462 test_msg("Couldn't allocate dummy root\n");
462 ret = -ENOMEM; 463 ret = PTR_ERR(root);
463 goto out; 464 goto out;
464 } 465 }
465 466
@@ -534,6 +535,7 @@ out:
534 btrfs_free_path(path); 535 btrfs_free_path(path);
535 btrfs_free_dummy_block_group(cache); 536 btrfs_free_dummy_block_group(cache);
536 btrfs_free_dummy_root(root); 537 btrfs_free_dummy_root(root);
538 btrfs_free_dummy_fs_info(fs_info);
537 return ret; 539 return ret;
538} 540}
539 541
diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c
index 29648c0a39f1..9f72aeda9220 100644
--- a/fs/btrfs/tests/inode-tests.c
+++ b/fs/btrfs/tests/inode-tests.c
@@ -230,6 +230,7 @@ static unsigned long vacancy_only = 0;
230 230
231static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize) 231static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
232{ 232{
233 struct btrfs_fs_info *fs_info = NULL;
233 struct inode *inode = NULL; 234 struct inode *inode = NULL;
234 struct btrfs_root *root = NULL; 235 struct btrfs_root *root = NULL;
235 struct extent_map *em = NULL; 236 struct extent_map *em = NULL;
@@ -248,19 +249,15 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
248 BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; 249 BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
249 BTRFS_I(inode)->location.offset = 0; 250 BTRFS_I(inode)->location.offset = 0;
250 251
251 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 252 fs_info = btrfs_alloc_dummy_fs_info();
252 if (IS_ERR(root)) { 253 if (!fs_info) {
253 test_msg("Couldn't allocate root\n"); 254 test_msg("Couldn't allocate dummy fs info\n");
254 goto out; 255 goto out;
255 } 256 }
256 257
257 /* 258 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
258 * We do this since btrfs_get_extent wants to assign em->bdev to 259 if (IS_ERR(root)) {
259 * root->fs_info->fs_devices->latest_bdev. 260 test_msg("Couldn't allocate root\n");
260 */
261 root->fs_info = btrfs_alloc_dummy_fs_info();
262 if (!root->fs_info) {
263 test_msg("Couldn't allocate dummy fs info\n");
264 goto out; 261 goto out;
265 } 262 }
266 263
@@ -835,11 +832,13 @@ out:
835 free_extent_map(em); 832 free_extent_map(em);
836 iput(inode); 833 iput(inode);
837 btrfs_free_dummy_root(root); 834 btrfs_free_dummy_root(root);
835 btrfs_free_dummy_fs_info(fs_info);
838 return ret; 836 return ret;
839} 837}
840 838
841static int test_hole_first(u32 sectorsize, u32 nodesize) 839static int test_hole_first(u32 sectorsize, u32 nodesize)
842{ 840{
841 struct btrfs_fs_info *fs_info = NULL;
843 struct inode *inode = NULL; 842 struct inode *inode = NULL;
844 struct btrfs_root *root = NULL; 843 struct btrfs_root *root = NULL;
845 struct extent_map *em = NULL; 844 struct extent_map *em = NULL;
@@ -855,15 +854,15 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
855 BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID; 854 BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
856 BTRFS_I(inode)->location.offset = 0; 855 BTRFS_I(inode)->location.offset = 0;
857 856
858 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 857 fs_info = btrfs_alloc_dummy_fs_info();
859 if (IS_ERR(root)) { 858 if (!fs_info) {
860 test_msg("Couldn't allocate root\n"); 859 test_msg("Couldn't allocate dummy fs info\n");
861 goto out; 860 goto out;
862 } 861 }
863 862
864 root->fs_info = btrfs_alloc_dummy_fs_info(); 863 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
865 if (!root->fs_info) { 864 if (IS_ERR(root)) {
866 test_msg("Couldn't allocate dummy fs info\n"); 865 test_msg("Couldn't allocate root\n");
867 goto out; 866 goto out;
868 } 867 }
869 868
@@ -934,11 +933,13 @@ out:
934 free_extent_map(em); 933 free_extent_map(em);
935 iput(inode); 934 iput(inode);
936 btrfs_free_dummy_root(root); 935 btrfs_free_dummy_root(root);
936 btrfs_free_dummy_fs_info(fs_info);
937 return ret; 937 return ret;
938} 938}
939 939
940static int test_extent_accounting(u32 sectorsize, u32 nodesize) 940static int test_extent_accounting(u32 sectorsize, u32 nodesize)
941{ 941{
942 struct btrfs_fs_info *fs_info = NULL;
942 struct inode *inode = NULL; 943 struct inode *inode = NULL;
943 struct btrfs_root *root = NULL; 944 struct btrfs_root *root = NULL;
944 int ret = -ENOMEM; 945 int ret = -ENOMEM;
@@ -949,15 +950,15 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
949 return ret; 950 return ret;
950 } 951 }
951 952
952 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 953 fs_info = btrfs_alloc_dummy_fs_info();
953 if (IS_ERR(root)) { 954 if (!fs_info) {
954 test_msg("Couldn't allocate root\n"); 955 test_msg("Couldn't allocate dummy fs info\n");
955 goto out; 956 goto out;
956 } 957 }
957 958
958 root->fs_info = btrfs_alloc_dummy_fs_info(); 959 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
959 if (!root->fs_info) { 960 if (IS_ERR(root)) {
960 test_msg("Couldn't allocate dummy fs info\n"); 961 test_msg("Couldn't allocate root\n");
961 goto out; 962 goto out;
962 } 963 }
963 964
@@ -1132,6 +1133,7 @@ out:
1132 NULL, GFP_KERNEL); 1133 NULL, GFP_KERNEL);
1133 iput(inode); 1134 iput(inode);
1134 btrfs_free_dummy_root(root); 1135 btrfs_free_dummy_root(root);
1136 btrfs_free_dummy_fs_info(fs_info);
1135 return ret; 1137 return ret;
1136} 1138}
1137 1139
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c
index 57a12c0d680b..4407fef7c16c 100644
--- a/fs/btrfs/tests/qgroup-tests.c
+++ b/fs/btrfs/tests/qgroup-tests.c
@@ -453,22 +453,24 @@ static int test_multiple_refs(struct btrfs_root *root,
453 453
454int btrfs_test_qgroups(u32 sectorsize, u32 nodesize) 454int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
455{ 455{
456 struct btrfs_fs_info *fs_info = NULL;
456 struct btrfs_root *root; 457 struct btrfs_root *root;
457 struct btrfs_root *tmp_root; 458 struct btrfs_root *tmp_root;
458 int ret = 0; 459 int ret = 0;
459 460
460 root = btrfs_alloc_dummy_root(sectorsize, nodesize); 461 fs_info = btrfs_alloc_dummy_fs_info();
461 if (IS_ERR(root)) { 462 if (!fs_info) {
462 test_msg("Couldn't allocate root\n"); 463 test_msg("Couldn't allocate dummy fs info\n");
463 return PTR_ERR(root); 464 return -ENOMEM;
464 } 465 }
465 466
466 root->fs_info = btrfs_alloc_dummy_fs_info(); 467 root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
467 if (!root->fs_info) { 468 if (IS_ERR(root)) {
468 test_msg("Couldn't allocate dummy fs info\n"); 469 test_msg("Couldn't allocate root\n");
469 ret = -ENOMEM; 470 ret = PTR_ERR(root);
470 goto out; 471 goto out;
471 } 472 }
473
472 /* We are using this root as our extent root */ 474 /* We are using this root as our extent root */
473 root->fs_info->extent_root = root; 475 root->fs_info->extent_root = root;
474 476
@@ -495,7 +497,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
495 btrfs_set_header_nritems(root->node, 0); 497 btrfs_set_header_nritems(root->node, 0);
496 root->alloc_bytenr += 2 * nodesize; 498 root->alloc_bytenr += 2 * nodesize;
497 499
498 tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize); 500 tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
499 if (IS_ERR(tmp_root)) { 501 if (IS_ERR(tmp_root)) {
500 test_msg("Couldn't allocate a fs root\n"); 502 test_msg("Couldn't allocate a fs root\n");
501 ret = PTR_ERR(tmp_root); 503 ret = PTR_ERR(tmp_root);
@@ -510,7 +512,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
510 goto out; 512 goto out;
511 } 513 }
512 514
513 tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize); 515 tmp_root = btrfs_alloc_dummy_root(fs_info, sectorsize, nodesize);
514 if (IS_ERR(tmp_root)) { 516 if (IS_ERR(tmp_root)) {
515 test_msg("Couldn't allocate a fs root\n"); 517 test_msg("Couldn't allocate a fs root\n");
516 ret = PTR_ERR(tmp_root); 518 ret = PTR_ERR(tmp_root);
@@ -531,5 +533,6 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
531 ret = test_multiple_refs(root, sectorsize, nodesize); 533 ret = test_multiple_refs(root, sectorsize, nodesize);
532out: 534out:
533 btrfs_free_dummy_root(root); 535 btrfs_free_dummy_root(root);
536 btrfs_free_dummy_fs_info(fs_info);
534 return ret; 537 return ret;
535} 538}