Commit a0766d8f authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: push extent lock into cow_file_range

Now that cow_file_range is the only function that is called with the
range locked, push this call into cow_file_range so we can further
narrow the scope.
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 00009d7b
...@@ -1336,6 +1336,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1336,6 +1336,8 @@ 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;
...@@ -1722,8 +1724,6 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode, ...@@ -1722,8 +1724,6 @@ 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);
...@@ -1744,12 +1744,11 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, ...@@ -1744,12 +1744,11 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
const bool is_reloc_ino = btrfs_is_data_reloc_root(inode->root); const bool is_reloc_ino = btrfs_is_data_reloc_root(inode->root);
const u64 range_bytes = end + 1 - start; const u64 range_bytes = end + 1 - start;
struct extent_io_tree *io_tree = &inode->io_tree; struct extent_io_tree *io_tree = &inode->io_tree;
struct extent_state *cached_state = NULL;
u64 range_start = start; u64 range_start = start;
u64 count; u64 count;
int ret; int ret;
lock_extent(io_tree, start, end, NULL);
/* /*
* If EXTENT_NORESERVE is set it means that when the buffered write was * If EXTENT_NORESERVE is set it means that when the buffered write was
* made we had not enough available data space and therefore we did not * made we had not enough available data space and therefore we did not
...@@ -1782,6 +1781,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, ...@@ -1782,6 +1781,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
* group that contains that extent to RO mode and therefore force COW * group that contains that extent to RO mode and therefore force COW
* when starting writeback. * when starting writeback.
*/ */
lock_extent(io_tree, start, end, &cached_state);
count = count_range_bits(io_tree, &range_start, end, range_bytes, count = count_range_bits(io_tree, &range_start, end, range_bytes,
EXTENT_NORESERVE, 0, NULL); EXTENT_NORESERVE, 0, NULL);
if (count > 0 || is_space_ino || is_reloc_ino) { if (count > 0 || is_space_ino || is_reloc_ino) {
...@@ -1800,6 +1800,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, ...@@ -1800,6 +1800,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
clear_extent_bit(io_tree, start, end, EXTENT_NORESERVE, clear_extent_bit(io_tree, start, end, EXTENT_NORESERVE,
NULL); NULL);
} }
unlock_extent(io_tree, start, end, &cached_state);
/* /*
* Don't try to create inline extents, as a mix of inline extent that * Don't try to create inline extents, as a mix of inline extent that
...@@ -2282,14 +2283,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page ...@@ -2282,14 +2283,12 @@ 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) { 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)
......
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