Commit 7c0260ee authored by Jeff Mahoney's avatar Jeff Mahoney Committed by David Sterba
Browse files

btrfs: tests, require fs_info for root



This allows the upcoming patchset to push nodesize and sectorsize into
fs_info.

Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8632daae
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -117,6 +117,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
#define BTRFS_FS_STATE_REMOUNTING	1
#define BTRFS_FS_STATE_REMOUNTING	1
#define BTRFS_FS_STATE_TRANS_ABORTED	2
#define BTRFS_FS_STATE_TRANS_ABORTED	2
#define BTRFS_FS_STATE_DEV_REPLACING	3
#define BTRFS_FS_STATE_DEV_REPLACING	3
#define BTRFS_FS_STATE_DUMMY_FS_INFO	4


#define BTRFS_BACKREF_REV_MAX		256
#define BTRFS_BACKREF_REV_MAX		256
#define BTRFS_BACKREF_REV_SHIFT		56
#define BTRFS_BACKREF_REV_SHIFT		56
+10 −5
Original line number Original line Diff line number Diff line
@@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
			 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
			 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
			 u64 objectid)
			 u64 objectid)
{
{
	bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
	root->node = NULL;
	root->node = NULL;
	root->commit_root = NULL;
	root->commit_root = NULL;
	root->sectorsize = sectorsize;
	root->sectorsize = sectorsize;
@@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
	root->log_transid = 0;
	root->log_transid = 0;
	root->log_transid_committed = -1;
	root->log_transid_committed = -1;
	root->last_log_commit = 0;
	root->last_log_commit = 0;
	if (fs_info)
	if (!dummy)
		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);


	memset(&root->root_key, 0, sizeof(root->root_key));
	memset(&root->root_key, 0, sizeof(root->root_key));
	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));
	if (fs_info)
	if (!dummy)
		root->defrag_trans_start = fs_info->generation;
		root->defrag_trans_start = fs_info->generation;
	else
	else
		root->defrag_trans_start = 0;
		root->defrag_trans_start = 0;
@@ -1315,15 +1316,19 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,


#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
/* Should only be used by the testing infrastructure */
/* Should only be used by the testing infrastructure */
struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize)
struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
					  u32 sectorsize, u32 nodesize)
{
{
	struct btrfs_root *root;
	struct btrfs_root *root;


	root = btrfs_alloc_root(NULL, GFP_KERNEL);
	if (!fs_info)
		return ERR_PTR(-EINVAL);

	root = btrfs_alloc_root(fs_info, GFP_KERNEL);
	if (!root)
	if (!root)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);
	/* We don't use the stripesize in selftest, set it as sectorsize */
	/* We don't use the stripesize in selftest, set it as sectorsize */
	__setup_root(nodesize, sectorsize, sectorsize, root, NULL,
	__setup_root(nodesize, sectorsize, sectorsize, root, fs_info,
			BTRFS_ROOT_TREE_OBJECTID);
			BTRFS_ROOT_TREE_OBJECTID);
	set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
	set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
	root->alloc_bytenr = 0;
	root->alloc_bytenr = 0;
+2 −1
Original line number Original line Diff line number Diff line
@@ -90,7 +90,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
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
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize);
struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
					  u32 sectorsize, u32 nodesize);
#endif
#endif


/*
/*
+17 −3
Original line number Original line Diff line number Diff line
@@ -128,14 +128,27 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void)
	extent_io_tree_init(&fs_info->freed_extents[0], NULL);
	extent_io_tree_init(&fs_info->freed_extents[0], NULL);
	extent_io_tree_init(&fs_info->freed_extents[1], NULL);
	extent_io_tree_init(&fs_info->freed_extents[1], NULL);
	fs_info->pinned_extents = &fs_info->freed_extents[0];
	fs_info->pinned_extents = &fs_info->freed_extents[0];
	set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);

	test_mnt->mnt_sb->s_fs_info = fs_info;

	return fs_info;
	return fs_info;
}
}


static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
{
{
	struct radix_tree_iter iter;
	struct radix_tree_iter iter;
	void **slot;
	void **slot;


	if (!fs_info)
		return;

	if (WARN_ON(!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
			      &fs_info->fs_state)))
		return;

	test_mnt->mnt_sb->s_fs_info = NULL;

	spin_lock(&fs_info->buffer_lock);
	spin_lock(&fs_info->buffer_lock);
	radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
	radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
		struct extent_buffer *eb;
		struct extent_buffer *eb;
@@ -167,10 +180,11 @@ void btrfs_free_dummy_root(struct btrfs_root *root)
{
{
	if (!root)
	if (!root)
		return;
		return;
	/* Will be freed by btrfs_free_fs_roots */
	if (WARN_ON(test_bit(BTRFS_ROOT_IN_RADIX, &root->state)))
		return;
	if (root->node)
	if (root->node)
		free_extent_buffer(root->node);
		free_extent_buffer(root->node);
	if (root->fs_info)
		btrfs_free_dummy_fs_info(root->fs_info);
	kfree(root);
	kfree(root);
}
}


+1 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
struct inode *btrfs_new_test_inode(void);
struct inode *btrfs_new_test_inode(void);
struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(void);
void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info);
void btrfs_free_dummy_root(struct btrfs_root *root);
void btrfs_free_dummy_root(struct btrfs_root *root);
struct btrfs_block_group_cache *
struct btrfs_block_group_cache *
btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
btrfs_alloc_dummy_block_group(unsigned long length, u32 sectorsize);
Loading