public inbox for [email protected]
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], Gabriel Krisman Bertazi <[email protected]>
Subject: [PATCH v2 7/9] io_uring/rw: Allocate async data through helper
Date: Fri, 22 Nov 2024 16:15:39 -0500	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This abstract away the cache details.

Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
 io_uring/rw.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index b62cdb5fc936..0db9259bcdd8 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -208,33 +208,29 @@ static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
 	}
 }
 
+static void io_rw_async_data_init(void *obj)
+{
+	struct io_async_rw *rw = (struct io_async_rw *)obj;
+
+	rw->free_iovec = 0;
+	rw->bytes_done = 0;
+}
+
 static int io_rw_alloc_async(struct io_kiocb *req)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 	struct io_async_rw *rw;
 
-	rw = io_alloc_cache_get(&ctx->rw_cache);
-	if (rw) {
-		if (rw->free_iovec) {
-			kasan_mempool_unpoison_object(rw->free_iovec,
-				rw->free_iov_nr * sizeof(struct iovec));
-			req->flags |= REQ_F_NEED_CLEANUP;
-		}
-		req->flags |= REQ_F_ASYNC_DATA;
-		req->async_data = rw;
-		goto done;
-	}
-
-	if (!io_alloc_async_data(req)) {
-		rw = req->async_data;
-		rw->free_iovec = NULL;
-		rw->free_iov_nr = 0;
-done:
+	rw = io_uring_alloc_async_data(&ctx->rw_cache, req, io_rw_async_data_init);
+	if (!rw)
+		return -ENOMEM;
+	if (rw->free_iovec) {
+		kasan_mempool_unpoison_object(rw->free_iovec,
+					      rw->free_iov_nr * sizeof(struct iovec));
+		req->flags |= REQ_F_NEED_CLEANUP;
 		rw->bytes_done = 0;
-		return 0;
 	}
-
-	return -ENOMEM;
+	return 0;
 }
 
 static int io_prep_rw_setup(struct io_kiocb *req, int ddir, bool do_import)
-- 
2.47.0


  parent reply	other threads:[~2024-11-22 21:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 2/9] io_uring: Add generic helper to allocate async data Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 3/9] io_uring/futex: Allocate ifd with generic alloc_cache helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 4/9] io_uring/poll: Allocate apoll " Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 5/9] io_uring/uring_cmd: Allocate async data through generic helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 6/9] io_uring/net: Allocate msghdr async data through helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` Gabriel Krisman Bertazi [this message]
2024-11-22 21:15 ` [PATCH v2 8/9] io_uring: Move old async data allocation helper to header Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 9/9] io_uring/msg_ring: Drop custom destructor Gabriel Krisman Bertazi

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] \
    [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