@@ -98,18 +98,18 @@ static bool io_net_retry(struct socket *sock, int flags)
return sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET;
}
-static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
+bool io_netmsg_recycle(struct io_kiocb *req)
{
struct io_async_msghdr *hdr = req->async_data;
- if (!hdr || issue_flags & IO_URING_F_UNLOCKED)
- return;
-
if (io_alloc_cache_store(&req->ctx->netmsg_cache)) {
hlist_add_head(&hdr->cache_list, &req->ctx->netmsg_cache.list);
req->async_data = NULL;
req->flags &= ~REQ_F_ASYNC_DATA;
+ return true;
}
+
+ return false;
}
static struct io_async_msghdr *io_recvmsg_alloc_async(struct io_kiocb *req,
@@ -261,7 +261,6 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
if (kmsg->free_iov)
kfree(kmsg->free_iov);
req->flags &= ~REQ_F_NEED_CLEANUP;
- io_netmsg_recycle(req, issue_flags);
if (ret >= 0)
ret += sr->done_io;
else if (sr->done_io)
@@ -583,7 +582,6 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
/* fast path, check for non-NULL to avoid function call */
if (kmsg->free_iov)
kfree(kmsg->free_iov);
- io_netmsg_recycle(req, issue_flags);
req->flags &= ~REQ_F_NEED_CLEANUP;
if (ret > 0)
ret += sr->done_io;
@@ -44,6 +44,7 @@ int io_connect_prep_async(struct io_kiocb *req);
int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
int io_connect(struct io_kiocb *req, unsigned int issue_flags);
+bool io_netmsg_recycle(struct io_kiocb *req);
void io_flush_netmsg_cache(struct io_ring_ctx *ctx);
#else
static inline void io_flush_netmsg_cache(struct io_ring_ctx *ctx)
@@ -153,6 +153,7 @@ const struct io_op_def io_op_defs[] = {
.issue = io_sendmsg,
.prep_async = io_sendmsg_prep_async,
.cleanup = io_sendmsg_recvmsg_cleanup,
+ .recycle_async = io_netmsg_recycle,
#else
.prep = io_eopnotsupp_prep,
#endif
@@ -170,6 +171,7 @@ const struct io_op_def io_op_defs[] = {
.issue = io_recvmsg,
.prep_async = io_recvmsg_prep_async,
.cleanup = io_sendmsg_recvmsg_cleanup,
+ .recycle_async = io_netmsg_recycle,
#else
.prep = io_eopnotsupp_prep,
#endif
Specifically will be useful for multishot as the lifetime of a request is a bit more complicated, but generally makes things a bit neater. Signed-off-by: Dylan Yudaken <dylany@fb.com> --- io_uring/net.c | 10 ++++------ io_uring/net.h | 1 + io_uring/opdef.c | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-)