@@ -1546,12 +1546,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
return -EINVAL;
}
- if (unlikely(iocb->aio_rw_flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC))) {
+ if (unlikely(iocb->aio_rw_flags &
+ ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT))) {
pr_debug("EINVAL: aio_rw_flags set with incompatible flags\n");
return -EINVAL;
}
-
/* prevent overflows */
if (unlikely(
(iocb->aio_buf != (unsigned long)iocb->aio_buf) ||
@@ -1598,6 +1598,14 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
req->common.ki_flags |= IOCB_DSYNC;
if (iocb->aio_rw_flags & RWF_SYNC)
req->common.ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+ if (iocb->aio_rw_flags & RWF_NOWAIT) {
+ if (!(iocb->aio_lio_opcode & IOCB_CMD_PWRITE) ||
+ !(req->common.ki_flags & IOCB_DIRECT)) {
+ ret = -EINVAL;
+ goto out_put_req;
+ }
+ req->common.ki_flags |= IOCB_NOWAIT;
+ }
ret = put_user(KIOCB_KEY, &user_iocb->aio_key);
if (unlikely(ret)) {
@@ -270,6 +270,7 @@ struct writeback_control;
#define IOCB_DSYNC (1 << 4)
#define IOCB_SYNC (1 << 5)
#define IOCB_WRITE (1 << 6)
+#define IOCB_NOWAIT (1 << 7)
struct kiocb {
struct file *ki_filp;
@@ -347,5 +347,6 @@ struct fscrypt_policy {
#define RWF_HIPRI 0x00000001 /* high priority request, poll if possible */
#define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */
#define RWF_SYNC 0x00000004 /* per-IO O_SYNC */
+#define RWF_NOWAIT 0x00000008 /* per-IO, return -EAGAIN if operation would block */
#endif /* _UAPI_LINUX_FS_H */