Skip to content

Commit 0ab5409

Browse files
josefbacikkdave
authored andcommitted
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>
1 parent a0766d8 commit 0ab5409

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fs/btrfs/inode.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
744744
struct folio *compressed_folio,
745745
bool update_i_size)
746746
{
747+
struct extent_state *cached = NULL;
747748
unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
748749
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED;
749750
u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
750751
int ret;
751752

753+
lock_extent(&inode->io_tree, offset, end, &cached);
752754
ret = __cow_file_range_inline(inode, offset, size, compressed_size,
753755
compress_type, compressed_folio,
754756
update_i_size);
755-
if (ret > 0)
757+
if (ret > 0) {
758+
unlock_extent(&inode->io_tree, offset, end, &cached);
756759
return ret;
760+
}
757761

762+
free_extent_state(cached);
758763
extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags,
759764
PAGE_UNLOCK | PAGE_START_WRITEBACK |
760765
PAGE_END_WRITEBACK);
@@ -1028,7 +1033,6 @@ static void compress_file_range(struct btrfs_work *work)
10281033
* Check cow_file_range() for why we don't even try to create inline
10291034
* extent for the subpage case.
10301035
*/
1031-
lock_extent(&inode->io_tree, start, end, NULL);
10321036
if (total_in < actual_end)
10331037
ret = cow_file_range_inline(inode, start, end, 0,
10341038
BTRFS_COMPRESS_NONE, NULL, false);
@@ -1040,7 +1044,6 @@ static void compress_file_range(struct btrfs_work *work)
10401044
mapping_set_error(mapping, -EIO);
10411045
goto free_pages;
10421046
}
1043-
unlock_extent(&inode->io_tree, start, end, NULL);
10441047

10451048
/*
10461049
* 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,
13361339
bool extent_reserved = false;
13371340
int ret = 0;
13381341

1339-
lock_extent(&inode->io_tree, start, end, NULL);
1340-
13411342
if (btrfs_is_free_space_inode(inode)) {
13421343
ret = -EINVAL;
13431344
goto out_unlock;
@@ -1367,6 +1368,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13671368
}
13681369
}
13691370

1371+
lock_extent(&inode->io_tree, start, end, NULL);
1372+
13701373
alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);
13711374

13721375
/*

0 commit comments

Comments
 (0)