io_uring: support MSG_WAITALL for IORING_OP_SEND(MSG)
commit4c3c09439c
upstream. Like commit7ba89d2af1
for recv/recvmsg, support MSG_WAITALL for the send side. If this flag is set and we do a short send, retry for a stream of seqpacket socket. Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
96ccba4a1a
commit
f901b4bfd0
@ -4617,6 +4617,13 @@ static int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET)
|
#if defined(CONFIG_NET)
|
||||||
|
static bool io_net_retry(struct socket *sock, int flags)
|
||||||
|
{
|
||||||
|
if (!(flags & MSG_WAITALL))
|
||||||
|
return false;
|
||||||
|
return sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET;
|
||||||
|
}
|
||||||
|
|
||||||
static int io_setup_async_msg(struct io_kiocb *req,
|
static int io_setup_async_msg(struct io_kiocb *req,
|
||||||
struct io_async_msghdr *kmsg)
|
struct io_async_msghdr *kmsg)
|
||||||
{
|
{
|
||||||
@ -4680,12 +4687,14 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
|||||||
if (req->ctx->compat)
|
if (req->ctx->compat)
|
||||||
sr->msg_flags |= MSG_CMSG_COMPAT;
|
sr->msg_flags |= MSG_CMSG_COMPAT;
|
||||||
#endif
|
#endif
|
||||||
|
sr->done_io = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
|
static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
{
|
{
|
||||||
struct io_async_msghdr iomsg, *kmsg;
|
struct io_async_msghdr iomsg, *kmsg;
|
||||||
|
struct io_sr_msg *sr = &req->sr_msg;
|
||||||
struct socket *sock;
|
struct socket *sock;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
int min_ret = 0;
|
int min_ret = 0;
|
||||||
@ -4716,12 +4725,21 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
|
|||||||
return io_setup_async_msg(req, kmsg);
|
return io_setup_async_msg(req, kmsg);
|
||||||
if (ret == -ERESTARTSYS)
|
if (ret == -ERESTARTSYS)
|
||||||
ret = -EINTR;
|
ret = -EINTR;
|
||||||
|
if (ret > 0 && io_net_retry(sock, flags)) {
|
||||||
|
sr->done_io += ret;
|
||||||
|
req->flags |= REQ_F_PARTIAL_IO;
|
||||||
|
return io_setup_async_msg(req, kmsg);
|
||||||
|
}
|
||||||
req_set_fail(req);
|
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 >= 0)
|
||||||
|
ret += sr->done_io;
|
||||||
|
else if (sr->done_io)
|
||||||
|
ret = sr->done_io;
|
||||||
__io_req_complete(req, issue_flags, ret, 0);
|
__io_req_complete(req, issue_flags, ret, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -4762,8 +4780,19 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
|
|||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
if (ret == -ERESTARTSYS)
|
if (ret == -ERESTARTSYS)
|
||||||
ret = -EINTR;
|
ret = -EINTR;
|
||||||
|
if (ret > 0 && io_net_retry(sock, flags)) {
|
||||||
|
sr->len -= ret;
|
||||||
|
sr->buf += ret;
|
||||||
|
sr->done_io += ret;
|
||||||
|
req->flags |= REQ_F_PARTIAL_IO;
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
req_set_fail(req);
|
req_set_fail(req);
|
||||||
}
|
}
|
||||||
|
if (ret >= 0)
|
||||||
|
ret += sr->done_io;
|
||||||
|
else if (sr->done_io)
|
||||||
|
ret = sr->done_io;
|
||||||
__io_req_complete(req, issue_flags, ret, 0);
|
__io_req_complete(req, issue_flags, ret, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -4911,13 +4940,6 @@ static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool io_net_retry(struct socket *sock, int flags)
|
|
||||||
{
|
|
||||||
if (!(flags & MSG_WAITALL))
|
|
||||||
return false;
|
|
||||||
return sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
|
static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
{
|
{
|
||||||
struct io_async_msghdr iomsg, *kmsg;
|
struct io_async_msghdr iomsg, *kmsg;
|
||||||
|
Reference in New Issue
Block a user