Skip to content

Commit

Permalink
Merge branch 'for-chris' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/kdave/linux into for-linus-4.7
  • Loading branch information
Chris Mason committed Jun 8, 2016
2 parents 8dff9c8 + 34b3e6c commit 4c52990
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 340 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
9 changes: 6 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,16 @@ 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,
BTRFS_ROOT_TREE_OBJECTID);
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 @@ -4728,16 +4728,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 @@ -4833,15 +4833,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
18 changes: 9 additions & 9 deletions fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "inode-map.h"
#include "volumes.h"

#define BITS_PER_BITMAP (PAGE_SIZE * 8)
#define BITS_PER_BITMAP (PAGE_SIZE * 8UL)
#define MAX_CACHE_BYTES_PER_GIG SZ_32K

struct btrfs_trim_range {
Expand Down Expand Up @@ -1415,11 +1415,11 @@ static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl,
u64 offset)
{
u64 bitmap_start;
u32 bytes_per_bitmap;
u64 bytes_per_bitmap;

bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit;
bitmap_start = offset - ctl->start;
bitmap_start = div_u64(bitmap_start, bytes_per_bitmap);
bitmap_start = div64_u64(bitmap_start, bytes_per_bitmap);
bitmap_start *= bytes_per_bitmap;
bitmap_start += ctl->start;

Expand Down Expand Up @@ -1638,10 +1638,10 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
u64 bitmap_bytes;
u64 extent_bytes;
u64 size = block_group->key.offset;
u32 bytes_per_bg = BITS_PER_BITMAP * ctl->unit;
u32 max_bitmaps = div_u64(size + bytes_per_bg - 1, bytes_per_bg);
u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit;
u64 max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg);

max_bitmaps = max_t(u32, max_bitmaps, 1);
max_bitmaps = max_t(u64, max_bitmaps, 1);

ASSERT(ctl->total_bitmaps <= max_bitmaps);

Expand All @@ -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 Expand Up @@ -3662,7 +3662,7 @@ int test_check_exists(struct btrfs_block_group_cache *cache,
if (tmp->offset + tmp->bytes < offset)
break;
if (offset + bytes < tmp->offset) {
n = rb_prev(&info->offset_index);
n = rb_prev(&tmp->offset_index);
continue;
}
info = tmp;
Expand All @@ -3676,7 +3676,7 @@ int test_check_exists(struct btrfs_block_group_cache *cache,
if (offset + bytes < tmp->offset)
break;
if (tmp->offset + tmp->bytes < offset) {
n = rb_next(&info->offset_index);
n = rb_next(&tmp->offset_index);
continue;
}
info = tmp;
Expand Down
52 changes: 33 additions & 19 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2318,28 +2318,42 @@ static void btrfs_print_mod_info(void)

static int btrfs_run_sanity_tests(void)
{
int ret;

int ret, i;
u32 sectorsize, nodesize;
u32 test_sectorsize[] = {
PAGE_SIZE,
};
ret = btrfs_init_test_fs();
if (ret)
return ret;

ret = btrfs_test_free_space_cache();
if (ret)
goto out;
ret = btrfs_test_extent_buffer_operations();
if (ret)
goto out;
ret = btrfs_test_extent_io();
if (ret)
goto out;
ret = btrfs_test_inodes();
if (ret)
goto out;
ret = btrfs_test_qgroups();
if (ret)
goto out;
ret = btrfs_test_free_space_tree();
for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
sectorsize = test_sectorsize[i];
for (nodesize = sectorsize;
nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
nodesize <<= 1) {
pr_info("BTRFS: selftest: sectorsize: %u nodesize: %u\n",
sectorsize, nodesize);
ret = btrfs_test_free_space_cache(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_extent_buffer_operations(sectorsize,
nodesize);
if (ret)
goto out;
ret = btrfs_test_extent_io(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_inodes(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_qgroups(sectorsize, nodesize);
if (ret)
goto out;
ret = btrfs_test_free_space_tree(sectorsize, nodesize);
if (ret)
goto out;
}
}
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
13 changes: 7 additions & 6 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();
test_msg("Running extent buffer operation tests\n");
return test_btrfs_split_item(sectorsize, nodesize);
}
Loading

0 comments on commit 4c52990

Please sign in to comment.