@@ -425,7 +425,7 @@ static void end_folio_read(struct folio *folio, bool uptodate, u64 start, u32 le
425425 struct btrfs_fs_info * fs_info = folio_to_fs_info (folio );
426426
427427 ASSERT (folio_pos (folio ) <= start &&
428- start + len <= folio_pos (folio ) + PAGE_SIZE );
428+ start + len <= folio_pos (folio ) + folio_size ( folio ) );
429429
430430 if (uptodate && btrfs_verify_folio (folio , start , len ))
431431 btrfs_folio_set_uptodate (fs_info , folio , start , len );
@@ -492,7 +492,7 @@ static void begin_folio_read(struct btrfs_fs_info *fs_info, struct folio *folio)
492492 return ;
493493
494494 ASSERT (folio_test_private (folio ));
495- btrfs_folio_set_lock (fs_info , folio , folio_pos (folio ), PAGE_SIZE );
495+ btrfs_folio_set_lock (fs_info , folio , folio_pos (folio ), folio_size ( folio ) );
496496}
497497
498498/*
@@ -753,7 +753,7 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl,
753753{
754754 struct btrfs_inode * inode = folio_to_inode (folio );
755755
756- ASSERT (pg_offset + size <= PAGE_SIZE );
756+ ASSERT (pg_offset + size <= folio_size ( folio ) );
757757 ASSERT (bio_ctrl -> end_io_func );
758758
759759 if (bio_ctrl -> bbio &&
@@ -935,7 +935,7 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
935935 struct inode * inode = folio -> mapping -> host ;
936936 struct btrfs_fs_info * fs_info = inode_to_fs_info (inode );
937937 u64 start = folio_pos (folio );
938- const u64 end = start + PAGE_SIZE - 1 ;
938+ const u64 end = start + folio_size ( folio ) - 1 ;
939939 u64 extent_offset ;
940940 u64 last_byte = i_size_read (inode );
941941 struct extent_map * em ;
@@ -1275,7 +1275,7 @@ static void set_delalloc_bitmap(struct folio *folio, unsigned long *delalloc_bit
12751275 unsigned int start_bit ;
12761276 unsigned int nbits ;
12771277
1278- ASSERT (start >= folio_start && start + len <= folio_start + PAGE_SIZE );
1278+ ASSERT (start >= folio_start && start + len <= folio_start + folio_size ( folio ) );
12791279 start_bit = (start - folio_start ) >> fs_info -> sectorsize_bits ;
12801280 nbits = len >> fs_info -> sectorsize_bits ;
12811281 ASSERT (bitmap_test_range_all_zero (delalloc_bitmap , start_bit , nbits ));
@@ -1293,7 +1293,7 @@ static bool find_next_delalloc_bitmap(struct folio *folio,
12931293 unsigned int first_zero ;
12941294 unsigned int first_set ;
12951295
1296- ASSERT (start >= folio_start && start < folio_start + PAGE_SIZE );
1296+ ASSERT (start >= folio_start && start < folio_start + folio_size ( folio ) );
12971297
12981298 start_bit = (start - folio_start ) >> fs_info -> sectorsize_bits ;
12991299 first_set = find_next_bit (delalloc_bitmap , bitmap_size , start_bit );
@@ -1495,7 +1495,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
14951495 delalloc_end = page_end ;
14961496 /*
14971497 * delalloc_end is already one less than the total length, so
1498- * we don't subtract one from PAGE_SIZE
1498+ * we don't subtract one from PAGE_SIZE.
14991499 */
15001500 delalloc_to_write +=
15011501 DIV_ROUND_UP (delalloc_end + 1 - page_start , PAGE_SIZE );
@@ -1761,7 +1761,7 @@ static int extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ctrl
17611761 goto done ;
17621762
17631763 ret = extent_writepage_io (inode , folio , folio_pos (folio ),
1764- PAGE_SIZE , bio_ctrl , i_size );
1764+ folio_size ( folio ) , bio_ctrl , i_size );
17651765 if (ret == 1 )
17661766 return 0 ;
17671767 if (ret < 0 )
@@ -2488,8 +2488,8 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
24882488 ASSERT (IS_ALIGNED (start , sectorsize ) && IS_ALIGNED (end + 1 , sectorsize ));
24892489
24902490 while (cur <= end ) {
2491- u64 cur_end = min ( round_down ( cur , PAGE_SIZE ) + PAGE_SIZE - 1 , end ) ;
2492- u32 cur_len = cur_end + 1 - cur ;
2491+ u64 cur_end ;
2492+ u32 cur_len ;
24932493 struct folio * folio ;
24942494
24952495 folio = filemap_get_folio (mapping , cur >> PAGE_SHIFT );
@@ -2499,13 +2499,18 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
24992499 * code is just in case, but shouldn't actually be run.
25002500 */
25012501 if (IS_ERR (folio )) {
2502+ cur_end = min (round_down (cur , PAGE_SIZE ) + PAGE_SIZE - 1 , end );
2503+ cur_len = cur_end + 1 - cur ;
25022504 btrfs_mark_ordered_io_finished (BTRFS_I (inode ), NULL ,
25032505 cur , cur_len , false);
25042506 mapping_set_error (mapping , PTR_ERR (folio ));
2505- cur = cur_end + 1 ;
2507+ cur = cur_end ;
25062508 continue ;
25072509 }
25082510
2511+ cur_end = min_t (u64 , folio_pos (folio ) + folio_size (folio ) - 1 , end );
2512+ cur_len = cur_end + 1 - cur ;
2513+
25092514 ASSERT (folio_test_locked (folio ));
25102515 if (pages_dirty && folio != locked_folio )
25112516 ASSERT (folio_test_dirty (folio ));
@@ -2617,7 +2622,7 @@ static bool try_release_extent_state(struct extent_io_tree *tree,
26172622 struct folio * folio )
26182623{
26192624 u64 start = folio_pos (folio );
2620- u64 end = start + PAGE_SIZE - 1 ;
2625+ u64 end = start + folio_size ( folio ) - 1 ;
26212626 bool ret ;
26222627
26232628 if (test_range_bit_exists (tree , start , end , EXTENT_LOCKED )) {
@@ -2655,7 +2660,7 @@ static bool try_release_extent_state(struct extent_io_tree *tree,
26552660bool try_release_extent_mapping (struct folio * folio , gfp_t mask )
26562661{
26572662 u64 start = folio_pos (folio );
2658- u64 end = start + PAGE_SIZE - 1 ;
2663+ u64 end = start + folio_size ( folio ) - 1 ;
26592664 struct btrfs_inode * inode = folio_to_inode (folio );
26602665 struct extent_io_tree * io_tree = & inode -> io_tree ;
26612666
0 commit comments