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

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

Btrfs: add sanity tests for new qgroup accounting code



This exercises the various parts of the new qgroup accounting code.  We do some
basic stuff and do some things with the shared refs to make sure all that code
works.  I had to add a bunch of infrastructure because I needed to be able to
insert items into a fake tree without having to do all the hard work myself,
hopefully this will be usefull in the future.  Thanks,

Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent fcebe456
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,4 +16,4 @@ 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/inode-tests.o
	tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o
+4 −0
Original line number Diff line number Diff line
@@ -900,7 +900,11 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
		goto out;
	BUG_ON(ret == 0);

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	if (trans && likely(trans->type != __TRANS_DUMMY)) {
#else
	if (trans) {
#endif
		/*
		 * look if there are updates for this ref queued and lock the
		 * head
+4 −0
Original line number Diff line number Diff line
@@ -1506,6 +1506,10 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
				   struct btrfs_root *root,
				   struct extent_buffer *buf)
{
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
		return 0;
#endif
	/* ensure we can see the force_cow */
	smp_rmb();

+6 −0
Original line number Diff line number Diff line
@@ -1798,6 +1798,10 @@ struct btrfs_root {

	u64 highest_objectid;

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	u64 alloc_bytenr;
#endif

	u64 defrag_trans_start;
	struct btrfs_key defrag_progress;
	struct btrfs_key defrag_max;
@@ -4111,6 +4115,8 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
/* Sanity test specific functions */
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
void btrfs_test_destroy_inode(struct inode *inode);
int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
			       u64 rfer, u64 excl);
#endif

#endif
+13 −5
Original line number Diff line number Diff line
@@ -1110,6 +1110,11 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
						 u64 bytenr, u32 blocksize)
{
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
	if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
		return alloc_test_extent_buffer(root->fs_info, bytenr,
						blocksize);
#endif
	return alloc_extent_buffer(root->fs_info, bytenr, blocksize);
}

@@ -1288,6 +1293,7 @@ struct btrfs_root *btrfs_alloc_dummy_root(void)
		return ERR_PTR(-ENOMEM);
	__setup_root(4096, 4096, 4096, 4096, root, NULL, 1);
	set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
	root->alloc_bytenr = 0;

	return root;
}
@@ -2089,7 +2095,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
		free_root_extent_buffers(info->chunk_root);
}

static void del_fs_roots(struct btrfs_fs_info *fs_info)
void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
{
	int ret;
	struct btrfs_root *gang[8];
@@ -2969,7 +2975,7 @@ int open_ctree(struct super_block *sb,
fail_trans_kthread:
	kthread_stop(fs_info->transaction_kthread);
	btrfs_cleanup_transaction(fs_info->tree_root);
	del_fs_roots(fs_info);
	btrfs_free_fs_roots(fs_info);
fail_cleaner:
	kthread_stop(fs_info->cleaner_kthread);

@@ -3504,7 +3510,9 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
	if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
		btrfs_free_log(NULL, root);

	if (root->free_ino_pinned)
		__btrfs_remove_free_space_cache(root->free_ino_pinned);
	if (root->free_ino_ctl)
		__btrfs_remove_free_space_cache(root->free_ino_ctl);
	free_fs_root(root);
}
@@ -3655,7 +3663,7 @@ int close_ctree(struct btrfs_root *root)

	btrfs_sysfs_remove_one(fs_info);

	del_fs_roots(fs_info);
	btrfs_free_fs_roots(fs_info);

	btrfs_put_block_group_cache(fs_info);

Loading