Jan Kara <jack@xxxxxxx> writes: > Gao Xiang has reported that on ext4 O_SYNC direct IO does not properly > sync file size update and thus if we crash at unfortunate moment, the > file can have smaller size although O_SYNC IO has reported successful > completion. The problem happens because update of on-disk inode size is > handled in ext4_dio_write_iter() *after* iomap_dio_rw() (and thus > dio_complete() in particular) has returned and generic_file_sync() gets > called by dio_complete(). Fix the problem by handling on-disk inode size > update directly in our ->end_io completion handler. > > References: https://lore.kernel.org/all/02d18236-26ef-09b0-90ad-030c4fe3ee20@xxxxxxxxxxxxxxxxx > Reported-by: Gao Xiang <hsiangkao@xxxxxxxxxxxxxxxxx> > CC: stable@xxxxxxxxxxxxxxx > Fixes: 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") > Signed-off-by: Jan Kara <jack@xxxxxxx> > --- > fs/ext4/file.c | 153 +++++++++++++++++++++---------------------------- > 1 file changed, 65 insertions(+), 88 deletions(-) > > Changes since v2: > * Added more comments explaining the code flow > * Added WARN_ON_ONCE to verify extending IO is handled synchronously > > Changes since v1: > * Rebased on top of Linus' tree (instead of a tree with iomap cleanup) > * Made ext4_dio_write_end_io() always return number of written bytes on > success for consistency Thanks for addressing it. It's always better to have a consistent return value wherever possible. > * Added Fixes tag Looks good to me. Please feel free to add - Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>