Commit b745fafa authored by Goldwyn Rodrigues's avatar Goldwyn Rodrigues Committed by Jens Axboe

fs: Introduce RWF_NOWAIT and FMODE_AIO_NOWAIT

RWF_NOWAIT informs kernel to bail out if an AIO request will block
for reasons such as file allocations, or a writeback triggered,
or would block while allocating requests while performing
direct I/O.

RWF_NOWAIT is translated to IOCB_NOWAIT for iocb->ki_flags.

FMODE_AIO_NOWAIT is a flag which identifies the file opened is capable
of returning -EAGAIN if the AIO call will block. This must be set by
supporting filesystems in the ->open() call.

Filesystems xfs, btrfs and ext4 would be supported in the following patches.
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9830f4be
...@@ -1592,6 +1592,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, ...@@ -1592,6 +1592,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
goto out_put_req; goto out_put_req;
} }
if ((req->common.ki_flags & IOCB_NOWAIT) &&
!(req->common.ki_flags & IOCB_DIRECT)) {
ret = -EOPNOTSUPP;
goto out_put_req;
}
ret = put_user(KIOCB_KEY, &user_iocb->aio_key); ret = put_user(KIOCB_KEY, &user_iocb->aio_key);
if (unlikely(ret)) { if (unlikely(ret)) {
pr_debug("EFAULT: aio_key\n"); pr_debug("EFAULT: aio_key\n");
......
...@@ -143,6 +143,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, ...@@ -143,6 +143,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
/* File was opened by fanotify and shouldn't generate fanotify events */ /* File was opened by fanotify and shouldn't generate fanotify events */
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000) #define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
/* File is capable of returning -EAGAIN if AIO will block */
#define FMODE_AIO_NOWAIT ((__force fmode_t)0x8000000)
/* /*
* Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
* that indicates that they should check the contents of the iovec are * that indicates that they should check the contents of the iovec are
...@@ -269,6 +272,7 @@ struct writeback_control; ...@@ -269,6 +272,7 @@ struct writeback_control;
#define IOCB_DSYNC (1 << 4) #define IOCB_DSYNC (1 << 4)
#define IOCB_SYNC (1 << 5) #define IOCB_SYNC (1 << 5)
#define IOCB_WRITE (1 << 6) #define IOCB_WRITE (1 << 6)
#define IOCB_NOWAIT (1 << 7)
struct kiocb { struct kiocb {
struct file *ki_filp; struct file *ki_filp;
...@@ -3064,6 +3068,11 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, int flags) ...@@ -3064,6 +3068,11 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, int flags)
if (unlikely(flags & ~RWF_SUPPORTED)) if (unlikely(flags & ~RWF_SUPPORTED))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (flags & RWF_NOWAIT) {
if (!(ki->ki_filp->f_mode & FMODE_AIO_NOWAIT))
return -EOPNOTSUPP;
ki->ki_flags |= IOCB_NOWAIT;
}
if (flags & RWF_HIPRI) if (flags & RWF_HIPRI)
ki->ki_flags |= IOCB_HIPRI; ki->ki_flags |= IOCB_HIPRI;
if (flags & RWF_DSYNC) if (flags & RWF_DSYNC)
......
...@@ -360,7 +360,9 @@ struct fscrypt_key { ...@@ -360,7 +360,9 @@ struct fscrypt_key {
#define RWF_HIPRI 0x00000001 /* high priority request, poll if possible */ #define RWF_HIPRI 0x00000001 /* high priority request, poll if possible */
#define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */ #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */
#define RWF_SYNC 0x00000004 /* per-IO O_SYNC */ #define RWF_SYNC 0x00000004 /* per-IO O_SYNC */
#define RWF_NOWAIT 0x00000008 /* per-IO, return -EAGAIN if operation would block */
#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC) #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC |\
RWF_NOWAIT)
#endif /* _UAPI_LINUX_FS_H */ #endif /* _UAPI_LINUX_FS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment