Commit 0ab54099 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: push lock_extent into cow_file_range_inline

Now that we've pushed the lock_extent() into cow_file_range() we can
push the extent locking into cow_file_range_inline() and move the
lock_extent in cow_file_range() to after we call
cow_file_range_inline().
Reviewed-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a0766d8f
...@@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, ...@@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
struct folio *compressed_folio, struct folio *compressed_folio,
bool update_i_size) bool update_i_size)
{ {
struct extent_state *cached = NULL;
unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED; EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED;
u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
int ret; int ret;
lock_extent(&inode->io_tree, offset, end, &cached);
ret = __cow_file_range_inline(inode, offset, size, compressed_size, ret = __cow_file_range_inline(inode, offset, size, compressed_size,
compress_type, compressed_folio, compress_type, compressed_folio,
update_i_size); update_i_size);
if (ret > 0) if (ret > 0) {
unlock_extent(&inode->io_tree, offset, end, &cached);
return ret; return ret;
}
free_extent_state(cached);
extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags, extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags,
PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_UNLOCK | PAGE_START_WRITEBACK |
PAGE_END_WRITEBACK); PAGE_END_WRITEBACK);
...@@ -1028,7 +1033,6 @@ static void compress_file_range(struct btrfs_work *work) ...@@ -1028,7 +1033,6 @@ static void compress_file_range(struct btrfs_work *work)
* Check cow_file_range() for why we don't even try to create inline * Check cow_file_range() for why we don't even try to create inline
* extent for the subpage case. * extent for the subpage case.
*/ */
lock_extent(&inode->io_tree, start, end, NULL);
if (total_in < actual_end) if (total_in < actual_end)
ret = cow_file_range_inline(inode, start, end, 0, ret = cow_file_range_inline(inode, start, end, 0,
BTRFS_COMPRESS_NONE, NULL, false); BTRFS_COMPRESS_NONE, NULL, false);
...@@ -1040,7 +1044,6 @@ static void compress_file_range(struct btrfs_work *work) ...@@ -1040,7 +1044,6 @@ static void compress_file_range(struct btrfs_work *work)
mapping_set_error(mapping, -EIO); mapping_set_error(mapping, -EIO);
goto free_pages; goto free_pages;
} }
unlock_extent(&inode->io_tree, start, end, NULL);
/* /*
* We aren't doing an inline extent. Round the compressed size up to a * We aren't doing an inline extent. Round the compressed size up to a
...@@ -1336,8 +1339,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1336,8 +1339,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
bool extent_reserved = false; bool extent_reserved = false;
int ret = 0; int ret = 0;
lock_extent(&inode->io_tree, start, end, NULL);
if (btrfs_is_free_space_inode(inode)) { if (btrfs_is_free_space_inode(inode)) {
ret = -EINVAL; ret = -EINVAL;
goto out_unlock; goto out_unlock;
...@@ -1367,6 +1368,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1367,6 +1368,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
} }
} }
lock_extent(&inode->io_tree, start, end, NULL);
alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); alloc_hint = get_extent_allocation_hint(inode, start, 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