linux-stable/fs/netfs
David Howells c97f59e276
netfs: Fix the pre-flush when appending to a file in writethrough mode
In netfs_perform_write(), when the file is marked NETFS_ICTX_WRITETHROUGH
or O_*SYNC or RWF_*SYNC was specified, write-through caching is performed
on a buffered file.  When setting up for write-through, we flush any
conflicting writes in the region and wait for the write to complete,
failing if there's a write error to return.

The issue arises if we're writing at or above the EOF position because we
skip the flush and - more importantly - the wait.  This becomes a problem
if there's a partial folio at the end of the file that is being written out
and we want to make a write to it too.  Both the already-running write and
the write we start both want to clear the writeback mark, but whoever is
second causes a warning looking something like:

    ------------[ cut here ]------------
    R=00000012: folio 11 is not under writeback
    WARNING: CPU: 34 PID: 654 at fs/netfs/write_collect.c:105
    ...
    CPU: 34 PID: 654 Comm: kworker/u386:27 Tainted: G S ...
    ...
    Workqueue: events_unbound netfs_write_collection_worker
    ...
    RIP: 0010:netfs_writeback_lookup_folio

Fix this by making the flush-and-wait unconditional.  It will do nothing if
there are no folios in the pagecache and will return quickly if there are
no folios in the region specified.

Further, move the WBC attachment above the flush call as the flush is going
to attach a WBC and detach it again if it is not present - and since we
need one anyway we might as well share it.

Fixes: 41d8e7673a ("netfs: Implement a write-through caching option")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202404161031.468b84f-oliver.sang@intel.com
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/2150448.1714130115@warthog.procyon.org.uk
Reviewed-by: Jeffrey Layton <jlayton@kernel.org>
cc: Eric Van Hensbergen <ericvh@kernel.org>
cc: Latchesar Ionkov <lucho@ionkov.net>
cc: Dominique Martinet <asmadeus@codewreck.org>
cc: Christian Schoenebeck <linux_oss@crudebyte.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
cc: v9fs@lists.linux.dev
cc: linux-afs@lists.infradead.org
cc: linux-cifs@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-04-26 14:56:18 +02:00
..
Kconfig netfs, fscache: Combine fscache with netfs 2023-12-24 15:08:46 +00:00
Makefile netfs: Implement unbuffered/DIO write support 2023-12-28 09:45:24 +00:00
buffered_read.c netfs: Don't use certain unnecessary folio_*() functions 2024-01-22 21:56:11 +00:00
buffered_write.c netfs: Fix the pre-flush when appending to a file in writethrough mode 2024-04-26 14:56:18 +02:00
direct_read.c netfs: Implement unbuffered/DIO read support 2023-12-28 09:45:23 +00:00
direct_write.c netfs: Fix missing zero-length check in unbuffered write 2024-01-29 14:53:21 +01:00
fscache_cache.c netfs, fscache: Prevent Oops in fscache_put_cache() 2024-01-22 21:58:35 +00:00
fscache_cookie.c netfs, fscache: Move fs/fscache/* into fs/netfs/ 2023-12-24 11:36:00 +00:00
fscache_internal.h netfs, fscache: Combine fscache with netfs 2023-12-24 15:08:46 +00:00
fscache_io.c fscache: Fix error handling in fscache_begin_operation() 2024-03-18 10:33:48 +01:00
fscache_main.c netfs, fscache: Move /proc/fs/fscache to /proc/fs/netfs and put in a symlink 2023-12-24 15:08:48 +00:00
fscache_proc.c netfs: Fix proc/fs/fscache symlink to point to "netfs" not "../netfs" 2024-01-04 13:15:32 +00:00
fscache_stats.c netfs: Fix interaction between write-streaming and cachefiles culling 2024-01-05 15:42:25 +00:00
fscache_volume.c netfs, fscache: Move fs/fscache/* into fs/netfs/ 2023-12-24 11:36:00 +00:00
internal.h netfs: Fix interaction between write-streaming and cachefiles culling 2024-01-05 15:42:25 +00:00
io.c netfs: Fix i_dio_count leak on DIO read past i_size 2024-01-29 14:53:18 +01:00
iterator.c netfs: Add func to calculate pagecount/size-limited span of an iterator 2023-12-28 09:45:18 +00:00
locking.c netfs: Implement unbuffered/DIO vs buffered I/O locking 2023-12-24 15:08:52 +00:00
main.c netfs: Export the netfs_sreq tracepoint 2023-12-28 09:45:27 +00:00
misc.c netfs: Don't use certain unnecessary folio_*() functions 2024-01-22 21:56:11 +00:00
objects.c netfs: Implement a write-through caching option 2023-12-28 09:45:27 +00:00
output.c netfs: Implement a write-through caching option 2023-12-28 09:45:27 +00:00
stats.c netfs: Fix interaction between write-streaming and cachefiles culling 2024-01-05 15:42:25 +00:00