From: Brian Foster <bfoster@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org, Avi Kivity <avi@scylladb.com>
Subject: Re: [PATCH 2/3] xfs: make xfs_file_aio_write_checks IOCB_NOWAIT-aware
Date: Mon, 11 Jan 2021 13:55:31 -0500 [thread overview]
Message-ID: <20210111185531.GE1091932@bfoster> (raw)
In-Reply-To: <20210111161212.1414034-3-hch@lst.de>
On Mon, Jan 11, 2021 at 05:12:11PM +0100, Christoph Hellwig wrote:
> 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: 29a5d29ec181 ("xfs: nowait aio support")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/xfs_file.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index aa3fe89628f0f1..1470fc4f2e0255 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -355,7 +355,14 @@ xfs_file_aio_write_checks(
> if (error <= 0)
> return error;
>
> - error = xfs_break_layouts(inode, iolock, BREAK_WRITE);
> + 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;
>
> @@ -366,7 +373,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;
> }
> /*
> @@ -388,6 +399,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);
> @@ -613,7 +628,8 @@ xfs_file_dio_aio_write(
> &xfs_dio_write_ops,
> is_sync_kiocb(iocb) || unaligned_io);
> out:
> - xfs_iunlock(ip, iolock);
> + if (iolock)
> + xfs_iunlock(ip, iolock);
>
> /*
> * No fallback to buffered IO after short writes for XFS, direct I/O
> @@ -652,7 +668,8 @@ xfs_file_dax_write(
> error = xfs_setfilesize(ip, pos, ret);
> }
> out:
> - xfs_iunlock(ip, iolock);
> + if (iolock)
> + xfs_iunlock(ip, iolock);
> if (error)
> return error;
>
> --
> 2.29.2
>
next prev parent reply other threads:[~2021-01-11 18:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 16:12 improve sub-block size direct I/O concurrency Christoph Hellwig
2021-01-11 16:12 ` [PATCH 1/3] xfs: factor out a xfs_ilock_iocb helper Christoph Hellwig
2021-01-11 18:55 ` Brian Foster
2021-01-11 16:12 ` [PATCH 2/3] xfs: make xfs_file_aio_write_checks IOCB_NOWAIT-aware Christoph Hellwig
2021-01-11 18:55 ` Brian Foster [this message]
2021-01-11 16:12 ` [PATCH 3/3] xfs: try to avoid the iolock exclusive for non-aligned direct writes Christoph Hellwig
2021-01-11 18:59 ` Brian Foster
2021-01-11 19:14 ` Christoph Hellwig
2021-01-11 19:49 ` Brian Foster
2021-01-11 20:52 ` Dave Chinner
2021-01-11 20:45 ` improve sub-block size direct I/O concurrency Dave Chinner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210111185531.GE1091932@bfoster \
--to=bfoster@redhat.com \
--cc=avi@scylladb.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox