f2fs: rework write preallocations
authorEric Biggers <ebiggers@google.com>
Fri, 16 Jul 2021 14:39:13 +0000 (09:39 -0500)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 17 Nov 2021 19:28:22 +0000 (11:28 -0800)
commit3d697a4a6b7dab8fb8a8c928b640999af3a08d87
treef68807abdbcf9ad45ae4bb0e2c3edc6dd86b99e2
parent3271d7eb00f1df82d9ea26b359ed065129639f7c
f2fs: rework write preallocations

f2fs_write_begin() assumes that all blocks were preallocated by
default unless FI_NO_PREALLOC is explicitly set.  This invites data
corruption, as there are cases in which not all blocks are preallocated.
Commit 47501f87c61a ("f2fs: preallocate DIO blocks when forcing
buffered_io") fixed one case, but there are others remaining.

Fix up this logic by replacing this flag with FI_PREALLOCATED_ALL, which
only gets set if all blocks for the current write were preallocated.

Also clean up f2fs_preallocate_blocks(), move it to file.c, and make it
handle some of the logic that was previously in write_iter() directly.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/file.c