Skip to content

Commit

Permalink
btrfs: tests, use BTRFS_FS_STATE_DUMMY_FS_INFO instead of dummy root
Browse files Browse the repository at this point in the history
Now that we have a dummy fs_info associated with each test that
uses a root, we don't need the DUMMY_ROOT bit anymore.  This lets
us make choices without needing an actual root like in e.g.
btrfs_find_create_tree_block.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Jeff Mahoney authored and David Sterba committed Jul 26, 2016
1 parent 7c0260e commit f5ee5c9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fs/btrfs/backref.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
goto out;
}

if (btrfs_test_is_dummy_root(root)) {
if (btrfs_is_testing(fs_info)) {
srcu_read_unlock(&fs_info->subvol_srcu, index);
ret = -ENOENT;
goto out;
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct extent_buffer *buf)
{
if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return 0;

/* ensure we can see the force_cow */
Expand Down
17 changes: 8 additions & 9 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,12 +1115,11 @@ struct btrfs_subvolume_writers {
#define BTRFS_ROOT_REF_COWS 1
#define BTRFS_ROOT_TRACK_DIRTY 2
#define BTRFS_ROOT_IN_RADIX 3
#define BTRFS_ROOT_DUMMY_ROOT 4
#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 5
#define BTRFS_ROOT_DEFRAG_RUNNING 6
#define BTRFS_ROOT_FORCE_COW 7
#define BTRFS_ROOT_MULTI_LOG_TASKS 8
#define BTRFS_ROOT_DIRTY 9
#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 4
#define BTRFS_ROOT_DEFRAG_RUNNING 5
#define BTRFS_ROOT_FORCE_COW 6
#define BTRFS_ROOT_MULTI_LOG_TASKS 7
#define BTRFS_ROOT_DIRTY 8

/*
* in ram representation of the tree. extent_root is used for all allocations
Expand Down Expand Up @@ -3613,13 +3612,13 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
void btrfs_test_destroy_inode(struct inode *inode);
#endif

static inline int btrfs_test_is_dummy_root(struct btrfs_root *root)
static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
{
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
if (unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
&fs_info->fs_state)))
return 1;
#endif
return 0;
}

#endif
3 changes: 1 addition & 2 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 bytenr)
{
if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return alloc_test_extent_buffer(root->fs_info, bytenr,
root->nodesize);
return alloc_extent_buffer(root->fs_info, bytenr);
Expand Down Expand Up @@ -1330,7 +1330,6 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info,
/* We don't use the stripesize in selftest, set it as sectorsize */
__setup_root(nodesize, sectorsize, sectorsize, root, fs_info,
BTRFS_ROOT_TREE_OBJECTID);
set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
root->alloc_bytenr = 0;

return root;
Expand Down
8 changes: 4 additions & 4 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
u64, u64, u64, u64, u64, u64);


if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return 0;

ref_root = btrfs_header_owner(buf);
Expand Down Expand Up @@ -6101,7 +6101,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
if (dropped > 0)
to_free += btrfs_calc_trans_metadata_size(root, dropped);

if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return;

trace_btrfs_space_reservation(root->fs_info, "delalloc",
Expand Down Expand Up @@ -7217,7 +7217,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root,
int ret;
struct btrfs_fs_info *fs_info = root->fs_info;

if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(fs_info))
return 0;

add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid);
Expand Down Expand Up @@ -8356,7 +8356,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
SKINNY_METADATA);

#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
if (btrfs_test_is_dummy_root(root)) {
if (btrfs_is_testing(root->fs_info)) {
buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr,
level);
if (!IS_ERR(buf))
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ static void btrfs_set_bit_hook(struct inode *inode,
}

/* For sanity tests */
if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return;

__percpu_counter_add(&root->fs_info->delalloc_bytes, len,
Expand Down Expand Up @@ -1803,7 +1803,7 @@ static void btrfs_clear_bit_hook(struct inode *inode,
btrfs_delalloc_release_metadata(inode, len);

/* For sanity tests. */
if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return;

if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/qgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf;
struct btrfs_key key;

if (btrfs_test_is_dummy_root(quota_root))
if (btrfs_is_testing(quota_root->fs_info))
return 0;

path = btrfs_alloc_path();
Expand Down Expand Up @@ -728,7 +728,7 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans,
int ret;
int slot;

if (btrfs_test_is_dummy_root(root))
if (btrfs_is_testing(root->fs_info))
return 0;

key.objectid = 0;
Expand Down

0 comments on commit f5ee5c9

Please sign in to comment.