Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: fail unaligned direct IO write with EINVAL

Commit bc264fea0f6f ("iomap: support incremental iomap_iter advances")
changed the error handling logic in iomap_iter(). Previously any error
from iomap_dio_bio_iter() got propagated to userspace, after this commit
if ->iomap_end returns error, it gets propagated to userspace instead of
an error from iomap_dio_bio_iter(). This results in unaligned writes to
ext4 to silently fallback to buffered IO instead of erroring out.

Now returning ENOTBLK for DIO writes from ext4_iomap_end() seems
unnecessary these days. It is enough to return ENOTBLK from
ext4_iomap_begin() when we don't support DIO write for that particular
file offset (due to hole).

Fixes: bc264fea0f6f ("iomap: support incremental iomap_iter advances")
Cc: stable@kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Message-ID: <20250901112739.32484-2-jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Jan Kara and committed by
Theodore Ts'o
96384574 46c22a8b

-35
-35
fs/ext4/inode.c
··· 3872 3872 return ret; 3873 3873 } 3874 3874 3875 - static inline bool ext4_want_directio_fallback(unsigned flags, ssize_t written) 3876 - { 3877 - /* must be a directio to fall back to buffered */ 3878 - if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != 3879 - (IOMAP_WRITE | IOMAP_DIRECT)) 3880 - return false; 3881 - 3882 - /* atomic writes are all-or-nothing */ 3883 - if (flags & IOMAP_ATOMIC) 3884 - return false; 3885 - 3886 - /* can only try again if we wrote nothing */ 3887 - return written == 0; 3888 - } 3889 - 3890 - static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, 3891 - ssize_t written, unsigned flags, struct iomap *iomap) 3892 - { 3893 - /* 3894 - * Check to see whether an error occurred while writing out the data to 3895 - * the allocated blocks. If so, return the magic error code for 3896 - * non-atomic write so that we fallback to buffered I/O and attempt to 3897 - * complete the remainder of the I/O. 3898 - * For non-atomic writes, any blocks that may have been 3899 - * allocated in preparation for the direct I/O will be reused during 3900 - * buffered I/O. For atomic write, we never fallback to buffered-io. 3901 - */ 3902 - if (ext4_want_directio_fallback(flags, written)) 3903 - return -ENOTBLK; 3904 - 3905 - return 0; 3906 - } 3907 - 3908 3875 const struct iomap_ops ext4_iomap_ops = { 3909 3876 .iomap_begin = ext4_iomap_begin, 3910 - .iomap_end = ext4_iomap_end, 3911 3877 }; 3912 3878 3913 3879 const struct iomap_ops ext4_iomap_overwrite_ops = { 3914 3880 .iomap_begin = ext4_iomap_overwrite_begin, 3915 - .iomap_end = ext4_iomap_end, 3916 3881 }; 3917 3882 3918 3883 static int ext4_iomap_begin_report(struct inode *inode, loff_t offset,