Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06ea65a3 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason
Browse files

Btrfs: add a sanity test for btrfs_split_item



While looking at somebodys corruption I became completely convinced that
btrfs_split_item was broken, so I wrote this test to verify that it was working
as it was supposed to.  Thankfully it appears to be working as intended, so just
add this test to make sure nobody breaks it in the future.  Thanks,

Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent dd3cc16b
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -14,4 +14,5 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o


btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
	tests/extent-buffer-tests.o
+3 −1
Original line number Original line Diff line number Diff line
@@ -1724,7 +1724,9 @@ struct btrfs_root {
	int ref_cows;
	int ref_cows;
	int track_dirty;
	int track_dirty;
	int in_radix;
	int in_radix;

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	int dummy_root;
#endif
	u64 defrag_trans_start;
	u64 defrag_trans_start;
	struct btrfs_key defrag_progress;
	struct btrfs_key defrag_progress;
	struct btrfs_key defrag_max;
	struct btrfs_key defrag_max;
+34 −4
Original line number Original line Diff line number Diff line
@@ -1229,6 +1229,7 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
	atomic_set(&root->refs, 1);
	atomic_set(&root->refs, 1);
	root->log_transid = 0;
	root->log_transid = 0;
	root->last_log_commit = 0;
	root->last_log_commit = 0;
	if (fs_info)
		extent_io_tree_init(&root->dirty_log_pages,
		extent_io_tree_init(&root->dirty_log_pages,
				     fs_info->btree_inode->i_mapping);
				     fs_info->btree_inode->i_mapping);


@@ -1236,7 +1237,10 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
	memset(&root->root_item, 0, sizeof(root->root_item));
	memset(&root->root_item, 0, sizeof(root->root_item));
	memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
	memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
	memset(&root->root_kobj, 0, sizeof(root->root_kobj));
	memset(&root->root_kobj, 0, sizeof(root->root_kobj));
	if (fs_info)
		root->defrag_trans_start = fs_info->generation;
		root->defrag_trans_start = fs_info->generation;
	else
		root->defrag_trans_start = 0;
	init_completion(&root->kobj_unregister);
	init_completion(&root->kobj_unregister);
	root->defrag_running = 0;
	root->defrag_running = 0;
	root->root_key.objectid = objectid;
	root->root_key.objectid = objectid;
@@ -1253,6 +1257,22 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
	return root;
	return root;
}
}


#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 *root;

	root = btrfs_alloc_root(NULL);
	if (!root)
		return ERR_PTR(-ENOMEM);
	__setup_root(4096, 4096, 4096, 4096, root, NULL, 1);
	root->dummy_root = 1;

	return root;
}
#endif

struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
				     struct btrfs_fs_info *fs_info,
				     struct btrfs_fs_info *fs_info,
				     u64 objectid)
				     u64 objectid)
@@ -3670,10 +3690,20 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *buf)


void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
{
{
	struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root;
	struct btrfs_root *root;
	u64 transid = btrfs_header_generation(buf);
	u64 transid = btrfs_header_generation(buf);
	int was_dirty;
	int was_dirty;


#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	/*
	 * This is a fast path so only do this check if we have sanity tests
	 * enabled.  Normal people shouldn't be marking dummy buffers as dirty
	 * outside of the sanity tests.
	 */
	if (unlikely(test_bit(EXTENT_BUFFER_DUMMY, &buf->bflags)))
		return;
#endif
	root = BTRFS_I(buf->pages[0]->mapping->host)->root;
	btrfs_assert_tree_locked(buf);
	btrfs_assert_tree_locked(buf);
	if (transid != root->fs_info->generation)
	if (transid != root->fs_info->generation)
		WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, "
		WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, "
+4 −0
Original line number Original line Diff line number Diff line
@@ -86,6 +86,10 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
				 struct btrfs_root *root);
				 struct btrfs_root *root);
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
struct btrfs_root *btrfs_alloc_dummy_root(void);
#endif

/*
/*
 * This function is used to grab the root, and avoid it is freed when we
 * This function is used to grab the root, and avoid it is freed when we
 * access it. But it doesn't ensure that the tree is not dropped.
 * access it. But it doesn't ensure that the tree is not dropped.
+6 −1
Original line number Original line Diff line number Diff line
@@ -1789,7 +1789,12 @@ static void btrfs_print_info(void)


static int btrfs_run_sanity_tests(void)
static int btrfs_run_sanity_tests(void)
{
{
	return btrfs_test_free_space_cache();
	int ret;

	ret = btrfs_test_free_space_cache();
	if (ret)
		return ret;
	return btrfs_test_extent_buffer_operations();
}
}


static int __init init_btrfs_fs(void)
static int __init init_btrfs_fs(void)
Loading