Skip to content

Commit f274115

Browse files
kdavesmb49
authored andcommitted
btrfs: tests: allocate dummy fs_info and root in test_find_delalloc()
BugLink: https://bugs.launchpad.net/bugs/2065912 commit b2136cc288fce2f24a92f3d656531b2d50ebec5a upstream. Allocate fs_info and root to have a valid fs_info pointer in case it's dereferenced by a helper outside of tests, like find_lock_delalloc_range(). Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent a0747a0 commit f274115

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

fs/btrfs/tests/extent-io-tests.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "btrfs-tests.h"
1212
#include "../ctree.h"
1313
#include "../extent_io.h"
14+
#include "../disk-io.h"
1415
#include "../btrfs_inode.h"
1516

1617
#define PROCESS_UNLOCK (1 << 0)
@@ -105,9 +106,11 @@ static void dump_extent_io_tree(const struct extent_io_tree *tree)
105106
}
106107
}
107108

108-
static int test_find_delalloc(u32 sectorsize)
109+
static int test_find_delalloc(u32 sectorsize, u32 nodesize)
109110
{
110-
struct inode *inode;
111+
struct btrfs_fs_info *fs_info;
112+
struct btrfs_root *root = NULL;
113+
struct inode *inode = NULL;
111114
struct extent_io_tree *tmp;
112115
struct page *page;
113116
struct page *locked_page = NULL;
@@ -121,12 +124,27 @@ static int test_find_delalloc(u32 sectorsize)
121124

122125
test_msg("running find delalloc tests");
123126

127+
fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
128+
if (!fs_info) {
129+
test_std_err(TEST_ALLOC_FS_INFO);
130+
return -ENOMEM;
131+
}
132+
133+
root = btrfs_alloc_dummy_root(fs_info);
134+
if (IS_ERR(root)) {
135+
test_std_err(TEST_ALLOC_ROOT);
136+
ret = PTR_ERR(root);
137+
goto out;
138+
}
139+
124140
inode = btrfs_new_test_inode();
125141
if (!inode) {
126142
test_std_err(TEST_ALLOC_INODE);
127-
return -ENOMEM;
143+
ret = -ENOMEM;
144+
goto out;
128145
}
129146
tmp = &BTRFS_I(inode)->io_tree;
147+
BTRFS_I(inode)->root = root;
130148

131149
/*
132150
* Passing NULL as we don't have fs_info but tracepoints are not used
@@ -316,6 +334,8 @@ static int test_find_delalloc(u32 sectorsize)
316334
process_page_range(inode, 0, total_dirty - 1,
317335
PROCESS_UNLOCK | PROCESS_RELEASE);
318336
iput(inode);
337+
btrfs_free_dummy_root(root);
338+
btrfs_free_dummy_fs_info(fs_info);
319339
return ret;
320340
}
321341

@@ -794,7 +814,7 @@ int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
794814

795815
test_msg("running extent I/O tests");
796816

797-
ret = test_find_delalloc(sectorsize);
817+
ret = test_find_delalloc(sectorsize, nodesize);
798818
if (ret)
799819
goto out;
800820

0 commit comments

Comments
 (0)