diff mbox series

nfs: do not extent writes to the entire folio

Message ID 20240705054251.2043864-1-hch@lst.de (mailing list archive)
State New
Headers show
Series nfs: do not extent writes to the entire folio | expand

Commit Message

Christoph Hellwig July 5, 2024, 5:42 a.m. UTC
nfs_update_folio has code to extend a write to the entire page under
certain conditions.  With the support for large folios this now
suddenly extents to the variable sized and potentially much larger folio.
Add code to limit the extension to the page boundaries of the start and
end of the write, which matches the historic expecation and the code
comments.

Fixes: b73fe2dd6cd5 ("nfs: add support for large folios")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/nfs/write.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Sagi Grimberg July 6, 2024, 9:41 p.m. UTC | #1
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Benjamin Coddington July 11, 2024, 2:43 p.m. UTC | #2
On 5 Jul 2024, at 1:42, Christoph Hellwig wrote:

> nfs_update_folio has code to extend a write to the entire page under
> certain conditions.  With the support for large folios this now
> suddenly extents to the variable sized and potentially much larger folio.
> Add code to limit the extension to the page boundaries of the start and
> end of the write, which matches the historic expecation and the code
> comments.
>
> Fixes: b73fe2dd6cd5 ("nfs: add support for large folios")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>

Ben
diff mbox series

Patch

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index f3b556ff35f9d2..4e81325f95d740 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1294,8 +1294,12 @@  int nfs_update_folio(struct file *file, struct folio *folio,
 		goto out;
 
 	if (nfs_can_extend_write(file, folio, pagelen)) {
-		count = max(count + offset, pagelen);
-		offset = 0;
+		unsigned int end = count + offset;
+
+		offset = round_down(offset, PAGE_SIZE);
+		if (end < pagelen)
+			end = min(round_up(end, PAGE_SIZE), pagelen);
+		count = end - offset;
 	}
 
 	status = nfs_writepage_setup(ctx, folio, offset, count);