@@ -762,8 +762,8 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
762762 return ret ;
763763 }
764764
765- free_extent_state ( cached );
766- extent_clear_unlock_delalloc ( inode , offset , end , NULL , clear_flags ,
765+ extent_clear_unlock_delalloc ( inode , offset , end , NULL , & cached ,
766+ clear_flags ,
767767 PAGE_UNLOCK | PAGE_START_WRITEBACK |
768768 PAGE_END_WRITEBACK );
769769 return ret ;
@@ -1154,6 +1154,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
11541154 struct btrfs_ordered_extent * ordered ;
11551155 struct btrfs_key ins ;
11561156 struct page * locked_page = NULL ;
1157+ struct extent_state * cached = NULL ;
11571158 struct extent_map * em ;
11581159 int ret = 0 ;
11591160 u64 start = async_extent -> start ;
@@ -1194,7 +1195,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
11941195 goto done ;
11951196 }
11961197
1197- lock_extent (io_tree , start , end , NULL );
1198+ lock_extent (io_tree , start , end , & cached );
11981199
11991200 /* Here we're doing allocation and writeback of the compressed pages */
12001201 em = create_io_em (inode , start ,
@@ -1229,7 +1230,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
12291230
12301231 /* Clear dirty, set writeback and unlock the pages. */
12311232 extent_clear_unlock_delalloc (inode , start , end ,
1232- NULL , EXTENT_LOCKED | EXTENT_DELALLOC ,
1233+ NULL , & cached , EXTENT_LOCKED | EXTENT_DELALLOC ,
12331234 PAGE_UNLOCK | PAGE_START_WRITEBACK );
12341235 btrfs_submit_compressed_write (ordered ,
12351236 async_extent -> folios , /* compressed_folios */
@@ -1247,7 +1248,8 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
12471248 btrfs_free_reserved_extent (fs_info , ins .objectid , ins .offset , 1 );
12481249 mapping_set_error (inode -> vfs_inode .i_mapping , - EIO );
12491250 extent_clear_unlock_delalloc (inode , start , end ,
1250- NULL , EXTENT_LOCKED | EXTENT_DELALLOC |
1251+ NULL , & cached ,
1252+ EXTENT_LOCKED | EXTENT_DELALLOC |
12511253 EXTENT_DELALLOC_NEW |
12521254 EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING ,
12531255 PAGE_UNLOCK | PAGE_START_WRITEBACK |
@@ -1329,6 +1331,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13291331{
13301332 struct btrfs_root * root = inode -> root ;
13311333 struct btrfs_fs_info * fs_info = root -> fs_info ;
1334+ struct extent_state * cached = NULL ;
13321335 u64 alloc_hint = 0 ;
13331336 u64 orig_start = start ;
13341337 u64 num_bytes ;
@@ -1429,7 +1432,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14291432
14301433 ram_size = ins .offset ;
14311434
1432- lock_extent (& inode -> io_tree , start , start + ram_size - 1 , NULL );
1435+ lock_extent (& inode -> io_tree , start , start + ram_size - 1 ,
1436+ & cached );
14331437
14341438 em = create_io_em (inode , start , ins .offset , /* len */
14351439 start , /* orig_start */
@@ -1441,7 +1445,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14411445 BTRFS_ORDERED_REGULAR /* type */ );
14421446 if (IS_ERR (em )) {
14431447 unlock_extent (& inode -> io_tree , start ,
1444- start + ram_size - 1 , NULL );
1448+ start + ram_size - 1 , & cached );
14451449 ret = PTR_ERR (em );
14461450 goto out_reserve ;
14471451 }
@@ -1453,7 +1457,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14531457 BTRFS_COMPRESS_NONE );
14541458 if (IS_ERR (ordered )) {
14551459 unlock_extent (& inode -> io_tree , start ,
1456- start + ram_size - 1 , NULL );
1460+ start + ram_size - 1 , & cached );
14571461 ret = PTR_ERR (ordered );
14581462 goto out_drop_extent_cache ;
14591463 }
@@ -1493,7 +1497,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14931497 page_ops |= PAGE_SET_ORDERED ;
14941498
14951499 extent_clear_unlock_delalloc (inode , start , start + ram_size - 1 ,
1496- locked_page ,
1500+ locked_page , & cached ,
14971501 EXTENT_LOCKED | EXTENT_DELALLOC ,
14981502 page_ops );
14991503 if (num_bytes < cur_alloc_size )
@@ -1552,7 +1556,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
15521556 if (!locked_page )
15531557 mapping_set_error (inode -> vfs_inode .i_mapping , ret );
15541558 extent_clear_unlock_delalloc (inode , orig_start , start - 1 ,
1555- locked_page , 0 , page_ops );
1559+ locked_page , NULL , 0 , page_ops );
15561560 }
15571561
15581562 /*
@@ -1575,7 +1579,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
15751579 if (extent_reserved ) {
15761580 extent_clear_unlock_delalloc (inode , start ,
15771581 start + cur_alloc_size - 1 ,
1578- locked_page ,
1582+ locked_page , & cached ,
15791583 clear_bits ,
15801584 page_ops );
15811585 start += cur_alloc_size ;
@@ -1590,7 +1594,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
15901594 if (start < end ) {
15911595 clear_bits |= EXTENT_CLEAR_DATA_RESV ;
15921596 extent_clear_unlock_delalloc (inode , start , end , locked_page ,
1593- clear_bits , page_ops );
1597+ & cached , clear_bits , page_ops );
15941598 }
15951599 return ret ;
15961600}
@@ -2206,11 +2210,10 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
22062210 btrfs_put_ordered_extent (ordered );
22072211
22082212 extent_clear_unlock_delalloc (inode , cur_offset , nocow_end ,
2209- locked_page , EXTENT_LOCKED |
2210- EXTENT_DELALLOC |
2213+ locked_page , & cached_state ,
2214+ EXTENT_LOCKED | EXTENT_DELALLOC |
22112215 EXTENT_CLEAR_DATA_RESV ,
22122216 PAGE_UNLOCK | PAGE_SET_ORDERED );
2213- free_extent_state (cached_state );
22142217
22152218 cur_offset = extent_end ;
22162219
@@ -2252,10 +2255,13 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
22522255 * we're not locked at this point.
22532256 */
22542257 if (cur_offset < end ) {
2255- lock_extent (& inode -> io_tree , cur_offset , end , NULL );
2258+ struct extent_state * cached = NULL ;
2259+
2260+ lock_extent (& inode -> io_tree , cur_offset , end , & cached );
22562261 extent_clear_unlock_delalloc (inode , cur_offset , end ,
2257- locked_page , EXTENT_LOCKED |
2258- EXTENT_DELALLOC | EXTENT_DEFRAG |
2262+ locked_page , & cached ,
2263+ EXTENT_LOCKED | EXTENT_DELALLOC |
2264+ EXTENT_DEFRAG |
22592265 EXTENT_DO_ACCOUNTING , PAGE_UNLOCK |
22602266 PAGE_START_WRITEBACK |
22612267 PAGE_END_WRITEBACK );
0 commit comments