Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -4127,12 +4127,19 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh)
return buffer_uptodate(bh);
}

/*
* Atomic writes are only supported through direct I/O, so an inode that
* can't do direct I/O at all (journaled data, inline data, verity) can't do
* atomic writes either. DAX inodes bypass the direct I/O path entirely.
*/
static inline bool ext4_inode_can_atomic_write(struct inode *inode)
{

return S_ISREG(inode->i_mode) &&
!IS_DAX(inode) &&
ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
EXT4_SB(inode->i_sb)->s_awu_min > 0;
EXT4_SB(inode->i_sb)->s_awu_min > 0 &&
ext4_dio_alignment(inode) != 0;
}

extern int ext4_block_write_begin(handle_t *handle, struct folio *folio,
Expand Down
17 changes: 13 additions & 4 deletions fs/ext4/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
if (iocb->ki_flags & IOCB_NOWAIT)
return -EOPNOTSUPP;

/*
* Buffered I/O provides no torn-write protection. The direct I/O path
* falls back here for inodes that can't do direct I/O at all, so an
* atomic write must be rejected rather than silently done non-atomically.
*/
if (iocb->ki_flags & IOCB_ATOMIC)
return -EOPNOTSUPP;

inode_lock(inode);

/*
Expand Down Expand Up @@ -689,11 +697,12 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
loff_t endbyte;

/*
* There is no support for atomic writes on buffered-io yet,
* we should never fallback to buffered-io for DIO atomic
* writes.
* Buffered I/O provides no torn-write protection, so never
* finish an atomic write through the page cache. iomap must
* not return a short atomic write, so treat one as a bug.
*/
WARN_ON_ONCE(iocb->ki_flags & IOCB_ATOMIC);
if (WARN_ON_ONCE(iocb->ki_flags & IOCB_ATOMIC))
return -EIO;

offset = iocb->ki_pos;
err = ext4_buffered_write_iter(iocb, from);
Expand Down
Loading