Skip to content

Commit 82028e0

Browse files
adam900710kdave
authored andcommitted
btrfs: inode: cleanup the log-tree exceptions in btrfs_truncate_inode_items()
There are a lot of root owner checks in btrfs_truncate_inode_items() like: if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) || root == fs_info->tree_root) But considering that, only these trees can have INODE_ITEMs: - tree root (for v1 space cache) - subvolume trees - tree reloc trees - data reloc tree - log trees And since subvolume/tree reloc/data reloc trees all have SHAREABLE bit, and we're checking tree root manually, so above check is just excluding log trees. This patch will replace two of such checks to a simpler one: if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) This would merge btrfs_drop_extent_cache() and lock_extent_bits() call into the same if branch. Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 92a7cc4 commit 82028e0

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

fs/btrfs/inode.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,20 +4113,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
41134113
return -ENOMEM;
41144114
path->reada = READA_BACK;
41154115

4116-
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
4116+
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
41174117
lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1,
41184118
&cached_state);
41194119

4120-
/*
4121-
* We want to drop from the next block forward in case this new size is
4122-
* not block aligned since we will be keeping the last block of the
4123-
* extent just the way it is.
4124-
*/
4125-
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
4126-
root == fs_info->tree_root)
4120+
/*
4121+
* We want to drop from the next block forward in case this
4122+
* new size is not block aligned since we will be keeping the
4123+
* last block of the extent just the way it is.
4124+
*/
41274125
btrfs_drop_extent_cache(BTRFS_I(inode), ALIGN(new_size,
41284126
fs_info->sectorsize),
41294127
(u64)-1, 0);
4128+
}
41304129

41314130
/*
41324131
* This function is also used to drop the items in the log tree before
@@ -4327,8 +4326,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
43274326
should_throttle = false;
43284327

43294328
if (found_extent &&
4330-
(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
4331-
root == fs_info->tree_root)) {
4329+
root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
43324330
struct btrfs_ref ref = { 0 };
43334331

43344332
bytes_deleted += extent_num_bytes;

0 commit comments

Comments
 (0)