bcachefs: bch2_seek_pagecache_data() folio conversion
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 19 Mar 2023 23:07:28 +0000 (19:07 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:59 +0000 (17:09 -0400)
This converts bch2_seek_pagecache_data() to handle large folios.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs-io.c

index 0cb76238f4871faf5c6febe673c99451424f2aa3..de4e5effca06a944061fbe2a0c83440da856edda 100644 (file)
@@ -3488,10 +3488,10 @@ err:
 static int folio_data_offset(struct folio *folio, unsigned offset)
 {
        struct bch_folio *s = bch2_folio(folio);
-       unsigned i;
+       unsigned i, sectors = folio_sectors(folio);
 
        if (s)
-               for (i = offset >> 9; i < PAGE_SECTORS; i++)
+               for (i = offset >> 9; i < sectors; i++)
                        if (s->s[i].state >= SECTOR_DIRTY)
                                return i << 9;
 
@@ -3519,12 +3519,10 @@ static loff_t bch2_seek_pagecache_data(struct inode *vinode,
 
                        folio_lock(folio);
                        offset = folio_data_offset(folio,
-                                       folio->index == start_index
-                                       ? start_offset & (PAGE_SIZE - 1)
-                                       : 0);
+                                       max(folio_pos(folio), start_offset) -
+                                       folio_pos(folio));
                        if (offset >= 0) {
-                               ret = clamp(((loff_t) folio->index << PAGE_SHIFT) +
-                                           offset,
+                               ret = clamp(folio_pos(folio) + offset,
                                            start_offset, end_offset);
                                folio_unlock(folio);
                                folio_batch_release(&fbatch);