diff mbox series

[for-next,4/4] io_uring: move netmsg recycling into io_uring cleanup

Message ID 20220708181838.1495428-5-dylany@fb.com (mailing list archive)
State New
Headers show
Series io_uring: multishot recv cleanups | expand

Commit Message

Dylan Yudaken July 8, 2022, 6:18 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/io_uring/net.c b/io_uring/net.c
index 997c17512694..c1cbafe96c63 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -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;
diff --git a/io_uring/net.h b/io_uring/net.h
index 576efb602c7f..c5a897e61f10 100644
--- a/io_uring/net.h
+++ b/io_uring/net.h
@@ -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)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index a7b84b43e6c2..b525e37f397a 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -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