Commit 82028e0a authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

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: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 92a7cc42
...@@ -4113,20 +4113,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, ...@@ -4113,20 +4113,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
return -ENOMEM; return -ENOMEM;
path->reada = READA_BACK; path->reada = READA_BACK;
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1,
&cached_state); &cached_state);
/* /*
* We want to drop from the next block forward in case this new size is * We want to drop from the next block forward in case this
* not block aligned since we will be keeping the last block of the * new size is not block aligned since we will be keeping the
* extent just the way it is. * last block of the extent just the way it is.
*/ */
if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
root == fs_info->tree_root)
btrfs_drop_extent_cache(BTRFS_I(inode), ALIGN(new_size, btrfs_drop_extent_cache(BTRFS_I(inode), ALIGN(new_size,
fs_info->sectorsize), fs_info->sectorsize),
(u64)-1, 0); (u64)-1, 0);
}
/* /*
* This function is also used to drop the items in the log tree before * 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, ...@@ -4327,8 +4326,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
should_throttle = false; should_throttle = false;
if (found_extent && if (found_extent &&
(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) || root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
root == fs_info->tree_root)) {
struct btrfs_ref ref = { 0 }; struct btrfs_ref ref = { 0 };
bytes_deleted += extent_num_bytes; bytes_deleted += extent_num_bytes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment