btrfs: push extent lock into run_delalloc_cow

This is used by zoned but also as the fallback for uncompressed extents
when we fail to compress the ranges.  Push the extent lock into
run_dealloc_cow(), and adjust the compression case to take the extent
lock after calling run_delalloc_cow().

Reviewed-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2024-04-03 15:31:17 -04:00 committed by David Sterba
parent 0e128d4e41
commit 00009d7bcb

View file

@ -1167,13 +1167,13 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
if (!(start >= locked_page_end || end <= locked_page_start)) if (!(start >= locked_page_end || end <= locked_page_start))
locked_page = async_chunk->locked_page; locked_page = async_chunk->locked_page;
} }
lock_extent(io_tree, start, end, NULL);
if (async_extent->compress_type == BTRFS_COMPRESS_NONE) { if (async_extent->compress_type == BTRFS_COMPRESS_NONE) {
submit_uncompressed_range(inode, async_extent, locked_page); submit_uncompressed_range(inode, async_extent, locked_page);
goto done; goto done;
} }
lock_extent(io_tree, start, end, NULL);
ret = btrfs_reserve_extent(root, async_extent->ram_size, ret = btrfs_reserve_extent(root, async_extent->ram_size,
async_extent->compressed_size, async_extent->compressed_size,
async_extent->compressed_size, async_extent->compressed_size,
@ -1722,6 +1722,8 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
u64 done_offset = end; u64 done_offset = end;
int ret; int ret;
lock_extent(&inode->io_tree, start, end, NULL);
while (start <= end) { while (start <= end) {
ret = cow_file_range(inode, locked_page, start, end, &done_offset, ret = cow_file_range(inode, locked_page, start, end, &done_offset,
true, false); true, false);
@ -2280,17 +2282,14 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
run_delalloc_compressed(inode, locked_page, start, end, wbc)) run_delalloc_compressed(inode, locked_page, start, end, wbc))
return 1; return 1;
/* if (zoned) {
* We're unlocked by the different fill functions below.
*/
lock_extent(&inode->io_tree, start, end, NULL);
if (zoned)
ret = run_delalloc_cow(inode, locked_page, start, end, wbc, ret = run_delalloc_cow(inode, locked_page, start, end, wbc,
true); true);
else } else {
lock_extent(&inode->io_tree, start, end, NULL);
ret = cow_file_range(inode, locked_page, start, end, NULL, ret = cow_file_range(inode, locked_page, start, end, NULL,
false, false); false, false);
}
out: out:
if (ret < 0) if (ret < 0)