Skip to content

Commit 01af106

Browse files
Matthew Wilcox (Oracle)kdave
Matthew Wilcox (Oracle)
authored andcommitted
btrfs: fix two misuses of folio_shift()
It is meaningless to shift a byte count by folio_shift(). The folio index is in units of PAGE_SIZE, not folio_size(). We can use folio_contains() to make this work for arbitrary-order folios, so remove the assertion that the folios are of order 0. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent fdef89c commit 01af106

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fs/btrfs/extent_io.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 -
@@ -956,7 +955,7 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
956955
return ret;
957956
}
958957

959-
if (folio->index == last_byte >> folio_shift(folio)) {
958+
if (folio_contains(folio, last_byte >> PAGE_SHIFT)) {
960959
size_t zero_offset = offset_in_folio(folio, last_byte);
961960

962961
if (zero_offset) {

0 commit comments

Comments
 (0)