iomap: Convert iomap_read_inline_data to take a folio

We still only support up to a single page of inline data (at least,
per call to iomap_read_inline_data()), but it can now be written into
the middle of a folio in case we decide to allocate a 16KiB page for
a file that's 8.1KiB in size.
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 431c0566
...@@ -197,16 +197,15 @@ struct iomap_readpage_ctx { ...@@ -197,16 +197,15 @@ struct iomap_readpage_ctx {
/** /**
* iomap_read_inline_data - copy inline data into the page cache * iomap_read_inline_data - copy inline data into the page cache
* @iter: iteration structure * @iter: iteration structure
* @page: page to copy to * @folio: folio to copy to
* *
* Copy the inline data in @iter into @page and zero out the rest of the page. * Copy the inline data in @iter into @folio and zero out the rest of the folio.
* Only a single IOMAP_INLINE extent is allowed at the end of each file. * Only a single IOMAP_INLINE extent is allowed at the end of each file.
* Returns zero for success to complete the read, or the usual negative errno. * Returns zero for success to complete the read, or the usual negative errno.
*/ */
static int iomap_read_inline_data(const struct iomap_iter *iter, static int iomap_read_inline_data(const struct iomap_iter *iter,
struct page *page) struct folio *folio)
{ {
struct folio *folio = page_folio(page);
struct iomap_page *iop; struct iomap_page *iop;
const struct iomap *iomap = iomap_iter_srcmap(iter); const struct iomap *iomap = iomap_iter_srcmap(iter);
size_t size = i_size_read(iter->inode) - iomap->offset; size_t size = i_size_read(iter->inode) - iomap->offset;
...@@ -214,7 +213,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter, ...@@ -214,7 +213,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
size_t offset = offset_in_folio(folio, iomap->offset); size_t offset = offset_in_folio(folio, iomap->offset);
void *addr; void *addr;
if (PageUptodate(page)) if (folio_test_uptodate(folio))
return 0; return 0;
if (WARN_ON_ONCE(size > PAGE_SIZE - poff)) if (WARN_ON_ONCE(size > PAGE_SIZE - poff))
...@@ -229,7 +228,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter, ...@@ -229,7 +228,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
else else
iop = to_iomap_page(folio); iop = to_iomap_page(folio);
addr = kmap_local_page(page) + poff; addr = kmap_local_folio(folio, offset);
memcpy(addr, iomap->inline_data, size); memcpy(addr, iomap->inline_data, size);
memset(addr + size, 0, PAGE_SIZE - poff - size); memset(addr + size, 0, PAGE_SIZE - poff - size);
kunmap_local(addr); kunmap_local(addr);
...@@ -261,7 +260,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, ...@@ -261,7 +260,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
sector_t sector; sector_t sector;
if (iomap->type == IOMAP_INLINE) if (iomap->type == IOMAP_INLINE)
return iomap_read_inline_data(iter, page); return iomap_read_inline_data(iter, folio);
/* zero post-eof blocks as the page may be mapped */ /* zero post-eof blocks as the page may be mapped */
iop = iomap_page_create(iter->inode, folio); iop = iomap_page_create(iter->inode, folio);
...@@ -597,10 +596,12 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, ...@@ -597,10 +596,12 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
static int iomap_write_begin_inline(const struct iomap_iter *iter, static int iomap_write_begin_inline(const struct iomap_iter *iter,
struct page *page) struct page *page)
{ {
struct folio *folio = page_folio(page);
/* needs more work for the tailpacking case; disable for now */ /* needs more work for the tailpacking case; disable for now */
if (WARN_ON_ONCE(iomap_iter_srcmap(iter)->offset != 0)) if (WARN_ON_ONCE(iomap_iter_srcmap(iter)->offset != 0))
return -EIO; return -EIO;
return iomap_read_inline_data(iter, page); return iomap_read_inline_data(iter, folio);
} }
static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos, static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment