Skip to content

Commit

Permalink
Merge branch 'for-linus-4.7' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/mason/linux-btrfs

Pull btrfs fixes from Chris Mason:
 "Has some fixes and some new self tests for btrfs.  The self tests are
  usually disabled in the .config file (unless you're doing btrfs dev
  work), and this bunch is meant to find problems with the 64K page size
  patches.

  Jeff has a patch to help people see if they are using the hardware
  assist crc32c module, which really helps us nail down problems when
  people ask why crcs are using so much CPU.

  Otherwise, it's small fixes"

* 'for-linus-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  Btrfs: self-tests: Fix extent buffer bitmap test fail on BE system
  Btrfs: self-tests: Fix test_bitmaps fail on 64k sectorsize
  Btrfs: self-tests: Use macros instead of constants and add missing newline
  Btrfs: self-tests: Support testing all possible sectorsizes and nodesizes
  Btrfs: self-tests: Execute page straddling test only when nodesize < PAGE_SIZE
  btrfs: advertise which crc32c implementation is being used at module load
  Btrfs: add validadtion checks for chunk loading
  Btrfs: add more validation checks for superblock
  Btrfs: clear uptodate flags of pages in sys_array eb
  Btrfs: self-tests: Support non-4k page size
  Btrfs: Fix integer overflow when calculating bytes_per_bitmap
  Btrfs: test_check_exists: Fix infinite loop when searching for free space entries
  Btrfs: end transaction if we abort when creating uuid root
  btrfs: Use __u64 in exported linux/btrfs.h.
  • Loading branch information
Linus Torvalds committed Jun 10, 2016
2 parents ccf55f7 + 719da39 commit 3d0f0b6
Show file tree
Hide file tree
Showing 19 changed files with 569 additions and 358 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
20 changes: 17 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 Expand Up @@ -4130,6 +4133,17 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
* Hint to catch really bogus numbers, bitflips or so, more exact checks are
* done later
*/
if (btrfs_super_bytes_used(sb) < 6 * btrfs_super_nodesize(sb)) {
btrfs_err(fs_info, "bytes_used is too small %llu",
btrfs_super_bytes_used(sb));
ret = -EINVAL;
}
if (!is_power_of_2(btrfs_super_stripesize(sb)) ||
btrfs_super_stripesize(sb) != sectorsize) {
btrfs_err(fs_info, "invalid stripesize %u",
btrfs_super_stripesize(sb));
ret = -EINVAL;
}
if (btrfs_super_num_devices(sb) > (1UL << 31))
printk(KERN_WARNING "BTRFS: suspicious number of devices: %llu\n",
btrfs_super_num_devices(sb));
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
5 changes: 5 additions & 0 deletions fs/btrfs/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ int __init btrfs_hash_init(void)
return PTR_ERR_OR_ZERO(tfm);
}

const char* btrfs_crc32c_impl(void)
{
return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm));
}

void btrfs_hash_exit(void)
{
crypto_free_shash(tfm);
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
int __init btrfs_hash_init(void);

void btrfs_hash_exit(void);
const char* btrfs_crc32c_impl(void);

u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length);

Expand Down
57 changes: 36 additions & 21 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ static void btrfs_interface_exit(void)

static void btrfs_print_mod_info(void)
{
printk(KERN_INFO "Btrfs loaded"
printk(KERN_INFO "Btrfs loaded, crc32c=%s"
#ifdef CONFIG_BTRFS_DEBUG
", debug=on"
#endif
Expand All @@ -2313,33 +2313,48 @@ static void btrfs_print_mod_info(void)
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
", integrity-checker=on"
#endif
"\n");
"\n",
btrfs_crc32c_impl());
}

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
Loading

0 comments on commit 3d0f0b6

Please sign in to comment.