@@ -523,8 +523,6 @@ static void end_bbio_data_read(struct btrfs_bio *bbio)
523523 u64 end ;
524524 u32 len ;
525525
526- /* For now only order 0 folios are supported for data. */
527- ASSERT (folio_order (folio ) == 0 );
528526 btrfs_debug (fs_info ,
529527 "%s: bi_sector=%llu, err=%d, mirror=%u" ,
530528 __func__ , bio -> bi_iter .bi_sector , bio -> bi_status ,
@@ -552,7 +550,6 @@ static void end_bbio_data_read(struct btrfs_bio *bbio)
552550
553551 if (likely (uptodate )) {
554552 loff_t i_size = i_size_read (inode );
555- pgoff_t end_index = i_size >> folio_shift (folio );
556553
557554 /*
558555 * Zero out the remaining part if this range straddles
@@ -561,9 +558,11 @@ static void end_bbio_data_read(struct btrfs_bio *bbio)
561558 * Here we should only zero the range inside the folio,
562559 * not touch anything else.
563560 *
564- * NOTE: i_size is exclusive while end is inclusive.
561+ * NOTE: i_size is exclusive while end is inclusive and
562+ * folio_contains() takes PAGE_SIZE units.
565563 */
566- if (folio_index (folio ) == end_index && i_size <= end ) {
564+ if (folio_contains (folio , i_size >> PAGE_SHIFT ) &&
565+ i_size <= end ) {
567566 u32 zero_start = max (offset_in_folio (folio , i_size ),
568567 offset_in_folio (folio , start ));
569568 u32 zero_len = offset_in_folio (folio , end ) + 1 -
@@ -899,7 +898,6 @@ static struct extent_map *get_extent_map(struct btrfs_inode *inode,
899898 u64 len , struct extent_map * * em_cached )
900899{
901900 struct extent_map * em ;
902- struct extent_state * cached_state = NULL ;
903901
904902 ASSERT (em_cached );
905903
@@ -915,14 +913,12 @@ static struct extent_map *get_extent_map(struct btrfs_inode *inode,
915913 * em_cached = NULL ;
916914 }
917915
918- btrfs_lock_and_flush_ordered_range (inode , start , start + len - 1 , & cached_state );
919916 em = btrfs_get_extent (inode , folio , start , len );
920917 if (!IS_ERR (em )) {
921918 BUG_ON (* em_cached );
922919 refcount_inc (& em -> refs );
923920 * em_cached = em ;
924921 }
925- unlock_extent (& inode -> io_tree , start , start + len - 1 , & cached_state );
926922
927923 return em ;
928924}
@@ -956,7 +952,7 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
956952 return ret ;
957953 }
958954
959- if (folio -> index == last_byte >> folio_shift ( folio )) {
955+ if (folio_contains ( folio , last_byte >> PAGE_SHIFT )) {
960956 size_t zero_offset = offset_in_folio (folio , last_byte );
961957
962958 if (zero_offset ) {
@@ -1079,11 +1075,18 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
10791075
10801076int btrfs_read_folio (struct file * file , struct folio * folio )
10811077{
1078+ struct btrfs_inode * inode = folio_to_inode (folio );
1079+ const u64 start = folio_pos (folio );
1080+ const u64 end = start + folio_size (folio ) - 1 ;
1081+ struct extent_state * cached_state = NULL ;
10821082 struct btrfs_bio_ctrl bio_ctrl = { .opf = REQ_OP_READ };
10831083 struct extent_map * em_cached = NULL ;
10841084 int ret ;
10851085
1086+ btrfs_lock_and_flush_ordered_range (inode , start , end , & cached_state );
10861087 ret = btrfs_do_readpage (folio , & em_cached , & bio_ctrl , NULL );
1088+ unlock_extent (& inode -> io_tree , start , end , & cached_state );
1089+
10871090 free_extent_map (em_cached );
10881091
10891092 /*
@@ -2380,12 +2383,20 @@ void btrfs_readahead(struct readahead_control *rac)
23802383{
23812384 struct btrfs_bio_ctrl bio_ctrl = { .opf = REQ_OP_READ | REQ_RAHEAD };
23822385 struct folio * folio ;
2386+ struct btrfs_inode * inode = BTRFS_I (rac -> mapping -> host );
2387+ const u64 start = readahead_pos (rac );
2388+ const u64 end = start + readahead_length (rac ) - 1 ;
2389+ struct extent_state * cached_state = NULL ;
23832390 struct extent_map * em_cached = NULL ;
23842391 u64 prev_em_start = (u64 )- 1 ;
23852392
2393+ btrfs_lock_and_flush_ordered_range (inode , start , end , & cached_state );
2394+
23862395 while ((folio = readahead_folio (rac )) != NULL )
23872396 btrfs_do_readpage (folio , & em_cached , & bio_ctrl , & prev_em_start );
23882397
2398+ unlock_extent (& inode -> io_tree , start , end , & cached_state );
2399+
23892400 if (em_cached )
23902401 free_extent_map (em_cached );
23912402 submit_one_bio (& bio_ctrl );
0 commit comments