xfs: Add async buffered write support
authorStefan Roesch <shr@fb.com>
Thu, 23 Jun 2022 17:51:57 +0000 (10:51 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Jul 2022 00:39:32 +0000 (18:39 -0600)
This adds the async buffered write support to XFS. For async buffered
write requests, the request will return -EAGAIN if the ilock cannot be
obtained immediately.

Signed-off-by: Stefan Roesch <shr@fb.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20220623175157.1715274-15-shr@fb.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/xfs/xfs_file.c
fs/xfs/xfs_iomap.c

index 5a171c0..8d9b14d 100644 (file)
@@ -410,7 +410,7 @@ restart:
                spin_unlock(&ip->i_flags_lock);
 
 out:
-       return file_modified(file);
+       return kiocb_modified(iocb);
 }
 
 static int
@@ -700,12 +700,11 @@ xfs_file_buffered_write(
        bool                    cleared_space = false;
        unsigned int            iolock;
 
-       if (iocb->ki_flags & IOCB_NOWAIT)
-               return -EOPNOTSUPP;
-
 write_retry:
        iolock = XFS_IOLOCK_EXCL;
-       xfs_ilock(ip, iolock);
+       ret = xfs_ilock_iocb(iocb, iolock);
+       if (ret)
+               return ret;
 
        ret = xfs_file_write_checks(iocb, from, &iolock);
        if (ret)
@@ -1165,7 +1164,7 @@ xfs_file_open(
 {
        if (xfs_is_shutdown(XFS_M(inode->i_sb)))
                return -EIO;
-       file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC;
+       file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC | FMODE_BUF_WASYNC;
        return generic_file_open(inode, file);
 }
 
index bcf7c36..5d50fed 100644 (file)
@@ -886,6 +886,7 @@ xfs_buffered_write_iomap_begin(
        bool                    eof = false, cow_eof = false, shared = false;
        int                     allocfork = XFS_DATA_FORK;
        int                     error = 0;
+       unsigned int            lockmode = XFS_ILOCK_EXCL;
 
        if (xfs_is_shutdown(mp))
                return -EIO;
@@ -897,7 +898,9 @@ xfs_buffered_write_iomap_begin(
 
        ASSERT(!XFS_IS_REALTIME_INODE(ip));
 
-       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       error = xfs_ilock_for_iomap(ip, flags, &lockmode);
+       if (error)
+               return error;
 
        if (XFS_IS_CORRUPT(mp, !xfs_ifork_has_extents(&ip->i_df)) ||
            XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BMAPIFORMAT)) {