Commit 68456d05 authored by John Garry's avatar John Garry Committed by Carlos Maiolino
Browse files

xfs: disallow atomic writes on DAX



Atomic writes are not currently supported for DAX, but two problems exist:
- we may go down DAX write path for IOCB_ATOMIC, which does not handle
  IOCB_ATOMIC properly
- we report non-zero atomic write limits in statx (for DAX inodes)

We may want atomic writes support on DAX in future, but just disallow for
now.

For this, ensure when IOCB_ATOMIC is set that we check the write size
versus the atomic write min and max before branching off to the DAX write
path. This is not strictly required for DAX, as we should not get this far
in the write path as FMODE_CAN_ATOMIC_WRITE should not be set.

In addition, due to reflink being supported for DAX, we automatically get
CoW-based atomic writes support being advertised. Remedy this by
disallowing atomic writes for a DAX inode for both sw and hw modes.

Reported-by: default avatarDarrick J. Wong <djwong@kernel.org>
Fixes: 9dffc58f ("xfs: update atomic write limits")
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarCarlos Maiolino <cem@kernel.org>
parent e7fb9b71
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1101,9 +1101,6 @@ xfs_file_write_iter(
	if (xfs_is_shutdown(ip->i_mount))
		return -EIO;

	if (IS_DAX(inode))
		return xfs_file_dax_write(iocb, from);

	if (iocb->ki_flags & IOCB_ATOMIC) {
		if (ocount < xfs_get_atomic_write_min(ip))
			return -EINVAL;
@@ -1116,6 +1113,9 @@ xfs_file_write_iter(
			return ret;
	}

	if (IS_DAX(inode))
		return xfs_file_dax_write(iocb, from);

	if (iocb->ki_flags & IOCB_DIRECT) {
		/*
		 * Allow a directio write to fall back to a buffered
+11 −0
Original line number Diff line number Diff line
@@ -358,9 +358,20 @@ static inline bool xfs_inode_has_bigrtalloc(const struct xfs_inode *ip)

static inline bool xfs_inode_can_hw_atomic_write(const struct xfs_inode *ip)
{
	if (IS_DAX(VFS_IC(ip)))
		return false;

	return xfs_inode_buftarg(ip)->bt_awu_max > 0;
}

static inline bool xfs_inode_can_sw_atomic_write(const struct xfs_inode *ip)
{
	if (IS_DAX(VFS_IC(ip)))
		return false;

	return xfs_can_sw_atomic_write(ip->i_mount);
}

/*
 * In-core inode flags.
 */
+3 −2
Original line number Diff line number Diff line
@@ -616,7 +616,8 @@ xfs_get_atomic_write_min(
	 * write of exactly one single fsblock if the bdev will make that
	 * guarantee for us.
	 */
	if (xfs_inode_can_hw_atomic_write(ip) || xfs_can_sw_atomic_write(mp))
	if (xfs_inode_can_hw_atomic_write(ip) ||
	    xfs_inode_can_sw_atomic_write(ip))
		return mp->m_sb.sb_blocksize;

	return 0;
@@ -633,7 +634,7 @@ xfs_get_atomic_write_max(
	 * write of exactly one single fsblock if the bdev will make that
	 * guarantee for us.
	 */
	if (!xfs_can_sw_atomic_write(mp)) {
	if (!xfs_inode_can_sw_atomic_write(ip)) {
		if (xfs_inode_can_hw_atomic_write(ip))
			return mp->m_sb.sb_blocksize;
		return 0;