public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>
Subject: [PATCH 03/15] io_uring/net: unify cleanup handling
Date: Tue, 19 Mar 2024 19:17:31 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Now that recv/recvmsg both do the same cleanup, put it in the retry and
finish handlers.

Signed-off-by: Jens Axboe <[email protected]>
---
 io_uring/net.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index ff22f6cc859e..2389bb1cc050 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -690,10 +690,16 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	return 0;
 }
 
-static inline void io_recv_prep_retry(struct io_kiocb *req)
+static inline void io_recv_prep_retry(struct io_kiocb *req,
+				      struct io_async_msghdr *kmsg)
 {
 	struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
 
+	if (kmsg->free_iov) {
+		kfree(kmsg->free_iov);
+		kmsg->free_iov = NULL;
+	}
+
 	req->flags &= ~REQ_F_BL_EMPTY;
 	sr->done_io = 0;
 	sr->len = 0; /* get from the provided buffer */
@@ -725,7 +731,7 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
 		struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
 		int mshot_retry_ret = IOU_ISSUE_SKIP_COMPLETE;
 
-		io_recv_prep_retry(req);
+		io_recv_prep_retry(req, kmsg);
 		/* Known not-empty or unknown state, retry */
 		if (cflags & IORING_CQE_F_SOCK_NONEMPTY || kmsg->msg.msg_inq < 0) {
 			if (sr->nr_multishot_loops++ < MULTISHOT_MAX_RETRY)
@@ -734,10 +740,9 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
 			sr->nr_multishot_loops = 0;
 			mshot_retry_ret = IOU_REQUEUE;
 		}
-		if (issue_flags & IO_URING_F_MULTISHOT)
+		*ret = io_setup_async_msg(req, kmsg, issue_flags);
+		if (*ret == -EAGAIN && issue_flags & IO_URING_F_MULTISHOT)
 			*ret = mshot_retry_ret;
-		else
-			*ret = -EAGAIN;
 		return true;
 	}
 
@@ -748,6 +753,7 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
 		*ret = IOU_STOP_MULTISHOT;
 	else
 		*ret = IOU_OK;
+	io_req_msg_cleanup(req, kmsg, issue_flags);
 	return true;
 }
 
@@ -931,11 +937,6 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
 	if (!io_recv_finish(req, &ret, kmsg, mshot_finished, issue_flags))
 		goto retry_multishot;
 
-	if (mshot_finished)
-		io_req_msg_cleanup(req, kmsg, issue_flags);
-	else if (ret == -EAGAIN)
-		return io_setup_async_msg(req, kmsg, issue_flags);
-
 	return ret;
 }
 
@@ -1037,11 +1038,6 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
 	if (!io_recv_finish(req, &ret, kmsg, ret <= 0, issue_flags))
 		goto retry_multishot;
 
-	if (ret == -EAGAIN)
-		return io_setup_async_msg(req, kmsg, issue_flags);
-	else if (ret != IOU_OK && ret != IOU_STOP_MULTISHOT)
-		io_req_msg_cleanup(req, kmsg, issue_flags);
-
 	return ret;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2024-03-20  1:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20  1:17 [PATCHSET 0/15] Get rid of ->prep_async() Jens Axboe
2024-03-20  1:17 ` [PATCH 01/15] io_uring/net: switch io_send() and io_send_zc() to using io_async_msghdr Jens Axboe
2024-03-20  1:17 ` [PATCH 02/15] io_uring/net: switch io_recv() " Jens Axboe
2024-03-20  1:17 ` Jens Axboe [this message]
2024-03-20  1:17 ` [PATCH 04/15] io_uring/net: always setup an io_async_msghdr Jens Axboe
2024-03-20  1:17 ` [PATCH 05/15] io_uring/net: get rid of ->prep_async() for receive side Jens Axboe
2024-03-20  1:17 ` [PATCH 06/15] io_uring/net: get rid of ->prep_async() for send side Jens Axboe
2024-03-20  1:17 ` [PATCH 07/15] io_uring: kill io_msg_alloc_async_prep() Jens Axboe
2024-03-20  1:17 ` [PATCH 08/15] io_uring/net: add iovec recycling Jens Axboe
2024-03-20  1:17 ` [PATCH 09/15] io_uring/net: drop 'kmsg' parameter from io_req_msg_cleanup() Jens Axboe
2024-03-20  1:17 ` [PATCH 10/15] io_uring/rw: always setup io_async_rw for read/write requests Jens Axboe
2024-03-20  1:17 ` [PATCH 11/15] io_uring: get rid of struct io_rw_state Jens Axboe
2024-03-20  1:17 ` [PATCH 12/15] io_uring/rw: add iovec recycling Jens Axboe
2024-03-20  1:17 ` [PATCH 13/15] io_uring/net: move connect to always using async data Jens Axboe
2024-03-20  1:17 ` [PATCH 14/15] io_uring/uring_cmd: switch to always allocating " Jens Axboe
2024-03-20  1:17 ` [PATCH 15/15] io_uring: drop ->prep_async() Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox