zonefs: Fix O_APPEND async write handling
authorDamien Le Moal <damien.lemoal@wdc.com>
Wed, 10 Mar 2021 06:20:28 +0000 (15:20 +0900)
committerDamien Le Moal <damien.lemoal@wdc.com>
Tue, 16 Mar 2021 08:46:55 +0000 (17:46 +0900)
commitebfd68cd0c1e81267c757332385cb96df30dacce
tree3610fbdef839e6165197216c3ea128b98d84d0b1
parent1601ea068b886da1f8f8d4e18b9403e9e24adef6
zonefs: Fix O_APPEND async write handling

zonefs updates the size of a sequential zone file inode only on
completion of direct writes. When executing asynchronous append writes
(with a file open with O_APPEND or using RWF_APPEND), the use of the
current inode size in generic_write_checks() to set an iocb offset thus
leads to unaligned write if an application issues an append write
operation with another write already being executed.

Fix this problem by introducing zonefs_write_checks() as a modified
version of generic_write_checks() using the file inode wp_offset for an
append write iocb offset. Also introduce zonefs_write_check_limits() to
replace generic_write_check_limits() call. This zonefs special helper
makes sure that the maximum file limit used is the maximum size of the
file being accessed.

Since zonefs_write_checks() already truncates the iov_iter, the calls
to iov_iter_truncate() in zonefs_file_dio_write() and
zonefs_file_buffered_write() are removed.

Fixes: 8dcc1a9d90c1 ("fs: New zonefs file system")
Cc: <stable@vger.kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
fs/zonefs/super.c