Skip to content

Commit 9638457

Browse files
jankaratytso
authored andcommitted
ext4: fail unaligned direct IO write with EINVAL
Commit bc264fe ("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: bc264fe ("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>
1 parent 46c22a8 commit 9638457

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

fs/ext4/inode.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,47 +3872,12 @@ static int ext4_iomap_overwrite_begin(struct inode *inode, loff_t offset,
38723872
return ret;
38733873
}
38743874

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-
39083875
const struct iomap_ops ext4_iomap_ops = {
39093876
.iomap_begin = ext4_iomap_begin,
3910-
.iomap_end = ext4_iomap_end,
39113877
};
39123878

39133879
const struct iomap_ops ext4_iomap_overwrite_ops = {
39143880
.iomap_begin = ext4_iomap_overwrite_begin,
3915-
.iomap_end = ext4_iomap_end,
39163881
};
39173882

39183883
static int ext4_iomap_begin_report(struct inode *inode, loff_t offset,

0 commit comments

Comments
 (0)