Btrfs: add tests for btrfs_get_extent
PATCH 1/1 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 <[email protected]>
--- fs/btrfs/Makefile | 3 +- fs/btrfs/ctree.h | 4 + fs/btrfs/inode.c | 8 + fs/btrfs/super.c | 3 + fs/btrfs/tests/btrfs-tests.c | 8 +- fs/btrfs/tests/btrfs-tests.h | 5 + fs/btrfs/tests/inode-tests.c | 832 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 861 insertions(+), 2 deletions(-) create mode 100644 fs/btrfs/tests/inode-tests.c
fs/btrfs/Makefile +2 -1
@@ -15,4 +15,5 @@ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \ - tests/extent-buffer-tests.o tests/btrfs-tests.o tests/extent-io-tests.o + tests/extent-buffer-tests.o tests/btrfs-tests.o \ + tests/extent-io-tests.o tests/inode-tests.o
fs/btrfs/ctree.h +4 -0
@@ -4034,5 +4034,9 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) return signal_pending(current); } +/* Sanity test specific functions */ +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +void btrfs_test_destroy_inode (struct inode *inode); +#endif #endif
fs/btrfs/inode.c +8 -0
@@ -7794,6 +7794,14 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)return inode; } +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +void btrfs_test_destroy_inode (struct inode *inode) +{ +btrfs_drop_extent_cache (inode,0 , (u64)-1 ,0 ); +kmem_cache_free (btrfs_inode_cachep,BTRFS_I (inode)); +} +#endif +static void btrfs_i_callback (struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu);
fs/btrfs/super.c +3 -0
@@ -1802,6 +1802,9 @@ static int btrfs_run_sanity_tests(void)if (ret) goto out; ret =btrfs_test_extent_io (); +if (ret) + goto out; + ret =btrfs_test_inodes (); out:btrfs_destroy_test_fs ();return ret;
fs/btrfs/tests/btrfs-tests.c +7 -1
@@ -24,11 +24,17 @@static struct vfsmount *test_mnt =NULL ; +static const struct super_operations btrfs_test_super_ops = { + .alloc_inode = btrfs_alloc_inode, + .destroy_inode = btrfs_test_destroy_inode, +}; +static struct dentry *btrfs_test_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *data) { -return mount_pseudo (fs_type,"btrfs_test:" ,NULL ,NULL ,BTRFS_TEST_MAGIC ); +return mount_pseudo (fs_type,"btrfs_test:" , &btrfs_test_super_ops, +NULL ,BTRFS_TEST_MAGIC ); }static struct file_system_type test_type = {
fs/btrfs/tests/btrfs-tests.h +5 -0
@@ -26,6 +26,7 @@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_init_test_fs (void );void btrfs_destroy_test_fs (void );struct inode *btrfs_new_test_inode (void );
@@ -49,6 +50,10 @@ static inline int btrfs_test_extent_io(void) {return 0 ; } +static inline int int btrfs_test_inodes(void) +{ +return 0 ; +}#endif #endif
fs/btrfs/tests/inode-tests.c new file +832 -0
832 lines not on this page · raw message
Signature · 1 line
1.8.3.1