]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: Validate atomic writes
authorJohn Garry <john.g.garry@oracle.com>
Tue, 5 Nov 2024 00:14:04 +0000 (16:14 -0800)
committerDarrick J. Wong <djwong@djwong.org>
Tue, 5 Nov 2024 00:22:10 +0000 (16:22 -0800)
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 <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/xfs_file.c

index 412b1d71b52b7d0f964b054c1718c5de9fde99e8..44be10490342783542ea0e9845826f9a4527ef26 100644 (file)
@@ -822,6 +822,20 @@ xfs_file_write_iter(
        if (IS_DAX(inode))
                return xfs_file_dax_write(iocb, from);
 
+       if (iocb->ki_flags & IOCB_ATOMIC) {
+               /*
+                * Currently only atomic writing of a single FS block is
+                * supported. It would be possible to atomic write smaller than
+                * a FS block, but there is no requirement to support this.
+                * Note that iomap also does not support this yet.
+                */
+               if (ocount != ip->i_mount->m_sb.sb_blocksize)
+                       return -EINVAL;
+               ret = generic_atomic_write_valid(iocb, from);
+               if (ret)
+                       return ret;
+       }
+
        if (iocb->ki_flags & IOCB_DIRECT) {
                /*
                 * Allow a directio write to fall back to a buffered