On Fri, Jul 16, 2021 at 10:19:09AM +0100, Christoph Hellwig wrote: > static void > iomap_read_inline_data(struct inode *inode, struct page *page, > - struct iomap *iomap) > + struct iomap *iomap, loff_t pos, unsigned int size) > { > - size_t size = i_size_read(inode); > + unsigned int block_aligned_size = round_up(size, i_blocksize(inode)); > + unsigned int poff = offset_in_page(pos); > void *addr; > > - if (PageUptodate(page)) > - return; > - > - BUG_ON(page_has_private(page)); > - BUG_ON(page->index); > + /* make sure that inline_data doesn't cross page boundary */ > BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data)); > + BUG_ON(size != i_size_read(inode) - pos); > > addr = kmap_atomic(page); > - memcpy(addr, iomap->inline_data, size); > - memset(addr + size, 0, PAGE_SIZE - size); > + memcpy(addr + poff, iomap->inline_data - iomap->offset + pos, size); > + memset(addr + poff + size, 0, block_aligned_size - size); > kunmap_atomic(addr); > - SetPageUptodate(page); > + > + iomap_set_range_uptodate(page, poff, block_aligned_size); > } This should be relatively straightforward to port to folios. I think it looks something like this ... @@ -211,23 +211,18 @@ struct iomap_readpage_ctx { }; static void iomap_read_inline_data(struct inode *inode, struct folio *folio, - struct iomap *iomap) + struct iomap *iomap, loff_t pos, size_t size) { - size_t size = i_size_read(inode); void *addr; + size_t offset = offset_in_folio(folio, pos); - if (folio_test_uptodate(folio)) - return; + BUG_ON(size != i_size_read(inode) - pos); - BUG_ON(folio->index); - BUG_ON(folio_multi(folio)); - BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data)); - - addr = kmap_local_folio(folio, 0); + addr = kmap_local_folio(folio, offset); memcpy(addr, iomap->inline_data, size); memset(addr + size, 0, PAGE_SIZE - size); kunmap_local(addr); - folio_mark_uptodate(folio); + iomap_set_range_uptodate(folio, to_iomap_page(folio), pos, size); } > - if (iomap->type == IOMAP_INLINE) { > - WARN_ON_ONCE(pos); > - iomap_read_inline_data(inode, page, iomap); > - return PAGE_SIZE; > - } > + if (iomap->type == IOMAP_INLINE && !pos) > + WARN_ON_ONCE(to_iomap_page(page) != NULL); > + else > + iop = iomap_page_create(inode, page); This WARN_ON doesn't make sense to me. If a file contains bytes 0-2047 that are !INLINE and then bytes 2048-2050 that are INLINE, we're going to trigger it. Perhaps just make this: if (iomap->type != IOMAP_INLINE || pos) iop = iomap_page_create(inode, page);