public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH for-next 7/8] io_uring/rsrc: devirtualise rsrc put callbacks
Date: Tue, 18 Apr 2023 14:06:40 +0100	[thread overview]
Message-ID: <02ca727bf8e5f7f820c2f404e95ae88c8f472930.1681822823.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

We only have two rsrc types, buffers and files, replace virtual
callbacks for putting resources down with a switch..case.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/rsrc.c | 25 +++++++++++++++++++------
 io_uring/rsrc.h |  2 +-
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 9378691d49f5..62988b3aa927 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -23,6 +23,8 @@ struct io_rsrc_update {
 	u32				offset;
 };
 
+static void io_rsrc_buf_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
+static void io_rsrc_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
 static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
 				  struct io_mapped_ubuf **pimu,
 				  struct page **last_hpage);
@@ -147,7 +149,18 @@ static void io_rsrc_put_work(struct io_rsrc_node *node)
 
 	if (prsrc->tag)
 		io_post_aux_cqe(data->ctx, prsrc->tag, 0, 0);
-	data->do_put(data->ctx, prsrc);
+
+	switch (data->rsrc_type) {
+	case IORING_RSRC_FILE:
+		io_rsrc_file_put(data->ctx, prsrc);
+		break;
+	case IORING_RSRC_BUFFER:
+		io_rsrc_buf_put(data->ctx, prsrc);
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		break;
+	}
 }
 
 void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
@@ -297,8 +310,8 @@ static __cold void **io_alloc_page_table(size_t size)
 	return table;
 }
 
-__cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
-				     rsrc_put_fn *do_put, u64 __user *utags,
+__cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx, int type,
+				     u64 __user *utags,
 				     unsigned nr, struct io_rsrc_data **pdata)
 {
 	struct io_rsrc_data *data;
@@ -316,7 +329,7 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
 
 	data->nr = nr;
 	data->ctx = ctx;
-	data->do_put = do_put;
+	data->rsrc_type = type;
 	if (utags) {
 		ret = -EFAULT;
 		for (i = 0; i < nr; i++) {
@@ -849,7 +862,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 		return -EMFILE;
 	if (nr_args > rlimit(RLIMIT_NOFILE))
 		return -EMFILE;
-	ret = io_rsrc_data_alloc(ctx, io_rsrc_file_put, tags, nr_args,
+	ret = io_rsrc_data_alloc(ctx, IORING_RSRC_FILE, tags, nr_args,
 				 &ctx->file_data);
 	if (ret)
 		return ret;
@@ -1184,7 +1197,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
 		return -EBUSY;
 	if (!nr_args || nr_args > IORING_MAX_REG_BUFFERS)
 		return -EINVAL;
-	ret = io_rsrc_data_alloc(ctx, io_rsrc_buf_put, tags, nr_args, &data);
+	ret = io_rsrc_data_alloc(ctx, IORING_RSRC_BUFFER, tags, nr_args, &data);
 	if (ret)
 		return ret;
 	ret = io_buffers_map_alloc(ctx, nr_args);
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 232079363f6a..5d0733c4c08d 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -33,7 +33,7 @@ struct io_rsrc_data {
 
 	u64				**tags;
 	unsigned int			nr;
-	rsrc_put_fn			*do_put;
+	u16				rsrc_type;
 	bool				quiesce;
 };
 
-- 
2.40.0


  parent reply	other threads:[~2023-04-18 13:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 13:06 [PATCH for-next 0/8] another round of rsrc refactoring Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 1/8] io_uring/rsrc: remove unused io_rsrc_node::llist Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 2/8] io_uring/rsrc: infer node from ctx on io_queue_rsrc_removal Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 3/8] io_uring/rsrc: merge nodes and io_rsrc_put Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 4/8] io_uring/rsrc: add empty flag in rsrc_node Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 5/8] io_uring/rsrc: inline io_rsrc_put_work() Pavel Begunkov
2023-04-18 13:06 ` [PATCH for-next 6/8] io_uring/rsrc: pass node to io_rsrc_put_work() Pavel Begunkov
2023-04-18 13:06 ` Pavel Begunkov [this message]
2023-04-18 13:06 ` [PATCH for-next 8/8] io_uring/rsrc: disassociate nodes and rsrc_data Pavel Begunkov
2023-04-19  1:39 ` [PATCH for-next 0/8] another round of rsrc refactoring 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 \
    --in-reply-to=02ca727bf8e5f7f820c2f404e95ae88c8f472930.1681822823.git.asml.silence@gmail.com \
    [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