Skip to content

Commit 91f9943

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: support RWF_NOWAIT for buffered reads
This is based on the old idea and code from Milosz Tanski. With the aio nowait code it becomes mostly trivial now. Buffered writes continue to return -EOPNOTSUPP if RWF_NOWAIT is passed. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 3239d83 commit 91f9943

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

fs/aio.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,12 +1593,6 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
15931593
goto out_put_req;
15941594
}
15951595

1596-
if ((req->common.ki_flags & IOCB_NOWAIT) &&
1597-
!(req->common.ki_flags & IOCB_DIRECT)) {
1598-
ret = -EOPNOTSUPP;
1599-
goto out_put_req;
1600-
}
1601-
16021596
ret = put_user(KIOCB_KEY, &user_iocb->aio_key);
16031597
if (unlikely(ret)) {
16041598
pr_debug("EFAULT: aio_key\n");

fs/btrfs/file.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,10 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
18861886
loff_t oldsize;
18871887
int clean_page = 0;
18881888

1889+
if (!(iocb->ki_flags & IOCB_DIRECT) &&
1890+
(iocb->ki_flags & IOCB_NOWAIT))
1891+
return -EOPNOTSUPP;
1892+
18891893
if (!inode_trylock(inode)) {
18901894
if (iocb->ki_flags & IOCB_NOWAIT)
18911895
return -EAGAIN;
@@ -3105,7 +3109,7 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int whence)
31053109

31063110
static int btrfs_file_open(struct inode *inode, struct file *filp)
31073111
{
3108-
filp->f_mode |= FMODE_AIO_NOWAIT;
3112+
filp->f_mode |= FMODE_NOWAIT;
31093113
return generic_file_open(inode, filp);
31103114
}
31113115

fs/ext4/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
223223
if (IS_DAX(inode))
224224
return ext4_dax_write_iter(iocb, from);
225225
#endif
226+
if (!o_direct && (iocb->ki_flags & IOCB_NOWAIT))
227+
return -EOPNOTSUPP;
226228

227229
if (!inode_trylock(inode)) {
228230
if (iocb->ki_flags & IOCB_NOWAIT)
@@ -448,9 +450,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
448450
return ret;
449451
}
450452

451-
/* Set the flags to support nowait AIO */
452-
filp->f_mode |= FMODE_AIO_NOWAIT;
453-
453+
filp->f_mode |= FMODE_NOWAIT;
454454
return dquot_file_open(inode, filp);
455455
}
456456

fs/xfs/xfs_file.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ xfs_file_buffered_aio_read(
259259

260260
trace_xfs_file_buffered_read(ip, iov_iter_count(to), iocb->ki_pos);
261261

262-
xfs_ilock(ip, XFS_IOLOCK_SHARED);
262+
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) {
263+
if (iocb->ki_flags & IOCB_NOWAIT)
264+
return -EAGAIN;
265+
xfs_ilock(ip, XFS_IOLOCK_SHARED);
266+
}
263267
ret = generic_file_read_iter(iocb, to);
264268
xfs_iunlock(ip, XFS_IOLOCK_SHARED);
265269

@@ -636,6 +640,9 @@ xfs_file_buffered_aio_write(
636640
int enospc = 0;
637641
int iolock;
638642

643+
if (iocb->ki_flags & IOCB_NOWAIT)
644+
return -EOPNOTSUPP;
645+
639646
write_retry:
640647
iolock = XFS_IOLOCK_EXCL;
641648
xfs_ilock(ip, iolock);
@@ -912,7 +919,7 @@ xfs_file_open(
912919
return -EFBIG;
913920
if (XFS_FORCED_SHUTDOWN(XFS_M(inode->i_sb)))
914921
return -EIO;
915-
file->f_mode |= FMODE_AIO_NOWAIT;
922+
file->f_mode |= FMODE_NOWAIT;
916923
return 0;
917924
}
918925

include/linux/fs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
146146
/* File was opened by fanotify and shouldn't generate fanotify events */
147147
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
148148

149-
/* File is capable of returning -EAGAIN if AIO will block */
150-
#define FMODE_AIO_NOWAIT ((__force fmode_t)0x8000000)
149+
/* File is capable of returning -EAGAIN if I/O will block */
150+
#define FMODE_NOWAIT ((__force fmode_t)0x8000000)
151151

152152
/*
153153
* Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
@@ -3149,7 +3149,7 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, int flags)
31493149
return -EOPNOTSUPP;
31503150

31513151
if (flags & RWF_NOWAIT) {
3152-
if (!(ki->ki_filp->f_mode & FMODE_AIO_NOWAIT))
3152+
if (!(ki->ki_filp->f_mode & FMODE_NOWAIT))
31533153
return -EOPNOTSUPP;
31543154
ki->ki_flags |= IOCB_NOWAIT;
31553155
}

0 commit comments

Comments
 (0)