Skip to content

Commit 70a7b91

Browse files
dhowellsbrauner
authored andcommitted
netfs: Fix write streaming disablement if fd open O_RDWR
In netfs_perform_write(), "write streaming" (the caching of dirty data in dirty but !uptodate folios) is performed to avoid the need to read data that is just going to get immediately overwritten. However, this is/will be disabled in three circumstances: if the fd is open O_RDWR, if fscache is in use (as we need to round out the blocks for DIO) or if content encryption is enabled (again for rounding out purposes). The idea behind disabling it if the fd is open O_RDWR is that we'd need to flush the write-streaming page before we could read the data, particularly through mmap. But netfs now fills in the gaps if ->read_folio() is called on the page, so that is unnecessary. Further, this doesn't actually work if a separate fd is open for reading. Fix this by removing the check for O_RDWR, thereby allowing streaming writes even when we might read. This caused a number of problems with the generic/522 xfstest, but those are now fixed. Fixes: c38f4e9 ("netfs: Provide func to copy data to pagecache for buffered write") Signed-off-by: David Howells <dhowells@redhat.com> Link: https://patch.msgid.link/20260512123404.719402-17-dhowells@redhat.com cc: Paulo Alcantara <pc@manguebit.org> cc: Matthew Wilcox <willy@infradead.org> cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a41168a commit 70a7b91

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

fs/netfs/buffered_write.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,
203203
}
204204

205205
/* Decide how we should modify a folio. We might be attempting
206-
* to do write-streaming, in which case we don't want to a
207-
* local RMW cycle if we can avoid it. If we're doing local
208-
* caching or content crypto, we award that priority over
209-
* avoiding RMW. If the file is open readably, then we also
210-
* assume that we may want to read what we wrote.
206+
* to do write-streaming, as we don't want to a local RMW cycle
207+
* if we can avoid it. If we're doing local caching or content
208+
* crypto, we award that priority over avoiding RMW. If the
209+
* file is open readably, then we let ->read_folio() fill in
210+
* the gaps.
211211
*/
212212
finfo = netfs_folio_info(folio);
213213
group = netfs_folio_group(folio);
@@ -283,12 +283,9 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,
283283

284284
/* We don't want to do a streaming write on a file that loses
285285
* caching service temporarily because the backing store got
286-
* culled and we don't really want to get a streaming write on
287-
* a file that's open for reading as ->read_folio() then has to
288-
* be able to flush it.
286+
* culled.
289287
*/
290-
if ((file->f_mode & FMODE_READ) ||
291-
netfs_is_cache_enabled(ctx)) {
288+
if (netfs_is_cache_enabled(ctx)) {
292289
if (finfo) {
293290
netfs_stat(&netfs_n_wh_wstream_conflict);
294291
goto flush_content;

0 commit comments

Comments
 (0)