Commit 50f258df authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Zheng Zengkai
Browse files

xfs: make xfs_file_aio_write_checks IOCB_NOWAIT-aware

mainline inclusion
from mainline-v5.11-rc4
commit 354be7e3
category: bugfix
bugzilla: 187526,https://gitee.com/openeuler/kernel/issues/I4KIAO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=354be7e3b2baf32e63c0599cc131d393591ba299



--------------------------------

Ensure we don't block on the iolock, or waiting for I/O in
xfs_file_aio_write_checks if the caller asked to avoid that.

Fixes: 29a5d29e ("xfs: nowait aio support")
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarGuo Xuenan <guoxuenan@huawei.com>
Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d8cd6731
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -363,7 +363,14 @@ xfs_file_aio_write_checks(
	if (error <= 0)
		return error;

	if (iocb->ki_flags & IOCB_NOWAIT) {
		error = break_layout(inode, false);
		if (error == -EWOULDBLOCK)
			error = -EAGAIN;
	} else {
		error = xfs_break_layouts(inode, iolock, BREAK_WRITE);
	}

	if (error)
		return error;

@@ -374,7 +381,11 @@ xfs_file_aio_write_checks(
	if (*iolock == XFS_IOLOCK_SHARED && !IS_NOSEC(inode)) {
		xfs_iunlock(ip, *iolock);
		*iolock = XFS_IOLOCK_EXCL;
		xfs_ilock(ip, *iolock);
		error = xfs_ilock_iocb(iocb, *iolock);
		if (error) {
			*iolock = 0;
			return error;
		}
		goto restart;
	}

@@ -405,6 +416,10 @@ xfs_file_aio_write_checks(
	isize = i_size_read(inode);
	if (iocb->ki_pos > isize) {
		spin_unlock(&ip->i_flags_lock);

		if (iocb->ki_flags & IOCB_NOWAIT)
			return -EAGAIN;

		if (!drained_dio) {
			if (*iolock == XFS_IOLOCK_SHARED) {
				xfs_iunlock(ip, *iolock);
@@ -635,6 +650,7 @@ xfs_file_dio_aio_write(
			   &xfs_dio_write_ops,
			   is_sync_kiocb(iocb) || unaligned_io);
out:
	if (iolock)
		xfs_iunlock(ip, iolock);

	/*
@@ -674,6 +690,7 @@ xfs_file_dax_write(
		error = xfs_setfilesize(ip, pos, ret);
	}
out:
	if (iolock)
		xfs_iunlock(ip, iolock);
	if (error)
		return error;