mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 00:52:01 +00:00
btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes()
Since add_pinned_bytes() only needs to know if the extent is metadata and if it's a chunk tree extent, btrfs_ref is a perfect match for it, as we don't need various owner/level trick to determine extent type. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
8a5040f7d9
commit
ddf30cf03f
@ -756,14 +756,15 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void add_pinned_bytes(struct btrfs_fs_info *fs_info, s64 num_bytes,
|
||||
bool metadata, u64 root_objectid)
|
||||
static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_ref *ref)
|
||||
{
|
||||
struct btrfs_space_info *space_info;
|
||||
s64 num_bytes = -ref->len;
|
||||
u64 flags;
|
||||
|
||||
if (metadata) {
|
||||
if (root_objectid == BTRFS_CHUNK_TREE_OBJECTID)
|
||||
if (ref->type == BTRFS_REF_METADATA) {
|
||||
if (ref->tree_ref.root == BTRFS_CHUNK_TREE_OBJECTID)
|
||||
flags = BTRFS_BLOCK_GROUP_SYSTEM;
|
||||
else
|
||||
flags = BTRFS_BLOCK_GROUP_METADATA;
|
||||
@ -2069,11 +2070,8 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
|
||||
|
||||
btrfs_ref_tree_mod(fs_info, &generic_ref);
|
||||
|
||||
if (ret == 0 && old_ref_mod < 0 && new_ref_mod >= 0) {
|
||||
bool metadata = owner < BTRFS_FIRST_FREE_OBJECTID;
|
||||
|
||||
add_pinned_bytes(fs_info, -num_bytes, metadata, root_objectid);
|
||||
}
|
||||
if (ret == 0 && old_ref_mod < 0 && new_ref_mod >= 0)
|
||||
add_pinned_bytes(fs_info, &generic_ref);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -7221,8 +7219,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
|
||||
}
|
||||
out:
|
||||
if (pin)
|
||||
add_pinned_bytes(fs_info, buf->len, true,
|
||||
root->root_key.objectid);
|
||||
add_pinned_bytes(fs_info, &generic_ref);
|
||||
|
||||
if (last_ref) {
|
||||
/*
|
||||
@ -7273,11 +7270,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
|
||||
if (root_objectid != BTRFS_TREE_LOG_OBJECTID)
|
||||
btrfs_ref_tree_mod(fs_info, &generic_ref);
|
||||
|
||||
if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0) {
|
||||
bool metadata = owner < BTRFS_FIRST_FREE_OBJECTID;
|
||||
|
||||
add_pinned_bytes(fs_info, num_bytes, metadata, root_objectid);
|
||||
}
|
||||
if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0)
|
||||
add_pinned_bytes(fs_info, &generic_ref);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user