Several file systems implement an almost identical ->end_io callback for direct writes: if the write succeeded and went beyond the current end-of-file, update i_size and mark the inode dirty (for example, ext2_dio_write_end_io()). Add a generic iomap_dio_end_io() helper for this case, so that file systems don't need to open-code it. The helper updates i_size without any locking, so it can be used only by file systems that issue all direct writes extending i_size synchronously (IOMAP_DIO_FORCE_WAIT) under inode_lock. The first user will be HFS+. cc: Christian Brauner cc: Christoph Hellwig cc: Darrick J. Wong cc: John Paul Adrian Glaubitz cc: Yangtao Li cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Signed-off-by: Viacheslav Dubeyko --- include/linux/iomap.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 5254430844b2..616abe7ebad9 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -672,6 +672,26 @@ struct iomap_dio_ops { struct bio_set *bio_set; }; +/* + * Direct I/O completion handler + */ +static inline +int iomap_dio_end_io(struct kiocb *iocb, ssize_t size, + int error, unsigned int flags) +{ + struct inode *inode = file_inode(iocb->ki_filp); + + if (error) + return error; + + if (size && i_size_read(inode) < iocb->ki_pos + size) { + i_size_write(inode, iocb->ki_pos + size); + mark_inode_dirty(inode); + } + + return 0; +} + /* * Wait for the I/O to complete in iomap_dio_rw even if the kiocb is not * synchronous. -- 2.53.0