mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 02:50:43 +00:00
io_uring: improve send/recv error handling
commit 7297ce3d59
upstream.
Hide all error handling under common if block, removes two extra ifs on
the success path and keeps the handling more condensed.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/5761545158a12968f3caf30f747eea65ed75dfc1.1637524285.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
2fd232bbd6
commit
abdc16c836
1 changed files with 31 additions and 24 deletions
|
@ -4706,17 +4706,18 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
min_ret = iov_iter_count(&kmsg->msg.msg_iter);
|
min_ret = iov_iter_count(&kmsg->msg.msg_iter);
|
||||||
|
|
||||||
ret = __sys_sendmsg_sock(sock, &kmsg->msg, flags);
|
ret = __sys_sendmsg_sock(sock, &kmsg->msg, flags);
|
||||||
if ((issue_flags & IO_URING_F_NONBLOCK) && ret == -EAGAIN)
|
|
||||||
return io_setup_async_msg(req, kmsg);
|
|
||||||
if (ret == -ERESTARTSYS)
|
|
||||||
ret = -EINTR;
|
|
||||||
|
|
||||||
|
if (ret < min_ret) {
|
||||||
|
if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
|
||||||
|
return io_setup_async_msg(req, kmsg);
|
||||||
|
if (ret == -ERESTARTSYS)
|
||||||
|
ret = -EINTR;
|
||||||
|
req_set_fail(req);
|
||||||
|
}
|
||||||
/* fast path, check for non-NULL to avoid function call */
|
/* fast path, check for non-NULL to avoid function call */
|
||||||
if (kmsg->free_iov)
|
if (kmsg->free_iov)
|
||||||
kfree(kmsg->free_iov);
|
kfree(kmsg->free_iov);
|
||||||
req->flags &= ~REQ_F_NEED_CLEANUP;
|
req->flags &= ~REQ_F_NEED_CLEANUP;
|
||||||
if (ret < min_ret)
|
|
||||||
req_set_fail(req);
|
|
||||||
__io_req_complete(req, issue_flags, ret, 0);
|
__io_req_complete(req, issue_flags, ret, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4752,13 +4753,13 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
|
|
||||||
msg.msg_flags = flags;
|
msg.msg_flags = flags;
|
||||||
ret = sock_sendmsg(sock, &msg);
|
ret = sock_sendmsg(sock, &msg);
|
||||||
if ((issue_flags & IO_URING_F_NONBLOCK) && ret == -EAGAIN)
|
if (ret < min_ret) {
|
||||||
return -EAGAIN;
|
if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
|
||||||
if (ret == -ERESTARTSYS)
|
return -EAGAIN;
|
||||||
ret = -EINTR;
|
if (ret == -ERESTARTSYS)
|
||||||
|
ret = -EINTR;
|
||||||
if (ret < min_ret)
|
|
||||||
req_set_fail(req);
|
req_set_fail(req);
|
||||||
|
}
|
||||||
__io_req_complete(req, issue_flags, ret, 0);
|
__io_req_complete(req, issue_flags, ret, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4945,10 +4946,15 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
|
|
||||||
ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.umsg,
|
ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.umsg,
|
||||||
kmsg->uaddr, flags);
|
kmsg->uaddr, flags);
|
||||||
if (force_nonblock && ret == -EAGAIN)
|
if (ret < min_ret) {
|
||||||
return io_setup_async_msg(req, kmsg);
|
if (ret == -EAGAIN && force_nonblock)
|
||||||
if (ret == -ERESTARTSYS)
|
return io_setup_async_msg(req, kmsg);
|
||||||
ret = -EINTR;
|
if (ret == -ERESTARTSYS)
|
||||||
|
ret = -EINTR;
|
||||||
|
req_set_fail(req);
|
||||||
|
} else if ((flags & MSG_WAITALL) && (kmsg->msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) {
|
||||||
|
req_set_fail(req);
|
||||||
|
}
|
||||||
|
|
||||||
if (req->flags & REQ_F_BUFFER_SELECTED)
|
if (req->flags & REQ_F_BUFFER_SELECTED)
|
||||||
cflags = io_put_recv_kbuf(req);
|
cflags = io_put_recv_kbuf(req);
|
||||||
|
@ -4956,8 +4962,6 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
if (kmsg->free_iov)
|
if (kmsg->free_iov)
|
||||||
kfree(kmsg->free_iov);
|
kfree(kmsg->free_iov);
|
||||||
req->flags &= ~REQ_F_NEED_CLEANUP;
|
req->flags &= ~REQ_F_NEED_CLEANUP;
|
||||||
if (ret < min_ret || ((flags & MSG_WAITALL) && (kmsg->msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))))
|
|
||||||
req_set_fail(req);
|
|
||||||
__io_req_complete(req, issue_flags, ret, cflags);
|
__io_req_complete(req, issue_flags, ret, cflags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5004,15 +5008,18 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
min_ret = iov_iter_count(&msg.msg_iter);
|
min_ret = iov_iter_count(&msg.msg_iter);
|
||||||
|
|
||||||
ret = sock_recvmsg(sock, &msg, flags);
|
ret = sock_recvmsg(sock, &msg, flags);
|
||||||
if (force_nonblock && ret == -EAGAIN)
|
|
||||||
return -EAGAIN;
|
|
||||||
if (ret == -ERESTARTSYS)
|
|
||||||
ret = -EINTR;
|
|
||||||
out_free:
|
out_free:
|
||||||
|
if (ret < min_ret) {
|
||||||
|
if (ret == -EAGAIN && force_nonblock)
|
||||||
|
return -EAGAIN;
|
||||||
|
if (ret == -ERESTARTSYS)
|
||||||
|
ret = -EINTR;
|
||||||
|
req_set_fail(req);
|
||||||
|
} else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) {
|
||||||
|
req_set_fail(req);
|
||||||
|
}
|
||||||
if (req->flags & REQ_F_BUFFER_SELECTED)
|
if (req->flags & REQ_F_BUFFER_SELECTED)
|
||||||
cflags = io_put_recv_kbuf(req);
|
cflags = io_put_recv_kbuf(req);
|
||||||
if (ret < min_ret || ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))))
|
|
||||||
req_set_fail(req);
|
|
||||||
__io_req_complete(req, issue_flags, ret, cflags);
|
__io_req_complete(req, issue_flags, ret, cflags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue