From 1ec443dd4bd0f92c4665ae5e3224cd95af13c296 Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Thu, 9 Dec 2021 15:47:44 -0500 Subject: [PATCH] iomap: Allow iomap_write_begin() to be called with the full length In the future, we want write_begin to know the entire length of the write so that it can choose to allocate large folios. Pass the full length in from __iomap_zero_iter() and limit it where necessary. Signed-off-by: Matthew Wilcox (Oracle) --- fs/gfs2/bmap.c | 3 +++ fs/iomap/buffered-io.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index d67108489148..9270db17c435 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -968,6 +968,9 @@ static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos, struct gfs2_sbd *sdp = GFS2_SB(inode); unsigned int blocks; + /* gfs2 does not support large folios yet */ + if (len > PAGE_SIZE) + len = PAGE_SIZE; blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits; return gfs2_trans_begin(sdp, RES_DINODE + blocks, 0); } diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 8d7a67655b60..1a9e897ee25a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -632,6 +632,8 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos, goto out_no_page; } folio = page_folio(page); + if (pos + len > folio_pos(folio) + folio_size(folio)) + len = folio_pos(folio) + folio_size(folio) - pos; if (srcmap->type == IOMAP_INLINE) status = iomap_write_begin_inline(iter, page); @@ -891,11 +893,13 @@ static s64 __iomap_zero_iter(struct iomap_iter *iter, loff_t pos, u64 length) struct page *page; int status; unsigned offset = offset_in_page(pos); - unsigned bytes = min_t(u64, PAGE_SIZE - offset, length); + unsigned bytes = min_t(u64, UINT_MAX, length); status = iomap_write_begin(iter, pos, bytes, &page); if (status) return status; + if (bytes > PAGE_SIZE - offset) + bytes = PAGE_SIZE - offset; zero_user(page, offset, bytes); mark_page_accessed(page); -- 2.50.1