Subject: [PATCH 03/17] netfs: Fix early issue of write op on partial write to folio tail

From: David Howells <[email-masked]>
Date: Thu, 20 Jun 2024 18:31:21 +0100

During the writeback procedure, at the end of netfs_write_folio(), pending
write operations are flushed if the amount of write-streaming data stored
in a page is less than the size of the folio because if we haven't modified
a folio to the end, it cannot be contiguous with the following folio...
except if the dirty region of the folio is right at the end of the folio
space.

Fix the test to take the offset into the folio into account as well, such
that if the dirty region runs right up to the end of the folio, we leave
the flushing for later.

Fixes: 288ace2f57c9 ("netfs: New writeback implementation")
Signed-off-by: David Howells <[email-masked]>
cc: Jeff Layton <[email-masked]>
cc: Eric Van Hensbergen <[email-masked]>
cc: Latchesar Ionkov <[email-masked]>
cc: Dominique Martinet <[email-masked]>
cc: Christian Schoenebeck <[email-masked]>
cc: Marc Dionne <[email-masked]>
cc: Steve French <[email-masked]>
cc: Paulo Alcantara <[email-masked]> (DFS, global name space)
cc: [email-masked]
cc: [email-masked]
cc: [email-masked]
cc: [email-masked]
cc: [email-masked]
---
 fs/netfs/write_issue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index 3aa86e268f40..ec6cf8707fb0 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -483,7 +483,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
 	if (!debug)
 		kdebug("R=%x: No submit", wreq->debug_id);
 
-	if (flen < fsize)
+	if (foff + flen < fsize)
 		for (int s = 0; s < NR_IO_STREAMS; s++)
 			netfs_issue_write(wreq, &wreq->io_streams[s]);