diff mbox series

[v8,6/7] xfs: Validate atomic writes

Message ID 20241015090142.3189518-7-john.g.garry@oracle.com (mailing list archive)
State New, archived
Headers show
Series block atomic writes for xfs | expand

Commit Message

John Garry Oct. 15, 2024, 9:01 a.m. UTC
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.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 fs/xfs/xfs_file.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Christoph Hellwig Oct. 15, 2024, 12:16 p.m. UTC | #1
On Tue, Oct 15, 2024 at 09:01:41AM +0000, John Garry wrote:
> Validate that an atomic write adheres to length/offset rules. Currently
> we can only write a single FS block.

> +	if (iocb->ki_flags & IOCB_ATOMIC) {
> +		if (ocount != ip->i_mount->m_sb.sb_blocksize)
> +			return -EINVAL;

Maybe throw in a comment here why we are currently limited to atomic
writes of exactly the file system block size and don't allow smaller
values.

Otherwise this looks good to me.
John Garry Oct. 15, 2024, 12:25 p.m. UTC | #2
On 15/10/2024 13:16, Christoph Hellwig wrote:
> On Tue, Oct 15, 2024 at 09:01:41AM +0000, John Garry wrote:
>> Validate that an atomic write adheres to length/offset rules. Currently
>> we can only write a single FS block.
>> +	if (iocb->ki_flags & IOCB_ATOMIC) {
>> +		if (ocount != ip->i_mount->m_sb.sb_blocksize)
>> +			return -EINVAL;
> Maybe throw in a comment here why we are currently limited to atomic
> writes of exactly the file system block size and don't allow smaller
> values.
> 

ok

> Otherwise this looks good to me.

cheers
diff mbox series

Patch

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 412b1d71b52b..3a0a35e7826a 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -822,6 +822,14 @@  xfs_file_write_iter(
 	if (IS_DAX(inode))
 		return xfs_file_dax_write(iocb, from);
 
+	if (iocb->ki_flags & IOCB_ATOMIC) {
+		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