btrfs: simplify boolean argument for btrfs_inc_ref()/btrfs_dec_ref()

Replace open-coded if/else blocks with the boolean directly and introduce
local const bool variables, making the code shorter and easier to read.

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Sun YangKai 2025-11-22 14:00:44 +08:00 committed by David Sterba
parent 8bfee251b7
commit a5eb902436
2 changed files with 18 additions and 38 deletions

View File

@ -249,6 +249,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
int ret = 0;
int level;
struct btrfs_disk_key disk_key;
const bool is_reloc_root = (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID);
u64 reloc_src_root = 0;
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
@ -262,7 +263,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
else
btrfs_node_key(buf, &disk_key, 0);
if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
if (is_reloc_root)
reloc_src_root = btrfs_header_owner(buf);
cow = btrfs_alloc_tree_block(trans, root, 0, new_root_objectid,
&disk_key, level, buf->start, 0,
@ -276,7 +277,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV);
btrfs_clear_header_flag(cow, BTRFS_HEADER_FLAG_WRITTEN |
BTRFS_HEADER_FLAG_RELOC);
if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
if (is_reloc_root)
btrfs_set_header_flag(cow, BTRFS_HEADER_FLAG_RELOC);
else
btrfs_set_header_owner(cow, new_root_objectid);
@ -291,16 +292,9 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
return ret;
}
if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
ret = btrfs_inc_ref(trans, root, cow, true);
if (unlikely(ret))
btrfs_abort_transaction(trans, ret);
} else {
ret = btrfs_inc_ref(trans, root, cow, false);
if (unlikely(ret))
btrfs_abort_transaction(trans, ret);
}
if (ret) {
ret = btrfs_inc_ref(trans, root, cow, is_reloc_root);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
btrfs_tree_unlock(cow);
free_extent_buffer(cow);
return ret;
@ -362,6 +356,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
u64 owner;
u64 flags;
int ret;
const bool is_reloc_root = (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID);
/*
* Backrefs update rules:
@ -397,8 +392,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
}
} else {
refs = 1;
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID ||
btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
if (is_reloc_root || btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
flags = BTRFS_BLOCK_FLAG_FULL_BACKREF;
else
flags = 0;
@ -417,14 +411,13 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
}
if (refs > 1) {
if ((owner == btrfs_root_id(root) ||
btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) &&
if ((owner == btrfs_root_id(root) || is_reloc_root) &&
!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) {
ret = btrfs_inc_ref(trans, root, buf, true);
if (ret)
return ret;
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) {
if (is_reloc_root) {
ret = btrfs_dec_ref(trans, root, buf, false);
if (ret)
return ret;
@ -437,20 +430,13 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
if (ret)
return ret;
} else {
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
ret = btrfs_inc_ref(trans, root, cow, true);
else
ret = btrfs_inc_ref(trans, root, cow, false);
ret = btrfs_inc_ref(trans, root, cow, is_reloc_root);
if (ret)
return ret;
}
} else {
if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
ret = btrfs_inc_ref(trans, root, cow, true);
else
ret = btrfs_inc_ref(trans, root, cow, false);
ret = btrfs_inc_ref(trans, root, cow, is_reloc_root);
if (ret)
return ret;
ret = btrfs_dec_ref(trans, root, buf, true);

View File

@ -5863,18 +5863,12 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
if (wc->refs[level] == 1) {
if (level == 0) {
if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
ret = btrfs_dec_ref(trans, root, eb, true);
if (ret) {
btrfs_abort_transaction(trans, ret);
return ret;
}
} else {
ret = btrfs_dec_ref(trans, root, eb, false);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
return ret;
}
const bool full_backref = (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF);
ret = btrfs_dec_ref(trans, root, eb, full_backref);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
return ret;
}
if (btrfs_is_fstree(btrfs_root_id(root))) {
ret = btrfs_qgroup_trace_leaf_items(trans, eb);