Since the size will be updated after the DIO completes, the data will not be shown to userspace before that. Signed-off-by: Yang Erkun --- fs/ext4/ext4.h | 2 ++ fs/ext4/inode.c | 5 +++-- include/trace/events/ext4.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 5a035d0e2761..bad43d047224 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -715,6 +715,8 @@ enum { #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020 /* Don't normalize allocation size (used for fallocate) */ #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040 + /* Get blocks from DIO */ +#define EXT4_GET_BLOCKS_DIO 0x0080 /* Convert written extents to unwritten */ #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100 /* Write zeros to newly created written extents */ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3d8ada26d5cd..168dbcc9e921 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -818,6 +818,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, if (map->m_flags & EXT4_MAP_NEW && !(map->m_flags & EXT4_MAP_UNWRITTEN) && !(flags & EXT4_GET_BLOCKS_ZERO) && + !(flags & EXT4_GET_BLOCKS_DIO) && !ext4_is_quota_file(inode) && ext4_should_order_data(inode)) { loff_t start_byte = @@ -3729,9 +3730,9 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, * happening and thus expose allocated blocks to direct I/O reads. */ else if (((loff_t)map->m_lblk << blkbits) >= i_size_read(inode)) - m_flags = EXT4_GET_BLOCKS_CREATE; + m_flags = EXT4_GET_BLOCKS_CREATE | EXT4_GET_BLOCKS_DIO; else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) - m_flags = EXT4_GET_BLOCKS_IO_CREATE_EXT; + m_flags = EXT4_GET_BLOCKS_IO_CREATE_EXT | EXT4_GET_BLOCKS_DIO; if (flags & IOMAP_ATOMIC) ret = ext4_map_blocks_atomic_write(handle, inode, map, m_flags, diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index ada2b9223df5..de6d848f2e37 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -43,6 +43,7 @@ struct partial_cluster; { EXT4_GET_BLOCKS_CONVERT, "CONVERT" }, \ { EXT4_GET_BLOCKS_METADATA_NOFAIL, "METADATA_NOFAIL" }, \ { EXT4_GET_BLOCKS_NO_NORMALIZE, "NO_NORMALIZE" }, \ + { EXT4_GET_BLOCKS_DIO, "DIO" }, \ { EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, "CONVERT_UNWRITTEN" }, \ { EXT4_GET_BLOCKS_ZERO, "ZERO" }, \ { EXT4_GET_BLOCKS_IO_SUBMIT, "IO_SUBMIT" }, \ -- 2.39.2