@@ -1336,6 +1336,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
1336
1336
bool extent_reserved = false;
1337
1337
int ret = 0 ;
1338
1338
1339
+ lock_extent (& inode -> io_tree , start , end , NULL );
1340
+
1339
1341
if (btrfs_is_free_space_inode (inode )) {
1340
1342
ret = - EINVAL ;
1341
1343
goto out_unlock ;
@@ -1722,8 +1724,6 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
1722
1724
u64 done_offset = end ;
1723
1725
int ret ;
1724
1726
1725
- lock_extent (& inode -> io_tree , start , end , NULL );
1726
-
1727
1727
while (start <= end ) {
1728
1728
ret = cow_file_range (inode , locked_page , start , end , & done_offset ,
1729
1729
true, false);
@@ -1744,12 +1744,11 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
1744
1744
const bool is_reloc_ino = btrfs_is_data_reloc_root (inode -> root );
1745
1745
const u64 range_bytes = end + 1 - start ;
1746
1746
struct extent_io_tree * io_tree = & inode -> io_tree ;
1747
+ struct extent_state * cached_state = NULL ;
1747
1748
u64 range_start = start ;
1748
1749
u64 count ;
1749
1750
int ret ;
1750
1751
1751
- lock_extent (io_tree , start , end , NULL );
1752
-
1753
1752
/*
1754
1753
* If EXTENT_NORESERVE is set it means that when the buffered write was
1755
1754
* 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
1781
* group that contains that extent to RO mode and therefore force COW
1783
1782
* when starting writeback.
1784
1783
*/
1784
+ lock_extent (io_tree , start , end , & cached_state );
1785
1785
count = count_range_bits (io_tree , & range_start , end , range_bytes ,
1786
1786
EXTENT_NORESERVE , 0 , NULL );
1787
1787
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
1800
clear_extent_bit (io_tree , start , end , EXTENT_NORESERVE ,
1801
1801
NULL );
1802
1802
}
1803
+ unlock_extent (io_tree , start , end , & cached_state );
1803
1804
1804
1805
/*
1805
1806
* 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
2283
run_delalloc_compressed (inode , locked_page , start , end , wbc ))
2283
2284
return 1 ;
2284
2285
2285
- if (zoned ) {
2286
+ if (zoned )
2286
2287
ret = run_delalloc_cow (inode , locked_page , start , end , wbc ,
2287
2288
true);
2288
- } else {
2289
- lock_extent (& inode -> io_tree , start , end , NULL );
2289
+ else
2290
2290
ret = cow_file_range (inode , locked_page , start , end , NULL ,
2291
2291
false, false);
2292
- }
2293
2292
2294
2293
out :
2295
2294
if (ret < 0 )
0 commit comments