Commit 3cdde224 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by David Sterba
Browse files

btrfs: btrfs_test_opt and friends should take a btrfs_fs_info



btrfs_test_opt and friends only use the root pointer to access
the fs_info.  Let's pass the fs_info directly in preparation to
eliminate similar patterns all over btrfs.

Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent bc074524
Loading
Loading
Loading
Loading
+11 −11
Original line number Original line Diff line number Diff line
@@ -1301,21 +1301,21 @@ struct btrfs_root {
#define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
#define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
#define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
#define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
#define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
#define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
#define btrfs_test_opt(root, opt)	((root)->fs_info->mount_opt & \
#define btrfs_test_opt(fs_info, opt)	((fs_info)->mount_opt & \
					 BTRFS_MOUNT_##opt)
					 BTRFS_MOUNT_##opt)


#define btrfs_set_and_info(root, opt, fmt, args...)			\
#define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
{									\
{									\
	if (!btrfs_test_opt(root, opt))					\
	if (!btrfs_test_opt(fs_info, opt))				\
		btrfs_info(root->fs_info, fmt, ##args);			\
		btrfs_info(fs_info, fmt, ##args);			\
	btrfs_set_opt(root->fs_info->mount_opt, opt);			\
	btrfs_set_opt(fs_info->mount_opt, opt);				\
}
}


#define btrfs_clear_and_info(root, opt, fmt, args...)			\
#define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
{									\
{									\
	if (btrfs_test_opt(root, opt))					\
	if (btrfs_test_opt(fs_info, opt))				\
		btrfs_info(root->fs_info, fmt, ##args);			\
		btrfs_info(fs_info, fmt, ##args);			\
	btrfs_clear_opt(root->fs_info->mount_opt, opt);			\
	btrfs_clear_opt(fs_info->mount_opt, opt);			\
}
}


#ifdef CONFIG_BTRFS_DEBUG
#ifdef CONFIG_BTRFS_DEBUG
@@ -1323,9 +1323,9 @@ static inline int
btrfs_should_fragment_free_space(struct btrfs_root *root,
btrfs_should_fragment_free_space(struct btrfs_root *root,
				 struct btrfs_block_group_cache *block_group)
				 struct btrfs_block_group_cache *block_group)
{
{
	return (btrfs_test_opt(root, FRAGMENT_METADATA) &&
	return (btrfs_test_opt(root->fs_info, FRAGMENT_METADATA) &&
		block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
		block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
	       (btrfs_test_opt(root, FRAGMENT_DATA) &&
	       (btrfs_test_opt(root->fs_info, FRAGMENT_DATA) &&
		block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
		block_group->flags &  BTRFS_BLOCK_GROUP_DATA);
}
}
#endif
#endif
+2 −2
Original line number Original line Diff line number Diff line
@@ -142,7 +142,7 @@ no_valid_dev_replace_entry_found:
		 * missing
		 * missing
		 */
		 */
		if (!dev_replace->srcdev &&
		if (!dev_replace->srcdev &&
		    !btrfs_test_opt(dev_root, DEGRADED)) {
		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
			ret = -EIO;
			ret = -EIO;
			btrfs_warn(fs_info,
			btrfs_warn(fs_info,
			   "cannot mount because device replace operation is ongoing and");
			   "cannot mount because device replace operation is ongoing and");
@@ -151,7 +151,7 @@ no_valid_dev_replace_entry_found:
			   src_devid);
			   src_devid);
		}
		}
		if (!dev_replace->tgtdev &&
		if (!dev_replace->tgtdev &&
		    !btrfs_test_opt(dev_root, DEGRADED)) {
		    !btrfs_test_opt(dev_root->fs_info, DEGRADED)) {
			ret = -EIO;
			ret = -EIO;
			btrfs_warn(fs_info,
			btrfs_warn(fs_info,
			   "cannot mount because device replace operation is ongoing and");
			   "cannot mount because device replace operation is ongoing and");
+11 −11
Original line number Original line Diff line number Diff line
@@ -3019,8 +3019,8 @@ retry_root_backup:
	if (IS_ERR(fs_info->transaction_kthread))
	if (IS_ERR(fs_info->transaction_kthread))
		goto fail_cleaner;
		goto fail_cleaner;


	if (!btrfs_test_opt(tree_root, SSD) &&
	if (!btrfs_test_opt(tree_root->fs_info, SSD) &&
	    !btrfs_test_opt(tree_root, NOSSD) &&
	    !btrfs_test_opt(tree_root->fs_info, NOSSD) &&
	    !fs_info->fs_devices->rotating) {
	    !fs_info->fs_devices->rotating) {
		btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
		btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
		btrfs_set_opt(fs_info->mount_opt, SSD);
		btrfs_set_opt(fs_info->mount_opt, SSD);
@@ -3033,9 +3033,9 @@ retry_root_backup:
	btrfs_apply_pending_changes(fs_info);
	btrfs_apply_pending_changes(fs_info);


#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
	if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
	if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) {
		ret = btrfsic_mount(tree_root, fs_devices,
		ret = btrfsic_mount(tree_root, fs_devices,
				    btrfs_test_opt(tree_root,
				    btrfs_test_opt(tree_root->fs_info,
					CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
					CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
				    1 : 0,
				    1 : 0,
				    fs_info->check_integrity_print_mask);
				    fs_info->check_integrity_print_mask);
@@ -3051,7 +3051,7 @@ retry_root_backup:


	/* do not make disk changes in broken FS or nologreplay is given */
	/* do not make disk changes in broken FS or nologreplay is given */
	if (btrfs_super_log_root(disk_super) != 0 &&
	if (btrfs_super_log_root(disk_super) != 0 &&
	    !btrfs_test_opt(tree_root, NOLOGREPLAY)) {
	    !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) {
		ret = btrfs_replay_log(fs_info, fs_devices);
		ret = btrfs_replay_log(fs_info, fs_devices);
		if (ret) {
		if (ret) {
			err = ret;
			err = ret;
@@ -3092,7 +3092,7 @@ retry_root_backup:
	if (sb->s_flags & MS_RDONLY)
	if (sb->s_flags & MS_RDONLY)
		return 0;
		return 0;


	if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) &&
	if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) &&
	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
		btrfs_info(fs_info, "creating free space tree");
		btrfs_info(fs_info, "creating free space tree");
		ret = btrfs_create_free_space_tree(fs_info);
		ret = btrfs_create_free_space_tree(fs_info);
@@ -3129,7 +3129,7 @@ retry_root_backup:


	btrfs_qgroup_rescan_resume(fs_info);
	btrfs_qgroup_rescan_resume(fs_info);


	if (btrfs_test_opt(tree_root, CLEAR_CACHE) &&
	if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) &&
	    btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
	    btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
		btrfs_info(fs_info, "clearing free space tree");
		btrfs_info(fs_info, "clearing free space tree");
		ret = btrfs_clear_free_space_tree(fs_info);
		ret = btrfs_clear_free_space_tree(fs_info);
@@ -3150,7 +3150,7 @@ retry_root_backup:
			close_ctree(tree_root);
			close_ctree(tree_root);
			return ret;
			return ret;
		}
		}
	} else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
	} else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) ||
		   fs_info->generation !=
		   fs_info->generation !=
				btrfs_super_uuid_tree_generation(disk_super)) {
				btrfs_super_uuid_tree_generation(disk_super)) {
		btrfs_info(fs_info, "checking UUID tree");
		btrfs_info(fs_info, "checking UUID tree");
@@ -3227,7 +3227,7 @@ fail:
	return err;
	return err;


recovery_tree_root:
recovery_tree_root:
	if (!btrfs_test_opt(tree_root, USEBACKUPROOT))
	if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT))
		goto fail_tree_roots;
		goto fail_tree_roots;


	free_root_pointers(fs_info, 0);
	free_root_pointers(fs_info, 0);
@@ -3642,7 +3642,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
	int total_errors = 0;
	int total_errors = 0;
	u64 flags;
	u64 flags;


	do_barriers = !btrfs_test_opt(root, NOBARRIER);
	do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER);
	backup_super_roots(root->fs_info);
	backup_super_roots(root->fs_info);


	sb = root->fs_info->super_for_commit;
	sb = root->fs_info->super_for_commit;
@@ -3926,7 +3926,7 @@ void close_ctree(struct btrfs_root *root)
	iput(fs_info->btree_inode);
	iput(fs_info->btree_inode);


#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
	if (btrfs_test_opt(root, CHECK_INTEGRITY))
	if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY))
		btrfsic_unmount(root, fs_info->fs_devices);
		btrfsic_unmount(root, fs_info->fs_devices);
#endif
#endif


+15 −15
Original line number Original line Diff line number Diff line
@@ -3448,7 +3448,7 @@ again:


	spin_lock(&block_group->lock);
	spin_lock(&block_group->lock);
	if (block_group->cached != BTRFS_CACHE_FINISHED ||
	if (block_group->cached != BTRFS_CACHE_FINISHED ||
	    !btrfs_test_opt(root, SPACE_CACHE)) {
	    !btrfs_test_opt(root->fs_info, SPACE_CACHE)) {
		/*
		/*
		 * don't bother trying to write stuff out _if_
		 * don't bother trying to write stuff out _if_
		 * a) we're not cached,
		 * a) we're not cached,
@@ -3525,7 +3525,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
	struct btrfs_path *path;
	struct btrfs_path *path;


	if (list_empty(&cur_trans->dirty_bgs) ||
	if (list_empty(&cur_trans->dirty_bgs) ||
	    !btrfs_test_opt(root, SPACE_CACHE))
	    !btrfs_test_opt(root->fs_info, SPACE_CACHE))
		return 0;
		return 0;


	path = btrfs_alloc_path();
	path = btrfs_alloc_path();
@@ -4444,7 +4444,7 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
	thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
	thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
		btrfs_calc_trans_metadata_size(root, 1);
		btrfs_calc_trans_metadata_size(root, 1);


	if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
	if (left < thresh && btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
		btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
		btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
			left, thresh, type);
			left, thresh, type);
		dump_space_info(info, 0, 0);
		dump_space_info(info, 0, 0);
@@ -6216,7 +6216,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
		spin_lock(&cache->space_info->lock);
		spin_lock(&cache->space_info->lock);
		spin_lock(&cache->lock);
		spin_lock(&cache->lock);


		if (btrfs_test_opt(root, SPACE_CACHE) &&
		if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
		    cache->disk_cache_state < BTRFS_DC_CLEAR)
		    cache->disk_cache_state < BTRFS_DC_CLEAR)
			cache->disk_cache_state = BTRFS_DC_CLEAR;
			cache->disk_cache_state = BTRFS_DC_CLEAR;


@@ -6598,7 +6598,7 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info,
		   u64 *empty_cluster)
		   u64 *empty_cluster)
{
{
	struct btrfs_free_cluster *ret = NULL;
	struct btrfs_free_cluster *ret = NULL;
	bool ssd = btrfs_test_opt(root, SSD);
	bool ssd = btrfs_test_opt(root->fs_info, SSD);


	*empty_cluster = 0;
	*empty_cluster = 0;
	if (btrfs_mixed_space_info(space_info))
	if (btrfs_mixed_space_info(space_info))
@@ -6743,7 +6743,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
			break;
			break;
		}
		}


		if (btrfs_test_opt(root, DISCARD))
		if (btrfs_test_opt(root->fs_info, DISCARD))
			ret = btrfs_discard_extent(root, start,
			ret = btrfs_discard_extent(root, start,
						   end + 1 - start, NULL);
						   end + 1 - start, NULL);


@@ -7962,7 +7962,7 @@ again:
			if (num_bytes == min_alloc_size)
			if (num_bytes == min_alloc_size)
				final_tried = true;
				final_tried = true;
			goto again;
			goto again;
		} else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
		} else if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
			struct btrfs_space_info *sinfo;
			struct btrfs_space_info *sinfo;


			sinfo = __find_space_info(root->fs_info, flags);
			sinfo = __find_space_info(root->fs_info, flags);
@@ -7993,7 +7993,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
	if (pin)
	if (pin)
		pin_down_extent(root, cache, start, len, 1);
		pin_down_extent(root, cache, start, len, 1);
	else {
	else {
		if (btrfs_test_opt(root, DISCARD))
		if (btrfs_test_opt(root->fs_info, DISCARD))
			ret = btrfs_discard_extent(root, start, len, NULL);
			ret = btrfs_discard_extent(root, start, len, NULL);
		btrfs_add_free_space(cache, start, len);
		btrfs_add_free_space(cache, start, len);
		btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
		btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
@@ -8301,7 +8301,7 @@ again:
		goto again;
		goto again;
	}
	}


	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
		static DEFINE_RATELIMIT_STATE(_rs,
		static DEFINE_RATELIMIT_STATE(_rs,
				DEFAULT_RATELIMIT_INTERVAL * 10,
				DEFAULT_RATELIMIT_INTERVAL * 10,
				/*DEFAULT_RATELIMIT_BURST*/ 1);
				/*DEFAULT_RATELIMIT_BURST*/ 1);
@@ -9735,7 +9735,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
	int full = 0;
	int full = 0;
	int ret = 0;
	int ret = 0;


	debug = btrfs_test_opt(root, ENOSPC_DEBUG);
	debug = btrfs_test_opt(root->fs_info, ENOSPC_DEBUG);


	block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
	block_group = btrfs_lookup_block_group(root->fs_info, bytenr);


@@ -10148,10 +10148,10 @@ int btrfs_read_block_groups(struct btrfs_root *root)
	path->reada = READA_FORWARD;
	path->reada = READA_FORWARD;


	cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
	cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
	if (btrfs_test_opt(root, SPACE_CACHE) &&
	if (btrfs_test_opt(root->fs_info, SPACE_CACHE) &&
	    btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
	    btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
		need_clear = 1;
		need_clear = 1;
	if (btrfs_test_opt(root, CLEAR_CACHE))
	if (btrfs_test_opt(root->fs_info, CLEAR_CACHE))
		need_clear = 1;
		need_clear = 1;


	while (1) {
	while (1) {
@@ -10182,7 +10182,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
			 * b) Setting 'dirty flag' makes sure that we flush
			 * b) Setting 'dirty flag' makes sure that we flush
			 *    the new space cache info onto disk.
			 *    the new space cache info onto disk.
			 */
			 */
			if (btrfs_test_opt(root, SPACE_CACHE))
			if (btrfs_test_opt(root->fs_info, SPACE_CACHE))
				cache->disk_cache_state = BTRFS_DC_CLEAR;
				cache->disk_cache_state = BTRFS_DC_CLEAR;
		}
		}


@@ -10641,7 +10641,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
	spin_lock(&block_group->space_info->lock);
	spin_lock(&block_group->space_info->lock);
	list_del_init(&block_group->ro_list);
	list_del_init(&block_group->ro_list);


	if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
	if (btrfs_test_opt(root->fs_info, ENOSPC_DEBUG)) {
		WARN_ON(block_group->space_info->total_bytes
		WARN_ON(block_group->space_info->total_bytes
			< block_group->key.offset);
			< block_group->key.offset);
		WARN_ON(block_group->space_info->bytes_readonly
		WARN_ON(block_group->space_info->bytes_readonly
@@ -10909,7 +10909,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
		spin_unlock(&space_info->lock);
		spin_unlock(&space_info->lock);


		/* DISCARD can flip during remount */
		/* DISCARD can flip during remount */
		trimming = btrfs_test_opt(root, DISCARD);
		trimming = btrfs_test_opt(root->fs_info, DISCARD);


		/* Implicit trim during transaction commit. */
		/* Implicit trim during transaction commit. */
		if (trimming)
		if (trimming)
+1 −1
Original line number Original line Diff line number Diff line
@@ -132,7 +132,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode,


static inline int __need_auto_defrag(struct btrfs_root *root)
static inline int __need_auto_defrag(struct btrfs_root *root)
{
{
	if (!btrfs_test_opt(root, AUTO_DEFRAG))
	if (!btrfs_test_opt(root->fs_info, AUTO_DEFRAG))
		return 0;
		return 0;


	if (btrfs_fs_closing(root->fs_info))
	if (btrfs_fs_closing(root->fs_info))
Loading