Commit fc28b25e authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba
Browse files

btrfs: stop accessing ->csum_root directly



We are going to have multiple csum roots in the future, so convert all
users of ->csum_root to btrfs_csum_root() and rename ->csum_root to
->_csum_root so we can easily find remaining users in the future.

Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 056c8311
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -353,6 +353,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
	struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
	struct btrfs_space_info *sinfo = block_rsv->space_info;
	struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
	struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0);
	u64 num_bytes;
	unsigned min_items;

@@ -362,7 +363,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
	 * it to a minimal amount for safety.
	 */
	num_bytes = btrfs_root_used(&extent_root->root_item) +
		btrfs_root_used(&fs_info->csum_root->root_item) +
		btrfs_root_used(&csum_root->root_item) +
		btrfs_root_used(&fs_info->tree_root->root_item);

	/*
@@ -476,8 +477,9 @@ static struct btrfs_block_rsv *get_block_rsv(
	struct btrfs_block_rsv *block_rsv = NULL;

	if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
	    (root == fs_info->csum_root && trans->adding_csums) ||
	    (root == fs_info->uuid_root))
	    (root == fs_info->uuid_root) ||
	    (trans->adding_csums &&
	     root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID))
		block_rsv = trans->block_rsv;

	if (!block_rsv)
+1 −1
Original line number Diff line number Diff line
@@ -628,7 +628,7 @@ struct btrfs_fs_info {
	struct btrfs_root *chunk_root;
	struct btrfs_root *dev_root;
	struct btrfs_root *fs_root;
	struct btrfs_root *csum_root;
	struct btrfs_root *_csum_root;
	struct btrfs_root *quota_root;
	struct btrfs_root *uuid_root;
	struct btrfs_root *free_space_root;
+8 −7
Original line number Diff line number Diff line
@@ -1563,7 +1563,7 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
	if (objectid == BTRFS_DEV_TREE_OBJECTID)
		return btrfs_grab_root(fs_info->dev_root);
	if (objectid == BTRFS_CSUM_TREE_OBJECTID)
		return btrfs_grab_root(fs_info->csum_root);
		return btrfs_grab_root(fs_info->_csum_root);
	if (objectid == BTRFS_QUOTA_TREE_OBJECTID)
		return btrfs_grab_root(fs_info->quota_root) ?
			fs_info->quota_root : ERR_PTR(-ENOENT);
@@ -1634,7 +1634,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
	btrfs_put_root(fs_info->tree_root);
	btrfs_put_root(fs_info->chunk_root);
	btrfs_put_root(fs_info->dev_root);
	btrfs_put_root(fs_info->csum_root);
	btrfs_put_root(fs_info->_csum_root);
	btrfs_put_root(fs_info->quota_root);
	btrfs_put_root(fs_info->uuid_root);
	btrfs_put_root(fs_info->free_space_root);
@@ -2009,6 +2009,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
	const int next_backup = info->backup_root_index;
	struct btrfs_root_backup *root_backup;
	struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
	struct btrfs_root *csum_root = btrfs_csum_root(info, 0);

	root_backup = info->super_for_commit->super_roots + next_backup;

@@ -2058,11 +2059,11 @@ static void backup_super_roots(struct btrfs_fs_info *info)
	btrfs_set_backup_dev_root_level(root_backup,
				       btrfs_header_level(info->dev_root->node));

	btrfs_set_backup_csum_root(root_backup, info->csum_root->node->start);
	btrfs_set_backup_csum_root(root_backup, csum_root->node->start);
	btrfs_set_backup_csum_root_gen(root_backup,
			       btrfs_header_generation(info->csum_root->node));
				       btrfs_header_generation(csum_root->node));
	btrfs_set_backup_csum_root_level(root_backup,
			       btrfs_header_level(info->csum_root->node));
					 btrfs_header_level(csum_root->node));

	btrfs_set_backup_total_bytes(root_backup,
			     btrfs_super_total_bytes(info->super_copy));
@@ -2168,7 +2169,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)

	free_root_extent_buffers(info->dev_root);
	free_root_extent_buffers(info->_extent_root);
	free_root_extent_buffers(info->csum_root);
	free_root_extent_buffers(info->_csum_root);
	free_root_extent_buffers(info->quota_root);
	free_root_extent_buffers(info->uuid_root);
	free_root_extent_buffers(info->fs_root);
@@ -2488,7 +2489,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
			}
		} else {
			set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
			fs_info->csum_root = root;
			fs_info->_csum_root = root;
		}
	} else {
		set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
+6 −0
Original line number Diff line number Diff line
@@ -109,6 +109,12 @@ static inline struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info
	return fs_info->_extent_root;
}

static inline struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info,
						 u64 bytenr)
{
	return fs_info->_csum_root;
}

static inline struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info)
{
	return btrfs_extent_root(fs_info, 0);
+8 −3
Original line number Diff line number Diff line
@@ -1851,8 +1851,11 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
	if (head->must_insert_reserved) {
		btrfs_pin_extent(trans, head->bytenr, head->num_bytes, 1);
		if (head->is_data) {
			ret = btrfs_del_csums(trans, fs_info->csum_root,
					      head->bytenr, head->num_bytes);
			struct btrfs_root *csum_root;

			csum_root = btrfs_csum_root(fs_info, head->bytenr);
			ret = btrfs_del_csums(trans, csum_root, head->bytenr,
					      head->num_bytes);
		}
	}

@@ -3188,7 +3191,9 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
		btrfs_release_path(path);

		if (is_data) {
			ret = btrfs_del_csums(trans, info->csum_root, bytenr,
			struct btrfs_root *csum_root;
			csum_root = btrfs_csum_root(info, bytenr);
			ret = btrfs_del_csums(trans, csum_root, bytenr,
					      num_bytes);
			if (ret) {
				btrfs_abort_transaction(trans, ret);
Loading