Skip to content

Commit 43c696f

Browse files
riteshharjaniDarrick J. Wong
authored andcommitted
ext4: Check for atomic writes support in write iter
Let's validate the given constraints for atomic write request. Otherwise it will fail with -EINVAL. Currently atomic write is only supported on DIO, so for buffered-io it will return -EOPNOTSUPP. Reviewed-by: John Garry <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Ritesh Harjani (IBM) <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Jan Kara <[email protected]>
1 parent 6dfc1c1 commit 43c696f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/ext4/file.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,20 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
692692
if (IS_DAX(inode))
693693
return ext4_dax_write_iter(iocb, from);
694694
#endif
695+
696+
if (iocb->ki_flags & IOCB_ATOMIC) {
697+
size_t len = iov_iter_count(from);
698+
int ret;
699+
700+
if (len < EXT4_SB(inode->i_sb)->s_awu_min ||
701+
len > EXT4_SB(inode->i_sb)->s_awu_max)
702+
return -EINVAL;
703+
704+
ret = generic_atomic_write_valid(iocb, from);
705+
if (ret)
706+
return ret;
707+
}
708+
695709
if (iocb->ki_flags & IOCB_DIRECT)
696710
return ext4_dio_write_iter(iocb, from);
697711
else

0 commit comments

Comments
 (0)