[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240429174746.2132161-21-john.g.garry@oracle.com>
Date: Mon, 29 Apr 2024 17:47:45 +0000
From: John Garry <john.g.garry@...cle.com>
To: david@...morbit.com, djwong@...nel.org, hch@....de,
viro@...iv.linux.org.uk, brauner@...nel.org, jack@...e.cz,
chandan.babu@...cle.com, willy@...radead.org
Cc: axboe@...nel.dk, martin.petersen@...cle.com, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, tytso@....edu, jbongio@...gle.com,
ojaswin@...ux.ibm.com, ritesh.list@...il.com, mcgrof@...nel.org,
p.raghav@...sung.com, linux-xfs@...r.kernel.org,
catherine.hoang@...cle.com, John Garry <john.g.garry@...cle.com>
Subject: [PATCH v3 20/21] xfs: Validate atomic writes
Validate that an atomic write adheres to length/offset rules. Since we
require extent alignment for atomic writes, this effectively also enforces
that the BIO which iomap produces is aligned.
For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_dio_write(),
FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this,
FORCEALIGN and also ATOMICWRITES flags would also need to be set for the
inode.
Signed-off-by: John Garry <john.g.garry@...cle.com>
---
fs/xfs/xfs_file.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index ee4f94cf6f4e..256d05c1be6a 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -712,12 +712,20 @@ xfs_file_dio_write(
struct kiocb *iocb,
struct iov_iter *from)
{
- struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
+ struct inode *inode = file_inode(iocb->ki_filp);
+ struct xfs_inode *ip = XFS_I(inode);
struct xfs_buftarg *target = xfs_inode_buftarg(ip);
size_t count = iov_iter_count(from);
struct xfs_mount *mp = ip->i_mount;
unsigned int blockmask;
+ if (iocb->ki_flags & IOCB_ATOMIC) {
+ if (!generic_atomic_write_valid_size(iocb->ki_pos, from,
+ i_blocksize(inode), XFS_FSB_TO_B(mp, ip->i_extsize))) {
+ return -EINVAL;
+ }
+ }
+
/* direct I/O must be aligned to device logical sector size */
if ((iocb->ki_pos | count) & target->bt_logical_sectormask)
return -EINVAL;
--
2.31.1
Powered by blists - more mailing lists