Skip to content

Commit

Permalink
Btrfs: self-tests: Support non-4k page size
Browse files Browse the repository at this point in the history
self-tests code assumes 4k as the sectorsize and nodesize. This commit
fix hardcoded 4K. Enables the self-tests code to be executed on non-4k
page sized systems (e.g. ppc64).

Reviewed-by: Josef Bacik <[email protected]>
Signed-off-by: Feifei Xu <[email protected]>
Signed-off-by: Chandan Rajendra <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
Feifei Xu authored and kdave committed Jun 2, 2016
1 parent 0ef6447 commit b9ef22d
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 291 deletions.
6 changes: 4 additions & 2 deletions fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,8 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path,

if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
BUG_ON(tm->slot != 0);
eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start);
eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start,
eb->len);
if (!eb_rewin) {
btrfs_tree_read_unlock_blocking(eb);
free_extent_buffer(eb);
Expand Down Expand Up @@ -1454,7 +1455,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
} else if (old_root) {
btrfs_tree_read_unlock(eb_root);
free_extent_buffer(eb_root);
eb = alloc_dummy_extent_buffer(root->fs_info, logical);
eb = alloc_dummy_extent_buffer(root->fs_info, logical,
root->nodesize);
} else {
btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK);
eb = btrfs_clone_extent_buffer(eb_root);
Expand Down
8 changes: 5 additions & 3 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 bytenr)
{
if (btrfs_test_is_dummy_root(root))
return alloc_test_extent_buffer(root->fs_info, bytenr);
return alloc_test_extent_buffer(root->fs_info, bytenr,
root->nodesize);
return alloc_extent_buffer(root->fs_info, bytenr);
}

Expand Down Expand Up @@ -1314,14 +1315,15 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
/* Should only be used by the testing infrastructure */
struct btrfs_root *btrfs_alloc_dummy_root(void)
struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize)
{
struct btrfs_root *root;

root = btrfs_alloc_root(NULL, GFP_KERNEL);
if (!root)
return ERR_PTR(-ENOMEM);
__setup_root(4096, 4096, 4096, root, NULL, 1);
/* We don't use the stripesize in selftest, set it as sectorsize */
__setup_root(nodesize, sectorsize, sectorsize, root, NULL, 1);
set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
root->alloc_bytenr = 0;

Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
void btrfs_free_fs_root(struct btrfs_root *root);

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
struct btrfs_root *btrfs_alloc_dummy_root(void);
struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize);
#endif

/*
Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4718,16 +4718,16 @@ struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
}

struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start)
u64 start, u32 nodesize)
{
unsigned long len;

if (!fs_info) {
/*
* Called only from tests that don't always have a fs_info
* available, but we know that nodesize is 4096
* available
*/
len = 4096;
len = nodesize;
} else {
len = fs_info->tree_root->nodesize;
}
Expand Down Expand Up @@ -4823,15 +4823,15 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start)
u64 start, u32 nodesize)
{
struct extent_buffer *eb, *exists = NULL;
int ret;

eb = find_extent_buffer(fs_info, start);
if (eb)
return eb;
eb = alloc_dummy_extent_buffer(fs_info, start);
eb = alloc_dummy_extent_buffer(fs_info, start, nodesize);
if (!eb)
return NULL;
eb->fs_info = fs_info;
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/extent_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start, unsigned long len);
struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start);
u64 start, u32 nodesize);
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start);
Expand Down Expand Up @@ -468,5 +468,5 @@ noinline u64 find_lock_delalloc_range(struct inode *inode,
u64 *end, u64 max_bytes);
#endif
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start);
u64 start, u32 nodesize);
#endif
2 changes: 1 addition & 1 deletion fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
* sure we don't go over our overall goal of MAX_CACHE_BYTES_PER_GIG as
* we add more bitmaps.
*/
bitmap_bytes = (ctl->total_bitmaps + 1) * PAGE_SIZE;
bitmap_bytes = (ctl->total_bitmaps + 1) * ctl->unit;

if (bitmap_bytes >= max_bytes) {
ctl->extents_thresh = 0;
Expand Down
16 changes: 10 additions & 6 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,27 +2319,31 @@ static void btrfs_print_mod_info(void)
static int btrfs_run_sanity_tests(void)
{
int ret;
u32 sectorsize, nodesize;

sectorsize = PAGE_SIZE;
nodesize = PAGE_SIZE;
ret = btrfs_init_test_fs();
if (ret)
return ret;

ret = btrfs_test_free_space_cache();
ret = btrfs_test_free_space_cache(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_extent_buffer_operations();
ret = btrfs_test_extent_buffer_operations(sectorsize,
nodesize);
if (ret)
goto out;
ret = btrfs_test_extent_io();
ret = btrfs_test_extent_io(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_inodes();
ret = btrfs_test_inodes(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_qgroups();
ret = btrfs_test_qgroups(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_free_space_tree();
ret = btrfs_test_free_space_tree(sectorsize, nodesize);
out:
btrfs_destroy_test_fs();
return ret;
Expand Down
6 changes: 3 additions & 3 deletions fs/btrfs/tests/btrfs-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
}

struct btrfs_block_group_cache *
btrfs_alloc_dummy_block_group(unsigned long length)
btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize)
{
struct btrfs_block_group_cache *cache;

Expand All @@ -192,8 +192,8 @@ btrfs_alloc_dummy_block_group(unsigned long length)
cache->key.objectid = 0;
cache->key.offset = length;
cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
cache->sectorsize = 4096;
cache->full_stripe_len = 4096;
cache->sectorsize = sectorsize;
cache->full_stripe_len = sectorsize;

INIT_LIST_HEAD(&cache->list);
INIT_LIST_HEAD(&cache->cluster_list);
Expand Down
27 changes: 14 additions & 13 deletions fs/btrfs/tests/btrfs-tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@
struct btrfs_root;
struct btrfs_trans_handle;

int btrfs_test_free_space_cache(void);
int btrfs_test_extent_buffer_operations(void);
int btrfs_test_extent_io(void);
int btrfs_test_inodes(void);
int btrfs_test_qgroups(void);
int btrfs_test_free_space_tree(void);
int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize);
int btrfs_test_extent_io(u32 sectorsize, u32 nodesize);
int btrfs_test_inodes(u32 sectorsize, u32 nodesize);
int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
int btrfs_init_test_fs(void);
void btrfs_destroy_test_fs(void);
struct inode *btrfs_new_test_inode(void);
struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
void btrfs_free_dummy_root(struct btrfs_root *root);
struct btrfs_block_group_cache *
btrfs_alloc_dummy_block_group(unsigned long length);
btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache);
void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans);
#else
static inline int btrfs_test_free_space_cache(void)
static inline int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
{
return 0;
}
static inline int btrfs_test_extent_buffer_operations(void)
static inline int btrfs_test_extent_buffer_operations(u32 sectorsize,
u32 nodesize)
{
return 0;
}
Expand All @@ -57,19 +58,19 @@ static inline int btrfs_init_test_fs(void)
static inline void btrfs_destroy_test_fs(void)
{
}
static inline int btrfs_test_extent_io(void)
static inline int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
{
return 0;
}
static inline int btrfs_test_inodes(void)
static inline int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
{
return 0;
}
static inline int btrfs_test_qgroups(void)
static inline int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
{
return 0;
}
static inline int btrfs_test_free_space_tree(void)
static inline int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize)
{
return 0;
}
Expand Down
11 changes: 6 additions & 5 deletions fs/btrfs/tests/extent-buffer-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "../extent_io.h"
#include "../disk-io.h"

static int test_btrfs_split_item(void)
static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
{
struct btrfs_path *path;
struct btrfs_root *root;
Expand All @@ -40,7 +40,7 @@ static int test_btrfs_split_item(void)

test_msg("Running btrfs_split_item tests\n");

root = btrfs_alloc_dummy_root();
root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(root)) {
test_msg("Could not allocate root\n");
return PTR_ERR(root);
Expand All @@ -53,7 +53,8 @@ static int test_btrfs_split_item(void)
return -ENOMEM;
}

path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, 4096);
path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, nodesize,
nodesize);
if (!eb) {
test_msg("Could not allocate dummy buffer\n");
ret = -ENOMEM;
Expand Down Expand Up @@ -222,8 +223,8 @@ static int test_btrfs_split_item(void)
return ret;
}

int btrfs_test_extent_buffer_operations(void)
int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize)
{
test_msg("Running extent buffer operation tests");
return test_btrfs_split_item();
return test_btrfs_split_item(sectorsize, nodesize);
}
27 changes: 14 additions & 13 deletions fs/btrfs/tests/extent-io-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
return count;
}

static int test_find_delalloc(void)
static int test_find_delalloc(u32 sectorsize)
{
struct inode *inode;
struct extent_io_tree tmp;
Expand Down Expand Up @@ -113,7 +113,7 @@ static int test_find_delalloc(void)
* |--- delalloc ---|
* |--- search ---|
*/
set_extent_delalloc(&tmp, 0, 4095, NULL);
set_extent_delalloc(&tmp, 0, sectorsize - 1, NULL);
start = 0;
end = 0;
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
Expand All @@ -122,9 +122,9 @@ static int test_find_delalloc(void)
test_msg("Should have found at least one delalloc\n");
goto out_bits;
}
if (start != 0 || end != 4095) {
test_msg("Expected start 0 end 4095, got start %Lu end %Lu\n",
start, end);
if (start != 0 || end != (sectorsize - 1)) {
test_msg("Expected start 0 end %u, got start %llu end %llu\n",
sectorsize - 1, start, end);
goto out_bits;
}
unlock_extent(&tmp, start, end);
Expand All @@ -144,7 +144,7 @@ static int test_find_delalloc(void)
test_msg("Couldn't find the locked page\n");
goto out_bits;
}
set_extent_delalloc(&tmp, 4096, max_bytes - 1, NULL);
set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, NULL);
start = test_start;
end = 0;
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
Expand Down Expand Up @@ -172,7 +172,7 @@ static int test_find_delalloc(void)
* |--- delalloc ---|
* |--- search ---|
*/
test_start = max_bytes + 4096;
test_start = max_bytes + sectorsize;
locked_page = find_lock_page(inode->i_mapping, test_start >>
PAGE_SHIFT);
if (!locked_page) {
Expand Down Expand Up @@ -351,14 +351,15 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
return 0;
}

static int test_eb_bitmaps(void)
static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
{
unsigned long len = PAGE_SIZE * 4;
unsigned long len;
unsigned long *bitmap;
struct extent_buffer *eb;
int ret;

test_msg("Running extent buffer bitmap tests\n");
len = sectorsize * 4;

bitmap = kmalloc(len, GFP_KERNEL);
if (!bitmap) {
Expand All @@ -379,7 +380,7 @@ static int test_eb_bitmaps(void)

/* Do it over again with an extent buffer which isn't page-aligned. */
free_extent_buffer(eb);
eb = __alloc_dummy_extent_buffer(NULL, PAGE_SIZE / 2, len);
eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
if (!eb) {
test_msg("Couldn't allocate test extent buffer\n");
kfree(bitmap);
Expand All @@ -393,17 +394,17 @@ static int test_eb_bitmaps(void)
return ret;
}

int btrfs_test_extent_io(void)
int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
{
int ret;

test_msg("Running extent I/O tests\n");

ret = test_find_delalloc();
ret = test_find_delalloc(sectorsize);
if (ret)
goto out;

ret = test_eb_bitmaps();
ret = test_eb_bitmaps(sectorsize, nodesize);
out:
test_msg("Extent I/O tests finished\n");
return ret;
Expand Down
Loading

0 comments on commit b9ef22d

Please sign in to comment.