Linux network filesystem support library
 help / color / mirror / Atom feed
* [PATCH 1/5] netfs: discard post-EOF pagecache when extending a file via write
@ 2026-09-21 15:49 Paulo Alcantara
  2026-09-21 15:49 ` [PATCH 2/5] smb: client: discard post-EOF pagecache when extending a file via truncate Paulo Alcantara
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Paulo Alcantara @ 2026-09-21 15:49 UTC (permalink / raw)
  To: linux-cifs, netfs
  Cc: David Howells, Christian Brauner, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, stable

Fix netfs to erase the contents of a hole created after the EOF by an
ordinary write if dirty data has been previously left there by writes
through an mmapped region.  Neither the buffered nor the
unbuffered/DIO write path drops that stale pagecache.

Discard it with truncate_pagecache() before an extending write, which
zeroes the folio straddling the EOF and drops the folios beyond it
while preserving the data below.

Fixes: 938e13a73b24 ("netfs: Implement buffered write API")
Fixes: 153a9961b551 ("netfs: Implement unbuffered/DIO write support")
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: stable@vger.kernel.org
---
 fs/netfs/buffered_write.c | 4 ++++
 fs/netfs/direct_write.c   | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c
index 2cdb68e6b16f..62849fd44313 100644
--- a/fs/netfs/buffered_write.c
+++ b/fs/netfs/buffered_write.c
@@ -469,6 +469,7 @@ ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *fr
 					 struct netfs_group *netfs_group)
 {
 	struct file *file = iocb->ki_filp;
+	struct inode *inode = file_inode(file);
 	ssize_t ret;
 
 	trace_netfs_write_iter(iocb, from);
@@ -481,6 +482,9 @@ ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *fr
 	if (ret)
 		return ret;
 
+	if (iocb->ki_pos > i_size_read(inode))
+		truncate_pagecache(inode, i_size_read(inode));
+
 	return netfs_perform_write(iocb, from, netfs_group);
 }
 EXPORT_SYMBOL(netfs_buffered_write_iter_locked);
diff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c
index 2361277416c7..4268a4ee376a 100644
--- a/fs/netfs/direct_write.c
+++ b/fs/netfs/direct_write.c
@@ -359,6 +359,10 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	ret = file_update_time(file);
 	if (ret < 0)
 		goto out;
+
+	if (iocb->ki_pos > i_size_read(inode))
+		truncate_pagecache(inode, i_size_read(inode));
+
 	if (iocb->ki_flags & IOCB_NOWAIT) {
 		/* We could block if there are any pages in the range. */
 		ret = -EAGAIN;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-21 16:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-21 15:49 [PATCH 1/5] netfs: discard post-EOF pagecache when extending a file via write Paulo Alcantara
2026-09-21 15:49 ` [PATCH 2/5] smb: client: discard post-EOF pagecache when extending a file via truncate Paulo Alcantara
2026-09-21 16:48   ` Paulo Alcantara
2026-09-21 15:49 ` [PATCH 3/5] smb: client: discard post-EOF pagecache when extending a file via zero range Paulo Alcantara
2026-09-21 15:49 ` [PATCH 4/5] smb: client: discard post-EOF pagecache when extending a file via copy range Paulo Alcantara
2026-09-21 15:49 ` [PATCH 5/5] smb: client: discard post-EOF pagecache when extending a file via clone range Paulo Alcantara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox