Skip to content

Commit f096207

Browse files
johnpgarryDarrick J. Wong
authored andcommitted
xfs: Validate atomic writes
Validate that an atomic write adheres to length/offset rules. Currently we can only write a single FS block. For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_write_iter(), FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this, ATOMICWRITES flags would also need to be set for the inode. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: John Garry <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 6432c6e commit f096207

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/xfs/xfs_file.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,20 @@ xfs_file_write_iter(
822822
if (IS_DAX(inode))
823823
return xfs_file_dax_write(iocb, from);
824824

825+
if (iocb->ki_flags & IOCB_ATOMIC) {
826+
/*
827+
* Currently only atomic writing of a single FS block is
828+
* supported. It would be possible to atomic write smaller than
829+
* a FS block, but there is no requirement to support this.
830+
* Note that iomap also does not support this yet.
831+
*/
832+
if (ocount != ip->i_mount->m_sb.sb_blocksize)
833+
return -EINVAL;
834+
ret = generic_atomic_write_valid(iocb, from);
835+
if (ret)
836+
return ret;
837+
}
838+
825839
if (iocb->ki_flags & IOCB_DIRECT) {
826840
/*
827841
* Allow a directio write to fall back to a buffered

0 commit comments

Comments
 (0)