Skip to content

Commit aaedb55

Browse files
Josef BacikChris Mason
authored andcommitted
Btrfs: add tests for btrfs_get_extent
I'm going to be removing hole extents in the near future so I wanted to make a sanity test for btrfs_get_extent to make sure I don't break anything in the meantime. This patch just puts btrfs_get_extent through its paces by giving it a completely unreasonable mapping to look at and make sure it is giving us back maps that make sense. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 294e30f commit aaedb55

File tree

7 files changed

+861
-2
lines changed

7 files changed

+861
-2
lines changed

fs/btrfs/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
1515
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
1616

1717
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
18-
tests/extent-buffer-tests.o tests/btrfs-tests.o tests/extent-io-tests.o
18+
tests/extent-buffer-tests.o tests/btrfs-tests.o \
19+
tests/extent-io-tests.o tests/inode-tests.o

fs/btrfs/ctree.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,5 +4034,9 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
40344034
return signal_pending(current);
40354035
}
40364036

4037+
/* Sanity test specific functions */
4038+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
4039+
void btrfs_test_destroy_inode(struct inode *inode);
4040+
#endif
40374041

40384042
#endif

fs/btrfs/inode.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7795,6 +7795,14 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
77957795
return inode;
77967796
}
77977797

7798+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
7799+
void btrfs_test_destroy_inode(struct inode *inode)
7800+
{
7801+
btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
7802+
kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
7803+
}
7804+
#endif
7805+
77987806
static void btrfs_i_callback(struct rcu_head *head)
77997807
{
78007808
struct inode *inode = container_of(head, struct inode, i_rcu);

fs/btrfs/super.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,9 @@ static int btrfs_run_sanity_tests(void)
18021802
if (ret)
18031803
goto out;
18041804
ret = btrfs_test_extent_io();
1805+
if (ret)
1806+
goto out;
1807+
ret = btrfs_test_inodes();
18051808
out:
18061809
btrfs_destroy_test_fs();
18071810
return ret;

fs/btrfs/tests/btrfs-tests.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424

2525
static struct vfsmount *test_mnt = NULL;
2626

27+
static const struct super_operations btrfs_test_super_ops = {
28+
.alloc_inode = btrfs_alloc_inode,
29+
.destroy_inode = btrfs_test_destroy_inode,
30+
};
31+
2732
static struct dentry *btrfs_test_mount(struct file_system_type *fs_type,
2833
int flags, const char *dev_name,
2934
void *data)
3035
{
31-
return mount_pseudo(fs_type, "btrfs_test:", NULL, NULL, BTRFS_TEST_MAGIC);
36+
return mount_pseudo(fs_type, "btrfs_test:", &btrfs_test_super_ops,
37+
NULL, BTRFS_TEST_MAGIC);
3238
}
3339

3440
static struct file_system_type test_type = {

fs/btrfs/tests/btrfs-tests.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
int btrfs_test_free_space_cache(void);
2727
int btrfs_test_extent_buffer_operations(void);
2828
int btrfs_test_extent_io(void);
29+
int btrfs_test_inodes(void);
2930
int btrfs_init_test_fs(void);
3031
void btrfs_destroy_test_fs(void);
3132
struct inode *btrfs_new_test_inode(void);
@@ -49,6 +50,10 @@ static inline int btrfs_test_extent_io(void)
4950
{
5051
return 0;
5152
}
53+
static inline int btrfs_test_inodes(void)
54+
{
55+
return 0;
56+
}
5257
#endif
5358

5459
#endif

0 commit comments

Comments
 (0)