btrfs: use cached_state for btrfs_check_nocow_lock
Now that try_lock_extent() takes a cached_state, plumb the cached_state through btrfs_try_lock_ordered_range() and then use a cached_state in btrfs_check_nocow_lock everywhere to avoid extra tree searches on the extent_io_tree. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
83ae4133ac
commit
632ddfa213
|
@ -1373,6 +1373,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = inode->root->fs_info;
|
struct btrfs_fs_info *fs_info = inode->root->fs_info;
|
||||||
struct btrfs_root *root = inode->root;
|
struct btrfs_root *root = inode->root;
|
||||||
|
struct extent_state *cached_state = NULL;
|
||||||
u64 lockstart, lockend;
|
u64 lockstart, lockend;
|
||||||
u64 num_bytes;
|
u64 num_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1389,12 +1390,14 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
|
||||||
num_bytes = lockend - lockstart + 1;
|
num_bytes = lockend - lockstart + 1;
|
||||||
|
|
||||||
if (nowait) {
|
if (nowait) {
|
||||||
if (!btrfs_try_lock_ordered_range(inode, lockstart, lockend)) {
|
if (!btrfs_try_lock_ordered_range(inode, lockstart, lockend,
|
||||||
|
&cached_state)) {
|
||||||
btrfs_drew_write_unlock(&root->snapshot_lock);
|
btrfs_drew_write_unlock(&root->snapshot_lock);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend, NULL);
|
btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend,
|
||||||
|
&cached_state);
|
||||||
}
|
}
|
||||||
ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
|
ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
|
||||||
NULL, NULL, NULL, nowait, false);
|
NULL, NULL, NULL, nowait, false);
|
||||||
|
@ -1403,7 +1406,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
|
||||||
else
|
else
|
||||||
*write_bytes = min_t(size_t, *write_bytes ,
|
*write_bytes = min_t(size_t, *write_bytes ,
|
||||||
num_bytes - pos + lockstart);
|
num_bytes - pos + lockstart);
|
||||||
unlock_extent(&inode->io_tree, lockstart, lockend, NULL);
|
unlock_extent(&inode->io_tree, lockstart, lockend, &cached_state);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1069,11 +1069,12 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
|
||||||
* Return true if btrfs_lock_ordered_range does not return any extents,
|
* Return true if btrfs_lock_ordered_range does not return any extents,
|
||||||
* otherwise false.
|
* otherwise false.
|
||||||
*/
|
*/
|
||||||
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end)
|
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
|
||||||
|
struct extent_state **cached_state)
|
||||||
{
|
{
|
||||||
struct btrfs_ordered_extent *ordered;
|
struct btrfs_ordered_extent *ordered;
|
||||||
|
|
||||||
if (!try_lock_extent(&inode->io_tree, start, end, NULL))
|
if (!try_lock_extent(&inode->io_tree, start, end, cached_state))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ordered = btrfs_lookup_ordered_range(inode, start, end - start + 1);
|
ordered = btrfs_lookup_ordered_range(inode, start, end - start + 1);
|
||||||
|
@ -1081,7 +1082,7 @@ bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
btrfs_put_ordered_extent(ordered);
|
btrfs_put_ordered_extent(ordered);
|
||||||
unlock_extent(&inode->io_tree, start, end, NULL);
|
unlock_extent(&inode->io_tree, start, end, cached_state);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,8 @@ void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, u64 nr,
|
||||||
void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
|
void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
|
||||||
u64 end,
|
u64 end,
|
||||||
struct extent_state **cached_state);
|
struct extent_state **cached_state);
|
||||||
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end);
|
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
|
||||||
|
struct extent_state **cached_state);
|
||||||
int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
|
int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
|
||||||
u64 post);
|
u64 post);
|
||||||
int __init ordered_data_init(void);
|
int __init ordered_data_init(void);
|
||||||
|
|
Loading…
Reference in New Issue