summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2024-04-03 13:53:57 -0400
committerDavid Sterba <dsterba@suse.com>2024-05-07 21:31:10 +0200
commit0ab540995ae049f1536260b0f6124483e685b593 (patch)
treeb1f661d22b5a1a3960f4ffcf9b1e1b536de73108 /fs
parenta0766d8f35d8c7b3df319ccfd6e85b4a07c1f0bd (diff)
downloadlinux-stable-0ab540995ae049f1536260b0f6124483e685b593.tar.gz
linux-stable-0ab540995ae049f1536260b0f6124483e685b593.tar.bz2
linux-stable-0ab540995ae049f1536260b0f6124483e685b593.zip
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: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/inode.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7f431151af94..d6bad01c0cdf 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
struct folio *compressed_folio,
bool update_i_size)
{
+ struct extent_state *cached = NULL;
unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED;
u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
int ret;
+ lock_extent(&inode->io_tree, offset, end, &cached);
ret = __cow_file_range_inline(inode, offset, size, compressed_size,
compress_type, compressed_folio,
update_i_size);
- if (ret > 0)
+ if (ret > 0) {
+ unlock_extent(&inode->io_tree, offset, end, &cached);
return ret;
+ }
+ free_extent_state(cached);
extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags,
PAGE_UNLOCK | PAGE_START_WRITEBACK |
PAGE_END_WRITEBACK);
@@ -1028,7 +1033,6 @@ again:
* Check cow_file_range() for why we don't even try to create inline
* extent for the subpage case.
*/
- lock_extent(&inode->io_tree, start, end, NULL);
if (total_in < actual_end)
ret = cow_file_range_inline(inode, start, end, 0,
BTRFS_COMPRESS_NONE, NULL, false);
@@ -1040,7 +1044,6 @@ again:
mapping_set_error(mapping, -EIO);
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
@@ -1336,8 +1339,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
bool extent_reserved = false;
int ret = 0;
- lock_extent(&inode->io_tree, start, end, NULL);
-
if (btrfs_is_free_space_inode(inode)) {
ret = -EINVAL;
goto out_unlock;
@@ -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);
/*