]> www.infradead.org Git - users/willy/linux.git/commitdiff
iomap: Allow iomap_write_begin() to be called with the full length
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 9 Dec 2021 20:47:44 +0000 (15:47 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 10 Dec 2021 14:37:14 +0000 (09:37 -0500)
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) <willy@infradead.org>
fs/gfs2/bmap.c
fs/iomap/buffered-io.c

index d67108489148eef281128c6841c52135abf74050..9270db17c43577b1931d7a9645c1520eb2f29fd3 100644 (file)
@@ -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);
 }
index 8d7a67655b60957adc5d9db991f0eec1bbd4f296..1a9e897ee25abf86cac4a7c8d6b7d46eb078a066 100644 (file)
@@ -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);