Skip to content

Commit d454ab8

Browse files
author
Matthew Wilcox (Oracle)
committed
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) <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]>
1 parent ea0f843 commit d454ab8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/iomap/buffered-io.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
619619
if (fatal_signal_pending(current))
620620
return -EINTR;
621621

622+
if (!mapping_large_folio_support(iter->inode->i_mapping))
623+
len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
624+
622625
if (page_ops && page_ops->page_prepare) {
623626
status = page_ops->page_prepare(iter->inode, pos, len);
624627
if (status)
@@ -632,6 +635,8 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
632635
goto out_no_page;
633636
}
634637
folio = page_folio(page);
638+
if (pos + len > folio_pos(folio) + folio_size(folio))
639+
len = folio_pos(folio) + folio_size(folio) - pos;
635640

636641
if (srcmap->type == IOMAP_INLINE)
637642
status = iomap_write_begin_inline(iter, page);
@@ -891,11 +896,13 @@ static s64 __iomap_zero_iter(struct iomap_iter *iter, loff_t pos, u64 length)
891896
struct page *page;
892897
int status;
893898
unsigned offset = offset_in_page(pos);
894-
unsigned bytes = min_t(u64, PAGE_SIZE - offset, length);
899+
unsigned bytes = min_t(u64, UINT_MAX, length);
895900

896901
status = iomap_write_begin(iter, pos, bytes, &page);
897902
if (status)
898903
return status;
904+
if (bytes > PAGE_SIZE - offset)
905+
bytes = PAGE_SIZE - offset;
899906

900907
zero_user(page, offset, bytes);
901908
mark_page_accessed(page);

0 commit comments

Comments
 (0)