* [PATCH v2] Add option to ignore O_NONBLOCK for retry purposes
@ 2021-06-18 22:10 Jens Axboe
2021-06-18 22:10 ` [PATCH] io_uring: add IORING_SETUP_IGNORE_ONONBLOCK flag Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2021-06-18 22:10 UTC (permalink / raw)
To: io-uring; +Cc: samuel
Hi,
After thinking a bit more about this, I think this makes more sense to
do as a setup flag. That means that libraries/applications using it
can have this just in their setup path instead of the hot path, and
it also means that we can save precious space in the sqe flags.
Hence v2 turns this from an sqe flag into a setup flag instead, and
makes the behavior per ring rather than per sqe.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] io_uring: add IORING_SETUP_IGNORE_ONONBLOCK flag
2021-06-18 22:10 [PATCH v2] Add option to ignore O_NONBLOCK for retry purposes Jens Axboe
@ 2021-06-18 22:10 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-06-18 22:10 UTC (permalink / raw)
To: io-uring; +Cc: samuel, Jens Axboe
If a file has O_NONBLOCK set, then io_uring will not arm poll and wait
for data/space if none is available. Instead, -EAGAIN is returned if
an IO attempt is made on the file descriptor.
For library use cases, the library may not be in full control of the
file descriptor, and hence cannot modify file flags through fcntl(2).
Or even if it can, it'd be inefficient and require 3 system calls to
check, set, and re-set.
If a ring is setup with IORING_SETUP_IGNORE_ONONBLOCK, that tells io_uring
to ignore O_NONBLOCK and arm poll to wait for data/space instead, just
like we would have if O_NONBLOCK wasn't set on the file descriptor.
Suggested-by: Samuel Williams <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
---
fs/io_uring.c | 8 +++++---
include/uapi/linux/io_uring.h | 1 +
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index fc8637f591a6..214b8cd297cf 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2686,7 +2686,8 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return ret;
/* don't allow async punt for O_NONBLOCK or RWF_NOWAIT */
- if ((kiocb->ki_flags & IOCB_NOWAIT) || (file->f_flags & O_NONBLOCK))
+ if ((kiocb->ki_flags & IOCB_NOWAIT) ||
+ ((file->f_flags & O_NONBLOCK) && !(ctx->flags & IORING_SETUP_IGNORE_ONONBLOCK)))
req->flags |= REQ_F_NOWAIT;
ioprio = READ_ONCE(sqe->ioprio);
@@ -4709,7 +4710,8 @@ static int io_accept(struct io_kiocb *req, unsigned int issue_flags)
unsigned int file_flags = force_nonblock ? O_NONBLOCK : 0;
int ret;
- if (req->file->f_flags & O_NONBLOCK)
+ if ((req->file->f_flags & O_NONBLOCK) &&
+ !(req->ctx->flags & IORING_SETUP_IGNORE_ONONBLOCK))
req->flags |= REQ_F_NOWAIT;
ret = __sys_accept4_file(req->file, file_flags, accept->addr,
@@ -9755,7 +9757,7 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
if (p.flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |
IORING_SETUP_SQ_AFF | IORING_SETUP_CQSIZE |
IORING_SETUP_CLAMP | IORING_SETUP_ATTACH_WQ |
- IORING_SETUP_R_DISABLED))
+ IORING_SETUP_R_DISABLED | IORING_SETUP_IGNORE_ONONBLOCK))
return -EINVAL;
return io_uring_create(entries, &p, params);
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index f1f9ac114b51..972fa742119b 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -98,6 +98,7 @@ enum {
#define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
#define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */
+#define IORING_SETUP_IGNORE_ONONBLOCK (1U << 7) /* ignore O_NONBLOCK */
enum {
IORING_OP_NOP,
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-18 22:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-18 22:10 [PATCH v2] Add option to ignore O_NONBLOCK for retry purposes Jens Axboe
2021-06-18 22:10 ` [PATCH] io_uring: add IORING_SETUP_IGNORE_ONONBLOCK flag Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox