@@ -1336,6 +1336,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13361336 bool extent_reserved = false;
13371337 int ret = 0 ;
13381338
1339+ lock_extent (& inode -> io_tree , start , end , NULL );
1340+
13391341 if (btrfs_is_free_space_inode (inode )) {
13401342 ret = - EINVAL ;
13411343 goto out_unlock ;
@@ -1722,8 +1724,6 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
17221724 u64 done_offset = end ;
17231725 int ret ;
17241726
1725- lock_extent (& inode -> io_tree , start , end , NULL );
1726-
17271727 while (start <= end ) {
17281728 ret = cow_file_range (inode , locked_page , start , end , & done_offset ,
17291729 true, false);
@@ -1744,12 +1744,11 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
17441744 const bool is_reloc_ino = btrfs_is_data_reloc_root (inode -> root );
17451745 const u64 range_bytes = end + 1 - start ;
17461746 struct extent_io_tree * io_tree = & inode -> io_tree ;
1747+ struct extent_state * cached_state = NULL ;
17471748 u64 range_start = start ;
17481749 u64 count ;
17491750 int ret ;
17501751
1751- lock_extent (io_tree , start , end , NULL );
1752-
17531752 /*
17541753 * If EXTENT_NORESERVE is set it means that when the buffered write was
17551754 * 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,
17821781 * group that contains that extent to RO mode and therefore force COW
17831782 * when starting writeback.
17841783 */
1784+ lock_extent (io_tree , start , end , & cached_state );
17851785 count = count_range_bits (io_tree , & range_start , end , range_bytes ,
17861786 EXTENT_NORESERVE , 0 , NULL );
17871787 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,
18001800 clear_extent_bit (io_tree , start , end , EXTENT_NORESERVE ,
18011801 NULL );
18021802 }
1803+ unlock_extent (io_tree , start , end , & cached_state );
18031804
18041805 /*
18051806 * 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
22822283 run_delalloc_compressed (inode , locked_page , start , end , wbc ))
22832284 return 1 ;
22842285
2285- if (zoned ) {
2286+ if (zoned )
22862287 ret = run_delalloc_cow (inode , locked_page , start , end , wbc ,
22872288 true);
2288- } else {
2289- lock_extent (& inode -> io_tree , start , end , NULL );
2289+ else
22902290 ret = cow_file_range (inode , locked_page , start , end , NULL ,
22912291 false, false);
2292- }
22932292
22942293out :
22952294 if (ret < 0 )
0 commit comments