Commit b9ef22de authored by Feifei Xu's avatar Feifei Xu Committed by David Sterba

Btrfs: self-tests: Support non-4k page size

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: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarFeifei Xu <xufeifei@linux.vnet.ibm.com>
Signed-off-by: default avatarChandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 0ef6447a
...@@ -1373,7 +1373,8 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path, ...@@ -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) { if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
BUG_ON(tm->slot != 0); 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) { if (!eb_rewin) {
btrfs_tree_read_unlock_blocking(eb); btrfs_tree_read_unlock_blocking(eb);
free_extent_buffer(eb); free_extent_buffer(eb);
...@@ -1454,7 +1455,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq) ...@@ -1454,7 +1455,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
} else if (old_root) { } else if (old_root) {
btrfs_tree_read_unlock(eb_root); btrfs_tree_read_unlock(eb_root);
free_extent_buffer(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 { } else {
btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK); btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK);
eb = btrfs_clone_extent_buffer(eb_root); eb = btrfs_clone_extent_buffer(eb_root);
......
...@@ -1147,7 +1147,8 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, ...@@ -1147,7 +1147,8 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 bytenr) u64 bytenr)
{ {
if (btrfs_test_is_dummy_root(root)) 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); return alloc_extent_buffer(root->fs_info, bytenr);
} }
...@@ -1314,14 +1315,15 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, ...@@ -1314,14 +1315,15 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
/* Should only be used by the testing infrastructure */ /* 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; struct btrfs_root *root;
root = btrfs_alloc_root(NULL, GFP_KERNEL); root = btrfs_alloc_root(NULL, GFP_KERNEL);
if (!root) if (!root)
return ERR_PTR(-ENOMEM); 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); set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
root->alloc_bytenr = 0; root->alloc_bytenr = 0;
......
...@@ -90,7 +90,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, ...@@ -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); void btrfs_free_fs_root(struct btrfs_root *root);
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #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 #endif
/* /*
......
...@@ -4718,16 +4718,16 @@ struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, ...@@ -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, struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start) u64 start, u32 nodesize)
{ {
unsigned long len; unsigned long len;
if (!fs_info) { if (!fs_info) {
/* /*
* Called only from tests that don't always have a 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 { } else {
len = fs_info->tree_root->nodesize; len = fs_info->tree_root->nodesize;
} }
...@@ -4823,7 +4823,7 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, ...@@ -4823,7 +4823,7 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, 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; struct extent_buffer *eb, *exists = NULL;
int ret; int ret;
...@@ -4831,7 +4831,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, ...@@ -4831,7 +4831,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
eb = find_extent_buffer(fs_info, start); eb = find_extent_buffer(fs_info, start);
if (eb) if (eb)
return eb; return eb;
eb = alloc_dummy_extent_buffer(fs_info, start); eb = alloc_dummy_extent_buffer(fs_info, start, nodesize);
if (!eb) if (!eb)
return NULL; return NULL;
eb->fs_info = fs_info; eb->fs_info = fs_info;
......
...@@ -348,7 +348,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, ...@@ -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, struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start, unsigned long len); u64 start, unsigned long len);
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);
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src); struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start); u64 start);
...@@ -468,5 +468,5 @@ noinline u64 find_lock_delalloc_range(struct inode *inode, ...@@ -468,5 +468,5 @@ noinline u64 find_lock_delalloc_range(struct inode *inode,
u64 *end, u64 max_bytes); u64 *end, u64 max_bytes);
#endif #endif
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start); u64 start, u32 nodesize);
#endif #endif
...@@ -1660,7 +1660,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) ...@@ -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 * sure we don't go over our overall goal of MAX_CACHE_BYTES_PER_GIG as
* we add more bitmaps. * 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) { if (bitmap_bytes >= max_bytes) {
ctl->extents_thresh = 0; ctl->extents_thresh = 0;
......
...@@ -2319,27 +2319,31 @@ static void btrfs_print_mod_info(void) ...@@ -2319,27 +2319,31 @@ static void btrfs_print_mod_info(void)
static int btrfs_run_sanity_tests(void) static int btrfs_run_sanity_tests(void)
{ {
int ret; int ret;
u32 sectorsize, nodesize;
sectorsize = PAGE_SIZE;
nodesize = PAGE_SIZE;
ret = btrfs_init_test_fs(); ret = btrfs_init_test_fs();
if (ret) if (ret)
return ret; return ret;
ret = btrfs_test_free_space_cache(); ret = btrfs_test_free_space_cache(sectorsize, nodesize);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_test_extent_buffer_operations(); ret = btrfs_test_extent_buffer_operations(sectorsize,
nodesize);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_test_extent_io(); ret = btrfs_test_extent_io(sectorsize, nodesize);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_test_inodes(); ret = btrfs_test_inodes(sectorsize, nodesize);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_test_qgroups(); ret = btrfs_test_qgroups(sectorsize, nodesize);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_test_free_space_tree(); ret = btrfs_test_free_space_tree(sectorsize, nodesize);
out: out:
btrfs_destroy_test_fs(); btrfs_destroy_test_fs();
return ret; return ret;
......
...@@ -175,7 +175,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root) ...@@ -175,7 +175,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
} }
struct btrfs_block_group_cache * 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; struct btrfs_block_group_cache *cache;
...@@ -192,8 +192,8 @@ btrfs_alloc_dummy_block_group(unsigned long length) ...@@ -192,8 +192,8 @@ btrfs_alloc_dummy_block_group(unsigned long length)
cache->key.objectid = 0; cache->key.objectid = 0;
cache->key.offset = length; cache->key.offset = length;
cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
cache->sectorsize = 4096; cache->sectorsize = sectorsize;
cache->full_stripe_len = 4096; cache->full_stripe_len = sectorsize;
INIT_LIST_HEAD(&cache->list); INIT_LIST_HEAD(&cache->list);
INIT_LIST_HEAD(&cache->cluster_list); INIT_LIST_HEAD(&cache->cluster_list);
......
...@@ -26,27 +26,28 @@ ...@@ -26,27 +26,28 @@
struct btrfs_root; struct btrfs_root;
struct btrfs_trans_handle; struct btrfs_trans_handle;
int btrfs_test_free_space_cache(void); int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize);
int btrfs_test_extent_buffer_operations(void); int btrfs_test_extent_buffer_operations(u32 sectorsize, u32 nodesize);
int btrfs_test_extent_io(void); int btrfs_test_extent_io(u32 sectorsize, u32 nodesize);
int btrfs_test_inodes(void); int btrfs_test_inodes(u32 sectorsize, u32 nodesize);
int btrfs_test_qgroups(void); int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
int btrfs_test_free_space_tree(void); int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
int btrfs_init_test_fs(void); int btrfs_init_test_fs(void);
void btrfs_destroy_test_fs(void); void btrfs_destroy_test_fs(void);
struct inode *btrfs_new_test_inode(void); struct inode *btrfs_new_test_inode(void);
struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void); struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
void btrfs_free_dummy_root(struct btrfs_root *root); void btrfs_free_dummy_root(struct btrfs_root *root);
struct btrfs_block_group_cache * 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_free_dummy_block_group(struct btrfs_block_group_cache *cache);
void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans); void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans);
#else #else
static inline int btrfs_test_free_space_cache(void) static inline int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
{ {
return 0; 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; return 0;
} }
...@@ -57,19 +58,19 @@ static inline int btrfs_init_test_fs(void) ...@@ -57,19 +58,19 @@ static inline int btrfs_init_test_fs(void)
static inline void btrfs_destroy_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; return 0;
} }
static inline int btrfs_test_inodes(void) static inline int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
{ {
return 0; return 0;
} }
static inline int btrfs_test_qgroups(void) static inline int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
{ {
return 0; 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; return 0;
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "../extent_io.h" #include "../extent_io.h"
#include "../disk-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_path *path;
struct btrfs_root *root; struct btrfs_root *root;
...@@ -40,7 +40,7 @@ static int test_btrfs_split_item(void) ...@@ -40,7 +40,7 @@ static int test_btrfs_split_item(void)
test_msg("Running btrfs_split_item tests\n"); test_msg("Running btrfs_split_item tests\n");
root = btrfs_alloc_dummy_root(); root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(root)) { if (IS_ERR(root)) {
test_msg("Could not allocate root\n"); test_msg("Could not allocate root\n");
return PTR_ERR(root); return PTR_ERR(root);
...@@ -53,7 +53,8 @@ static int test_btrfs_split_item(void) ...@@ -53,7 +53,8 @@ static int test_btrfs_split_item(void)
return -ENOMEM; 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) { if (!eb) {
test_msg("Could not allocate dummy buffer\n"); test_msg("Could not allocate dummy buffer\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -222,8 +223,8 @@ static int test_btrfs_split_item(void) ...@@ -222,8 +223,8 @@ static int test_btrfs_split_item(void)
return ret; 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"); test_msg("Running extent buffer operation tests");
return test_btrfs_split_item(); return test_btrfs_split_item(sectorsize, nodesize);
} }
...@@ -65,7 +65,7 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end, ...@@ -65,7 +65,7 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
return count; return count;
} }
static int test_find_delalloc(void) static int test_find_delalloc(u32 sectorsize)
{ {
struct inode *inode; struct inode *inode;
struct extent_io_tree tmp; struct extent_io_tree tmp;
...@@ -113,7 +113,7 @@ static int test_find_delalloc(void) ...@@ -113,7 +113,7 @@ static int test_find_delalloc(void)
* |--- delalloc ---| * |--- delalloc ---|
* |--- search ---| * |--- search ---|
*/ */
set_extent_delalloc(&tmp, 0, 4095, NULL); set_extent_delalloc(&tmp, 0, sectorsize - 1, NULL);
start = 0; start = 0;
end = 0; end = 0;
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
...@@ -122,9 +122,9 @@ static int test_find_delalloc(void) ...@@ -122,9 +122,9 @@ static int test_find_delalloc(void)
test_msg("Should have found at least one delalloc\n"); test_msg("Should have found at least one delalloc\n");
goto out_bits; goto out_bits;
} }
if (start != 0 || end != 4095) { if (start != 0 || end != (sectorsize - 1)) {
test_msg("Expected start 0 end 4095, got start %Lu end %Lu\n", test_msg("Expected start 0 end %u, got start %llu end %llu\n",
start, end); sectorsize - 1, start, end);
goto out_bits; goto out_bits;
} }
unlock_extent(&tmp, start, end); unlock_extent(&tmp, start, end);
...@@ -144,7 +144,7 @@ static int test_find_delalloc(void) ...@@ -144,7 +144,7 @@ static int test_find_delalloc(void)
test_msg("Couldn't find the locked page\n"); test_msg("Couldn't find the locked page\n");
goto out_bits; goto out_bits;
} }
set_extent_delalloc(&tmp, 4096, max_bytes - 1, NULL); set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, NULL);
start = test_start; start = test_start;
end = 0; end = 0;
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
...@@ -172,7 +172,7 @@ static int test_find_delalloc(void) ...@@ -172,7 +172,7 @@ static int test_find_delalloc(void)
* |--- delalloc ---| * |--- delalloc ---|
* |--- search ---| * |--- search ---|
*/ */
test_start = max_bytes + 4096; test_start = max_bytes + sectorsize;
locked_page = find_lock_page(inode->i_mapping, test_start >> locked_page = find_lock_page(inode->i_mapping, test_start >>
PAGE_SHIFT); PAGE_SHIFT);
if (!locked_page) { if (!locked_page) {
...@@ -351,14 +351,15 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, ...@@ -351,14 +351,15 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
return 0; 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; unsigned long *bitmap;
struct extent_buffer *eb; struct extent_buffer *eb;
int ret; int ret;
test_msg("Running extent buffer bitmap tests\n"); test_msg("Running extent buffer bitmap tests\n");
len = sectorsize * 4;
bitmap = kmalloc(len, GFP_KERNEL); bitmap = kmalloc(len, GFP_KERNEL);
if (!bitmap) { if (!bitmap) {
...@@ -379,7 +380,7 @@ static int test_eb_bitmaps(void) ...@@ -379,7 +380,7 @@ static int test_eb_bitmaps(void)
/* Do it over again with an extent buffer which isn't page-aligned. */ /* Do it over again with an extent buffer which isn't page-aligned. */
free_extent_buffer(eb); 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) { if (!eb) {
test_msg("Couldn't allocate test extent buffer\n"); test_msg("Couldn't allocate test extent buffer\n");
kfree(bitmap); kfree(bitmap);
...@@ -393,17 +394,17 @@ static int test_eb_bitmaps(void) ...@@ -393,17 +394,17 @@ static int test_eb_bitmaps(void)
return ret; return ret;
} }
int btrfs_test_extent_io(void) int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
{ {
int ret; int ret;
test_msg("Running extent I/O tests\n"); test_msg("Running extent I/O tests\n");
ret = test_find_delalloc(); ret = test_find_delalloc(sectorsize);
if (ret) if (ret)
goto out; goto out;
ret = test_eb_bitmaps(); ret = test_eb_bitmaps(sectorsize, nodesize);
out: out:
test_msg("Extent I/O tests finished\n"); test_msg("Extent I/O tests finished\n");
return ret; return ret;
......
...@@ -99,7 +99,8 @@ static int test_extents(struct btrfs_block_group_cache *cache) ...@@ -99,7 +99,8 @@ static int test_extents(struct btrfs_block_group_cache *cache)
return 0; return 0;
} }
static int test_bitmaps(struct btrfs_block_group_cache *cache) static int test_bitmaps(struct btrfs_block_group_cache *cache,
u32 sectorsize)
{ {
u64 next_bitmap_offset; u64 next_bitmap_offset;
int ret; int ret;
...@@ -139,7 +140,7 @@ static int test_bitmaps(struct btrfs_block_group_cache *cache) ...@@ -139,7 +140,7 @@ static int test_bitmaps(struct btrfs_block_group_cache *cache)
* The first bitmap we have starts at offset 0 so the next one is just * The first bitmap we have starts at offset 0 so the next one is just
* at the end of the first bitmap. * at the end of the first bitmap.
*/ */
next_bitmap_offset = (u64)(BITS_PER_BITMAP * 4096); next_bitmap_offset = (u64)(BITS_PER_BITMAP * sectorsize);
/* Test a bit straddling two bitmaps */ /* Test a bit straddling two bitmaps */
ret = test_add_free_space_entry(cache, next_bitmap_offset - SZ_2M, ret = test_add_free_space_entry(cache, next_bitmap_offset - SZ_2M,
...@@ -167,9 +168,10 @@ static int test_bitmaps(struct btrfs_block_group_cache *cache) ...@@ -167,9 +168,10 @@ static int test_bitmaps(struct btrfs_block_group_cache *cache)
} }
/* This is the high grade jackassery */ /* This is the high grade jackassery */
static int test_bitmaps_and_extents(struct btrfs_block_group_cache *cache) static int test_bitmaps_and_extents(struct btrfs_block_group_cache *cache,
u32 sectorsize)
{ {
u64 bitmap_offset = (u64)(BITS_PER_BITMAP * 4096); u64 bitmap_offset = (u64)(BITS_PER_BITMAP * sectorsize);
int ret; int ret;
test_msg("Running bitmap and extent tests\n"); test_msg("Running bitmap and extent tests\n");
...@@ -401,7 +403,8 @@ static int check_cache_empty(struct btrfs_block_group_cache *cache) ...@@ -401,7 +403,8 @@ static int check_cache_empty(struct btrfs_block_group_cache *cache)
* requests. * requests.
*/ */
static int static int
test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache,
u32 sectorsize)
{ {
int ret; int ret;
u64 offset; u64 offset;
...@@ -539,7 +542,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -539,7 +542,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
* The goal is to test that the bitmap entry space stealing doesn't * The goal is to test that the bitmap entry space stealing doesn't
* steal this space region. * steal this space region.
*/ */
ret = btrfs_add_free_space(cache, SZ_128M + SZ_16M, 4096); ret = btrfs_add_free_space(cache, SZ_128M + SZ_16M, sectorsize);
if (ret) { if (ret) {
test_msg("Error adding free space: %d\n", ret); test_msg("Error adding free space: %d\n", ret);
return ret; return ret;
...@@ -597,8 +600,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -597,8 +600,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
return -ENOENT; return -ENOENT;
} }
if (cache->free_space_ctl->free_space != (SZ_1M + 4096)) { if (cache->free_space_ctl->free_space != (SZ_1M + sectorsize)) {
test_msg("Cache free space is not 1Mb + 4Kb\n"); test_msg("Cache free space is not 1Mb + %u\n", sectorsize);
return -EINVAL; return -EINVAL;
} }
...@@ -611,22 +614,25 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -611,22 +614,25 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
return -EINVAL; return -EINVAL;
} }
/* All that remains is a 4Kb free space region in a bitmap. Confirm. */ /*
* All that remains is a sectorsize free space region in a bitmap.
* Confirm.
*/
ret = check_num_extents_and_bitmaps(cache, 1, 1); ret = check_num_extents_and_bitmaps(cache, 1, 1);
if (ret) if (ret)
return ret; return ret;
if (cache->free_space_ctl->free_space != 4096) { if (cache->free_space_ctl->free_space != sectorsize) {
test_msg("Cache free space is not 4Kb\n"); test_msg("Cache free space is not %u\n", sectorsize);
return -EINVAL; return -EINVAL;
} }
offset = btrfs_find_space_for_alloc(cache, offset = btrfs_find_space_for_alloc(cache,
0, 4096, 0, 0, sectorsize, 0,
&max_extent_size); &max_extent_size);
if (offset != (SZ_128M + SZ_16M)) { if (offset != (SZ_128M + SZ_16M)) {
test_msg("Failed to allocate 4Kb from space cache, returned offset is: %llu\n", test_msg("Failed to allocate %u, returned offset : %llu\n",
offset); sectorsize, offset);
return -EINVAL; return -EINVAL;
} }
...@@ -733,7 +739,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -733,7 +739,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
* The goal is to test that the bitmap entry space stealing doesn't * The goal is to test that the bitmap entry space stealing doesn't
* steal this space region. * steal this space region.
*/ */
ret = btrfs_add_free_space(cache, SZ_32M, 8192); ret = btrfs_add_free_space(cache, SZ_32M, 2 * sectorsize);
if (ret) { if (ret) {
test_msg("Error adding free space: %d\n", ret); test_msg("Error adding free space: %d\n", ret);
return ret; return ret;
...@@ -757,7 +763,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -757,7 +763,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
/* /*
* Confirm that our extent entry didn't stole all free space from the * Confirm that our extent entry didn't stole all free space from the
* bitmap, because of the small 8Kb free space region. * bitmap, because of the small 2 * sectorsize free space region.
*/ */
ret = check_num_extents_and_bitmaps(cache, 2, 1); ret = check_num_extents_and_bitmaps(cache, 2, 1);
if (ret) if (ret)
...@@ -783,8 +789,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -783,8 +789,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
return -ENOENT; return -ENOENT;
} }
if (cache->free_space_ctl->free_space != (SZ_1M + 8192)) { if (cache->free_space_ctl->free_space != (SZ_1M + 2 * sectorsize)) {
test_msg("Cache free space is not 1Mb + 8Kb\n"); test_msg("Cache free space is not 1Mb + %u\n", 2 * sectorsize);
return -EINVAL; return -EINVAL;
} }
...@@ -796,21 +802,25 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -796,21 +802,25 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
return -EINVAL; return -EINVAL;
} }
/* All that remains is a 8Kb free space region in a bitmap. Confirm. */ /*
* All that remains is 2 * sectorsize free space region
* in a bitmap. Confirm.
*/
ret = check_num_extents_and_bitmaps(cache, 1, 1); ret = check_num_extents_and_bitmaps(cache, 1, 1);
if (ret) if (ret)
return ret; return ret;
if (cache->free_space_ctl->free_space != 8192) { if (cache->free_space_ctl->free_space != 2 * sectorsize) {
test_msg("Cache free space is not 8Kb\n"); test_msg("Cache free space is not %u\n", 2 * sectorsize);
return -EINVAL; return -EINVAL;
} }
offset = btrfs_find_space_for_alloc(cache, offset = btrfs_find_space_for_alloc(cache,
0, 8192, 0, 0, 2 * sectorsize, 0,
&max_extent_size); &max_extent_size);
if (offset != SZ_32M) { if (offset != SZ_32M) {
test_msg("Failed to allocate 8Kb from space cache, returned offset is: %llu\n", test_msg("Failed to allocate %u, offset: %llu\n",
2 * sectorsize,
offset); offset);
return -EINVAL; return -EINVAL;
} }
...@@ -825,7 +835,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) ...@@ -825,7 +835,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
return 0; return 0;
} }
int btrfs_test_free_space_cache(void) int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
{ {
struct btrfs_block_group_cache *cache; struct btrfs_block_group_cache *cache;
struct btrfs_root *root = NULL; struct btrfs_root *root = NULL;
...@@ -833,13 +843,13 @@ int btrfs_test_free_space_cache(void) ...@@ -833,13 +843,13 @@ int btrfs_test_free_space_cache(void)
test_msg("Running btrfs free space cache tests\n"); test_msg("Running btrfs free space cache tests\n");
cache = btrfs_alloc_dummy_block_group(1024 * 1024 * 1024); cache = btrfs_alloc_dummy_block_group(1024 * 1024 * 1024, sectorsize);
if (!cache) { if (!cache) {
test_msg("Couldn't run the tests\n"); test_msg("Couldn't run the tests\n");
return 0; return 0;
} }
root = btrfs_alloc_dummy_root(); root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(root)) { if (IS_ERR(root)) {
ret = PTR_ERR(root); ret = PTR_ERR(root);
goto out; goto out;
...@@ -855,14 +865,14 @@ int btrfs_test_free_space_cache(void) ...@@ -855,14 +865,14 @@ int btrfs_test_free_space_cache(void)
ret = test_extents(cache); ret = test_extents(cache);
if (ret) if (ret)
goto out; goto out;
ret = test_bitmaps(cache); ret = test_bitmaps(cache, sectorsize);
if (ret) if (ret)
goto out; goto out;
ret = test_bitmaps_and_extents(cache); ret = test_bitmaps_and_extents(cache, sectorsize);
if (ret) if (ret)
goto out; goto out;
ret = test_steal_space_from_bitmap_to_extent(cache); ret = test_steal_space_from_bitmap_to_extent(cache, sectorsize);
out: out:
btrfs_free_dummy_block_group(cache); btrfs_free_dummy_block_group(cache);
btrfs_free_dummy_root(root); btrfs_free_dummy_root(root);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Boston, MA 021110-1307, USA. * Boston, MA 021110-1307, USA.
*/ */
#include <linux/types.h>
#include "btrfs-tests.h" #include "btrfs-tests.h"
#include "../ctree.h" #include "../ctree.h"
#include "../disk-io.h" #include "../disk-io.h"
...@@ -30,7 +31,7 @@ struct free_space_extent { ...@@ -30,7 +31,7 @@ struct free_space_extent {
* The test cases align their operations to this in order to hit some of the * The test cases align their operations to this in order to hit some of the
* edge cases in the bitmap code. * edge cases in the bitmap code.
*/ */
#define BITMAP_RANGE (BTRFS_FREE_SPACE_BITMAP_BITS * 4096) #define BITMAP_RANGE (BTRFS_FREE_SPACE_BITMAP_BITS * PAGE_SIZE)
static int __check_free_space_extents(struct btrfs_trans_handle *trans, static int __check_free_space_extents(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
...@@ -439,7 +440,8 @@ typedef int (*test_func_t)(struct btrfs_trans_handle *, ...@@ -439,7 +440,8 @@ typedef int (*test_func_t)(struct btrfs_trans_handle *,
struct btrfs_block_group_cache *, struct btrfs_block_group_cache *,
struct btrfs_path *); struct btrfs_path *);
static int run_test(test_func_t test_func, int bitmaps) static int run_test(test_func_t test_func, int bitmaps,
u32 sectorsize, u32 nodesize)
{ {
struct btrfs_root *root = NULL; struct btrfs_root *root = NULL;
struct btrfs_block_group_cache *cache = NULL; struct btrfs_block_group_cache *cache = NULL;
...@@ -447,7 +449,7 @@ static int run_test(test_func_t test_func, int bitmaps) ...@@ -447,7 +449,7 @@ static int run_test(test_func_t test_func, int bitmaps)
struct btrfs_path *path = NULL; struct btrfs_path *path = NULL;
int ret; int ret;
root = btrfs_alloc_dummy_root(); root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(root)) { if (IS_ERR(root)) {
test_msg("Couldn't allocate dummy root\n"); test_msg("Couldn't allocate dummy root\n");
ret = PTR_ERR(root); ret = PTR_ERR(root);
...@@ -466,7 +468,8 @@ static int run_test(test_func_t test_func, int bitmaps) ...@@ -466,7 +468,8 @@ static int run_test(test_func_t test_func, int bitmaps)
root->fs_info->free_space_root = root; root->fs_info->free_space_root = root;
root->fs_info->tree_root = root; root->fs_info->tree_root = root;
root->node = alloc_test_extent_buffer(root->fs_info, 4096); root->node = alloc_test_extent_buffer(root->fs_info,
nodesize, nodesize);
if (!root->node) { if (!root->node) {
test_msg("Couldn't allocate dummy buffer\n"); test_msg("Couldn't allocate dummy buffer\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -474,9 +477,9 @@ static int run_test(test_func_t test_func, int bitmaps) ...@@ -474,9 +477,9 @@ static int run_test(test_func_t test_func, int bitmaps)
} }
btrfs_set_header_level(root->node, 0); btrfs_set_header_level(root->node, 0);
btrfs_set_header_nritems(root->node, 0); btrfs_set_header_nritems(root->node, 0);
root->alloc_bytenr += 8192; root->alloc_bytenr += 2 * nodesize;
cache = btrfs_alloc_dummy_block_group(8 * BITMAP_RANGE); cache = btrfs_alloc_dummy_block_group(8 * BITMAP_RANGE, sectorsize);
if (!cache) { if (!cache) {
test_msg("Couldn't allocate dummy block group cache\n"); test_msg("Couldn't allocate dummy block group cache\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -534,17 +537,18 @@ static int run_test(test_func_t test_func, int bitmaps) ...@@ -534,17 +537,18 @@ static int run_test(test_func_t test_func, int bitmaps)
return ret; return ret;
} }
static int run_test_both_formats(test_func_t test_func) static int run_test_both_formats(test_func_t test_func,
u32 sectorsize, u32 nodesize)
{ {
int ret; int ret;
ret = run_test(test_func, 0); ret = run_test(test_func, 0, sectorsize, nodesize);
if (ret) if (ret)
return ret; return ret;
return run_test(test_func, 1); return run_test(test_func, 1, sectorsize, nodesize);
} }
int btrfs_test_free_space_tree(void) int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize)
{ {
test_func_t tests[] = { test_func_t tests[] = {
test_empty_block_group, test_empty_block_group,
...@@ -561,9 +565,11 @@ int btrfs_test_free_space_tree(void) ...@@ -561,9 +565,11 @@ int btrfs_test_free_space_tree(void)
test_msg("Running free space tree tests\n"); test_msg("Running free space tree tests\n");
for (i = 0; i < ARRAY_SIZE(tests); i++) { for (i = 0; i < ARRAY_SIZE(tests); i++) {
int ret = run_test_both_formats(tests[i]); int ret = run_test_both_formats(tests[i], sectorsize,
nodesize);
if (ret) { if (ret) {
test_msg("%pf failed\n", tests[i]); test_msg("%pf : sectorsize %u failed\n",
tests[i], sectorsize);
return ret; return ret;
} }
} }
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Boston, MA 021110-1307, USA. * Boston, MA 021110-1307, USA.
*/ */
#include <linux/types.h>
#include "btrfs-tests.h" #include "btrfs-tests.h"
#include "../ctree.h" #include "../ctree.h"
#include "../transaction.h" #include "../transaction.h"
...@@ -216,7 +217,8 @@ static int remove_extent_ref(struct btrfs_root *root, u64 bytenr, ...@@ -216,7 +217,8 @@ static int remove_extent_ref(struct btrfs_root *root, u64 bytenr,
return ret; return ret;
} }
static int test_no_shared_qgroup(struct btrfs_root *root) static int test_no_shared_qgroup(struct btrfs_root *root,
u32 sectorsize, u32 nodesize)
{ {
struct btrfs_trans_handle trans; struct btrfs_trans_handle trans;
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
...@@ -238,18 +240,18 @@ static int test_no_shared_qgroup(struct btrfs_root *root) ...@@ -238,18 +240,18 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
* we can only call btrfs_qgroup_account_extent() directly to test * we can only call btrfs_qgroup_account_extent() directly to test
* quota. * quota.
*/ */
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
test_msg("Couldn't find old roots: %d\n", ret); test_msg("Couldn't find old roots: %d\n", ret);
return ret; return ret;
} }
ret = insert_normal_tree_ref(root, 4096, 4096, 0, 5); ret = insert_normal_tree_ref(root, nodesize, nodesize, 0, 5);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
ulist_free(new_roots); ulist_free(new_roots);
...@@ -257,32 +259,32 @@ static int test_no_shared_qgroup(struct btrfs_root *root) ...@@ -257,32 +259,32 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
old_roots, new_roots); nodesize, old_roots, new_roots);
if (ret) { if (ret) {
test_msg("Couldn't account space for a qgroup %d\n", ret); test_msg("Couldn't account space for a qgroup %d\n", ret);
return ret; return ret;
} }
if (btrfs_verify_qgroup_counts(fs_info, 5, 4096, 4096)) { if (btrfs_verify_qgroup_counts(fs_info, 5, nodesize, nodesize)) {
test_msg("Qgroup counts didn't match expected values\n"); test_msg("Qgroup counts didn't match expected values\n");
return -EINVAL; return -EINVAL;
} }
old_roots = NULL; old_roots = NULL;
new_roots = NULL; new_roots = NULL;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
test_msg("Couldn't find old roots: %d\n", ret); test_msg("Couldn't find old roots: %d\n", ret);
return ret; return ret;
} }
ret = remove_extent_item(root, 4096, 4096); ret = remove_extent_item(root, nodesize, nodesize);
if (ret) if (ret)
return -EINVAL; return -EINVAL;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
ulist_free(new_roots); ulist_free(new_roots);
...@@ -290,8 +292,8 @@ static int test_no_shared_qgroup(struct btrfs_root *root) ...@@ -290,8 +292,8 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
old_roots, new_roots); nodesize, old_roots, new_roots);
if (ret) { if (ret) {
test_msg("Couldn't account space for a qgroup %d\n", ret); test_msg("Couldn't account space for a qgroup %d\n", ret);
return -EINVAL; return -EINVAL;
...@@ -310,7 +312,8 @@ static int test_no_shared_qgroup(struct btrfs_root *root) ...@@ -310,7 +312,8 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
* right, also remove one of the roots and make sure the exclusive count is * right, also remove one of the roots and make sure the exclusive count is
* adjusted properly. * adjusted properly.
*/ */
static int test_multiple_refs(struct btrfs_root *root) static int test_multiple_refs(struct btrfs_root *root,
u32 sectorsize, u32 nodesize)
{ {
struct btrfs_trans_handle trans; struct btrfs_trans_handle trans;
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
...@@ -329,18 +332,18 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -329,18 +332,18 @@ static int test_multiple_refs(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
test_msg("Couldn't find old roots: %d\n", ret); test_msg("Couldn't find old roots: %d\n", ret);
return ret; return ret;
} }
ret = insert_normal_tree_ref(root, 4096, 4096, 0, 5); ret = insert_normal_tree_ref(root, nodesize, nodesize, 0, 5);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
ulist_free(new_roots); ulist_free(new_roots);
...@@ -348,30 +351,31 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -348,30 +351,31 @@ static int test_multiple_refs(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
old_roots, new_roots); nodesize, old_roots, new_roots);
if (ret) { if (ret) {
test_msg("Couldn't account space for a qgroup %d\n", ret); test_msg("Couldn't account space for a qgroup %d\n", ret);
return ret; return ret;
} }
if (btrfs_verify_qgroup_counts(fs_info, 5, 4096, 4096)) { if (btrfs_verify_qgroup_counts(fs_info, 5,
nodesize, nodesize)) {
test_msg("Qgroup counts didn't match expected values\n"); test_msg("Qgroup counts didn't match expected values\n");
return -EINVAL; return -EINVAL;
} }
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
test_msg("Couldn't find old roots: %d\n", ret); test_msg("Couldn't find old roots: %d\n", ret);
return ret; return ret;
} }
ret = add_tree_ref(root, 4096, 4096, 0, 256); ret = add_tree_ref(root, nodesize, nodesize, 0, 256);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
ulist_free(new_roots); ulist_free(new_roots);
...@@ -379,35 +383,35 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -379,35 +383,35 @@ static int test_multiple_refs(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
old_roots, new_roots); nodesize, old_roots, new_roots);
if (ret) { if (ret) {
test_msg("Couldn't account space for a qgroup %d\n", ret); test_msg("Couldn't account space for a qgroup %d\n", ret);
return ret; return ret;
} }
if (btrfs_verify_qgroup_counts(fs_info, 5, 4096, 0)) { if (btrfs_verify_qgroup_counts(fs_info, 5, nodesize, 0)) {
test_msg("Qgroup counts didn't match expected values\n"); test_msg("Qgroup counts didn't match expected values\n");
return -EINVAL; return -EINVAL;
} }
if (btrfs_verify_qgroup_counts(fs_info, 256, 4096, 0)) { if (btrfs_verify_qgroup_counts(fs_info, 256, nodesize, 0)) {
test_msg("Qgroup counts didn't match expected values\n"); test_msg("Qgroup counts didn't match expected values\n");
return -EINVAL; return -EINVAL;
} }
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
test_msg("Couldn't find old roots: %d\n", ret); test_msg("Couldn't find old roots: %d\n", ret);
return ret; return ret;
} }
ret = remove_extent_ref(root, 4096, 4096, 0, 256); ret = remove_extent_ref(root, nodesize, nodesize, 0, 256);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots); ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots);
if (ret) { if (ret) {
ulist_free(old_roots); ulist_free(old_roots);
ulist_free(new_roots); ulist_free(new_roots);
...@@ -415,8 +419,8 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -415,8 +419,8 @@ static int test_multiple_refs(struct btrfs_root *root)
return ret; return ret;
} }
ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096, ret = btrfs_qgroup_account_extent(&trans, fs_info, nodesize,
old_roots, new_roots); nodesize, old_roots, new_roots);
if (ret) { if (ret) {
test_msg("Couldn't account space for a qgroup %d\n", ret); test_msg("Couldn't account space for a qgroup %d\n", ret);
return ret; return ret;
...@@ -427,7 +431,7 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -427,7 +431,7 @@ static int test_multiple_refs(struct btrfs_root *root)
return -EINVAL; return -EINVAL;
} }
if (btrfs_verify_qgroup_counts(fs_info, 5, 4096, 4096)) { if (btrfs_verify_qgroup_counts(fs_info, 5, nodesize, nodesize)) {
test_msg("Qgroup counts didn't match expected values\n"); test_msg("Qgroup counts didn't match expected values\n");
return -EINVAL; return -EINVAL;
} }
...@@ -435,13 +439,13 @@ static int test_multiple_refs(struct btrfs_root *root) ...@@ -435,13 +439,13 @@ static int test_multiple_refs(struct btrfs_root *root)
return 0; return 0;
} }
int btrfs_test_qgroups(void) int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
{ {
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_root *tmp_root; struct btrfs_root *tmp_root;
int ret = 0; int ret = 0;
root = btrfs_alloc_dummy_root(); root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(root)) { if (IS_ERR(root)) {
test_msg("Couldn't allocate root\n"); test_msg("Couldn't allocate root\n");
return PTR_ERR(root); return PTR_ERR(root);
...@@ -468,7 +472,8 @@ int btrfs_test_qgroups(void) ...@@ -468,7 +472,8 @@ int btrfs_test_qgroups(void)
* Can't use bytenr 0, some things freak out * Can't use bytenr 0, some things freak out
* *cough*backref walking code*cough* * *cough*backref walking code*cough*
*/ */
root->node = alloc_test_extent_buffer(root->fs_info, 4096); root->node = alloc_test_extent_buffer(root->fs_info, nodesize,
nodesize);
if (!root->node) { if (!root->node) {
test_msg("Couldn't allocate dummy buffer\n"); test_msg("Couldn't allocate dummy buffer\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -476,9 +481,9 @@ int btrfs_test_qgroups(void) ...@@ -476,9 +481,9 @@ int btrfs_test_qgroups(void)
} }
btrfs_set_header_level(root->node, 0); btrfs_set_header_level(root->node, 0);
btrfs_set_header_nritems(root->node, 0); btrfs_set_header_nritems(root->node, 0);
root->alloc_bytenr += 8192; root->alloc_bytenr += 2 * nodesize;
tmp_root = btrfs_alloc_dummy_root(); tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(tmp_root)) { if (IS_ERR(tmp_root)) {
test_msg("Couldn't allocate a fs root\n"); test_msg("Couldn't allocate a fs root\n");
ret = PTR_ERR(tmp_root); ret = PTR_ERR(tmp_root);
...@@ -493,7 +498,7 @@ int btrfs_test_qgroups(void) ...@@ -493,7 +498,7 @@ int btrfs_test_qgroups(void)
goto out; goto out;
} }
tmp_root = btrfs_alloc_dummy_root(); tmp_root = btrfs_alloc_dummy_root(sectorsize, nodesize);
if (IS_ERR(tmp_root)) { if (IS_ERR(tmp_root)) {
test_msg("Couldn't allocate a fs root\n"); test_msg("Couldn't allocate a fs root\n");
ret = PTR_ERR(tmp_root); ret = PTR_ERR(tmp_root);
...@@ -508,10 +513,10 @@ int btrfs_test_qgroups(void) ...@@ -508,10 +513,10 @@ int btrfs_test_qgroups(void)
} }
test_msg("Running qgroup tests\n"); test_msg("Running qgroup tests\n");
ret = test_no_shared_qgroup(root); ret = test_no_shared_qgroup(root, sectorsize, nodesize);
if (ret) if (ret)
goto out; goto out;
ret = test_multiple_refs(root); ret = test_multiple_refs(root, sectorsize, nodesize);
out: out:
btrfs_free_dummy_root(root); btrfs_free_dummy_root(root);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment