improve multishot error codes
cover improve multishot error codes
Unify error codes between normal execution path and multishot. It's a dependency for other work, but it should stand well as independent cleanups.
Pavel Begunkov (2):
io_uring: return -EAGAIN to continue multishot
io_uring: unify STOP_MULTISHOT with IOU_OK
io_uring/io_uring.c | 5 +--- io_uring/io_uring.h | 19 +++++++------ io_uring/net.c | 66 +++++++++++++-------------------------------- io_uring/poll.c | 5 ++-- io_uring/rw.c | 15 ++++------- 5 files changed, 38 insertions(+), 72 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/2 io_uring: return -EAGAIN to continue multishot
Multishot errors can be mapped 1:1 to normal errors, but there are not identical. It leads to a peculiar situation where all multishot requests has to check in what context they're run and return different codes.
Unify them starting with EAGAIN / IOU_ISSUE_SKIP_COMPLETE(EIOCBQUEUED) pair, which mean that core io_uring still owns the request and it should be retried. In case of multishot it's naturally just continues to poll, otherwise it might poll, use iowq or do any other kind of allowed blocking. Introduce IOU_RETRY aliased to -EAGAIN for that.
Apart from obvious upsides, multishot can now also check for misuse of IOU_ISSUE_SKIP_COMPLETE.
--- io_uring/io_uring.c | 4 +--- io_uring/io_uring.h | 8 ++++++++ io_uring/net.c | 47 ++++++++++++++------------------------------- io_uring/poll.c | 3 ++- io_uring/rw.c | 11 ++++------- 5 files changed, 29 insertions(+), 44 deletions(-)
io_uring/io_uring.c +1 -3
@@ -1791,10 +1791,8 @@ int io_poll_issue(struct io_kiocb *req, io_tw_token_t tw) ret =__io_issue_sqe (req, issue_flags, &io_issue_defs[req->opcode]); +WARN_ON_ONCE (ret ==IOU_ISSUE_SKIP_COMPLETE );WARN_ON_ONCE (ret ==IOU_OK ); - -if (ret ==IOU_ISSUE_SKIP_COMPLETE ) - ret =0 ;return ret; }
io_uring/io_uring.h +8 -0
@@ -22,6 +22,14 @@ enum {IOU_OK =0 ,IOU_ISSUE_SKIP_COMPLETE = -EIOCBQUEUED , +/* +* The request has more work to do and should be retried. io_uring will +* attempt to wait on the file for eligible opcodes, but otherwise +* it'll be handed to iowq for blocking execution. It works for normal +* requests as well as for the multi shot mode. +*/ +IOU_RETRY = -EAGAIN , +/* * Requeue the task_work to restart operations on this request. The * actual value isn't important, should just be not an otherwise
io_uring/net.c +14 -33
97 lines not on this page · raw message
io_uring/poll.c +2 -1
@@ -289,11 +289,12 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw) } }else {int ret =io_poll_issue (req, tw); +if (ret ==IOU_STOP_MULTISHOT )return IOU_POLL_REMOVE_POLL_USE_RES ;else if (ret ==IOU_REQUEUE )return IOU_POLL_REQUEUE ; -if (ret <0 ) +if (ret !=IOU_RETRY && ret <0 )return ret; }
io_uring/rw.c +4 -7
@@ -1068,9 +1068,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)*/ if (io_kbuf_recycle (req, issue_flags)) rw->len =0 ; -if (issue_flags &IO_URING_F_MULTISHOT ) -return IOU_ISSUE_SKIP_COMPLETE ; -return -EAGAIN ; +return IOU_RETRY ; }else if (ret <=0 ) {io_kbuf_recycle (req, issue_flags);if (ret <0 )
@@ -1088,16 +1086,15 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags) rw->len =0 ;/* similarly to above, reset len to 0 */ if (io_req_post_cqe (req, ret, cflags |IORING_CQE_F_MORE )) { -if (issue_flags &IO_URING_F_MULTISHOT ) { +if (issue_flags &IO_URING_F_MULTISHOT )/* * Force retry, as we might have more data to * be read and otherwise it won't get retried * until (if ever) another poll is triggered. */ io_poll_multishot_retry (req); -return IOU_ISSUE_SKIP_COMPLETE ; - } -return -EAGAIN ; + +return IOU_RETRY ; } }
Signature · 1 line
2.48.1
PATCH 2/2 io_uring: unify STOP_MULTISHOT with IOU_OK
In reply to Pavel BegunkovIOU_OK means that the request ownership is now handed back to core io_uring and it has to complete it using the result provided in req->cqe. Same is true for multishot and IOU_STOP_MULTISHOT.
Rename it into IOU_COMPLETE to avoid confusion and use for both modes.
--- io_uring/io_uring.c | 1 - io_uring/io_uring.h | 11 +++-------- io_uring/net.c | 19 ++++--------------- io_uring/poll.c | 2 +- io_uring/rw.c | 4 +--- 5 files changed, 9 insertions(+), 28 deletions(-)
io_uring/io_uring.c +0 -1
@@ -1792,7 +1792,6 @@ int io_poll_issue(struct io_kiocb *req, io_tw_token_t tw) ret =__io_issue_sqe (req, issue_flags, &io_issue_defs[req->opcode]);WARN_ON_ONCE (ret ==IOU_ISSUE_SKIP_COMPLETE ); -WARN_ON_ONCE (ret ==IOU_OK );return ret; }
io_uring/io_uring.h +3 -8
@@ -19,7 +19,9 @@#endif enum { -IOU_OK =0 , +IOU_OK =0 ,/* deprecated, use IOU_COMPLETE */ +IOU_COMPLETE =0 , +IOU_ISSUE_SKIP_COMPLETE = -EIOCBQUEUED ,/*
@@ -36,13 +38,6 @@ enum {* valid error code, yet less than -MAX_ERRNO and valid internally. */ IOU_REQUEUE = -3072, - -/* -* Intended only when both IO_URING_F_MULTISHOT is passed -* to indicate to the poll runner that multishot should be -* removed and the result is set on req->cqe.res. -*/ - IOU_STOP_MULTISHOT = -ECANCELED, };struct io_wait_queue {
io_uring/net.c +4 -15
@@ -915,11 +915,7 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,/* Finish the request / stop multishot. */ finish:io_req_set_res (req, *ret, cflags); - -if (issue_flags &IO_URING_F_MULTISHOT ) - *ret =IOU_STOP_MULTISHOT ; -else - *ret =IOU_OK ; + *ret =IOU_COMPLETE ;io_req_msg_cleanup (req, issue_flags);return true; }
@@ -1288,9 +1284,7 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags)if (len && zc->len ==0 ) {io_req_set_res (req,0 ,0 ); -if (issue_flags &IO_URING_F_MULTISHOT ) -return IOU_STOP_MULTISHOT ; -return IOU_OK ; +return IOU_COMPLETE ; }if (unlikely (ret <=0 ) && ret != -EAGAIN ) {if (ret == -ERESTARTSYS )
@@ -1300,10 +1294,7 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags)req_set_fail (req);io_req_set_res (req, ret,0 ); - -if (issue_flags &IO_URING_F_MULTISHOT ) -return IOU_STOP_MULTISHOT ; -return IOU_OK ; +return IOU_COMPLETE ; }return IOU_RETRY ; }
@@ -1709,9 +1700,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)io_req_set_res (req, ret, cflags);if (ret <0 )req_set_fail (req); -if (!(issue_flags &IO_URING_F_MULTISHOT )) -return IOU_OK ; -return IOU_STOP_MULTISHOT ; +return IOU_COMPLETE ; }int io_socket_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe)
io_uring/poll.c +1 -1
@@ -290,7 +290,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw) }else {int ret =io_poll_issue (req, tw); -if (ret ==IOU_STOP_MULTISHOT ) +if (ret ==IOU_COMPLETE )return IOU_POLL_REMOVE_POLL_USE_RES ;else if (ret ==IOU_REQUEUE )return IOU_POLL_REQUEUE ;
io_uring/rw.c +1 -3
@@ -1104,9 +1104,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)*/ io_req_set_res (req, ret, cflags);io_req_rw_cleanup (req, issue_flags); -if (issue_flags &IO_URING_F_MULTISHOT ) -return IOU_STOP_MULTISHOT ; -return IOU_OK ; +return IOU_COMPLETE ; }static bool io_kiocb_start_write (struct io_kiocb *req,struct kiocb *kiocb)
Signature · 1 line
2.48.1
Quoted 9 lines · Pavel Begunkov
Unify error codes between normal execution path and multishot. It's a dependency for other work, but it should stand well as independent cleanups.
Pavel Begunkov (2):
io_uring: return-EAGAINto continue multishot
io_uring: unifySTOP_MULTISHOTwithIOU_OK[...]
Applied, thanks!
[1/2] io_uring: return -EAGAIN to continue multishot
commit: 7a9dcb05f5501b07a2ef7d0ef743f4f17e9f3055
[2/2] io_uring: unify STOP_MULTISHOT with IOU_OK
commit: 5027d02452c982bdc7b36205c66466ebd7e6ee17Best regards,
Signature · 1 line
Jens Axboe