summaryrefslogtreecommitdiff
path: root/io_uring/rsrc.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2023-04-11 12:06:07 +0100
committerJens Axboe <axboe@kernel.dk>2023-04-12 12:09:41 -0600
commit2933ae6eaa05e8db6ad33a3ca12af18d2a25358c (patch)
tree7ff931f2b1017b3a02df2e2004b5520c8a92ca95 /io_uring/rsrc.c
parent13c223962eac16f161cf9b6355209774c609af28 (diff)
io_uring/rsrc: refactor io_rsrc_node_switch
We use io_rsrc_node_switch() coupled with io_rsrc_node_switch_start() for a bunch of cases including initialising ctx->rsrc_node, i.e. by passing NULL instead of rsrc_data. Leave it to only deal with actual node changing. For that, first remove it from io_uring_create() and add a function allocating the first node. Then also remove all calls to io_rsrc_node_switch() from files/buffers register as we already have a node installed and it does essentially nothing. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/d146fe306ff98b1a5a60c997c252534f03d423d7.1681210788.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r--io_uring/rsrc.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 329cc3851dfd..f2c660ffea74 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -204,7 +204,7 @@ void io_rsrc_node_ref_zero(struct io_rsrc_node *node)
}
}
-static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
+struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
{
struct io_rsrc_node *ref_node;
struct io_cache_entry *entry;
@@ -231,23 +231,18 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
struct io_rsrc_data *data_to_kill)
__must_hold(&ctx->uring_lock)
{
- WARN_ON_ONCE(io_alloc_cache_empty(&ctx->rsrc_node_cache));
- WARN_ON_ONCE(data_to_kill && !ctx->rsrc_node);
+ struct io_rsrc_node *node = ctx->rsrc_node;
+ struct io_rsrc_node *backup = io_rsrc_node_alloc(ctx);
- if (data_to_kill) {
- struct io_rsrc_node *rsrc_node = ctx->rsrc_node;
-
- rsrc_node->rsrc_data = data_to_kill;
- list_add_tail(&rsrc_node->node, &ctx->rsrc_ref_list);
-
- data_to_kill->refs++;
- /* put master ref */
- io_put_rsrc_node(ctx, rsrc_node);
- ctx->rsrc_node = NULL;
- }
+ if (WARN_ON_ONCE(!backup))
+ return;
- if (!ctx->rsrc_node)
- ctx->rsrc_node = io_rsrc_node_alloc(ctx);
+ data_to_kill->refs++;
+ node->rsrc_data = data_to_kill;
+ list_add_tail(&node->node, &ctx->rsrc_ref_list);
+ /* put master ref */
+ io_put_rsrc_node(ctx, node);
+ ctx->rsrc_node = backup;
}
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
@@ -921,9 +916,6 @@ 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_node_switch_start(ctx);
- if (ret)
- return ret;
ret = io_rsrc_data_alloc(ctx, io_rsrc_file_put, tags, nr_args,
&ctx->file_data);
if (ret)
@@ -978,7 +970,6 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
/* default it to the whole table */
io_file_table_set_alloc_range(ctx, 0, ctx->nr_user_files);
- io_rsrc_node_switch(ctx, NULL);
return 0;
fail:
__io_sqe_files_unregister(ctx);
@@ -1260,9 +1251,6 @@ 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_node_switch_start(ctx);
- if (ret)
- return ret;
ret = io_rsrc_data_alloc(ctx, io_rsrc_buf_put, tags, nr_args, &data);
if (ret)
return ret;
@@ -1300,8 +1288,6 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
ctx->buf_data = data;
if (ret)
__io_sqe_buffers_unregister(ctx);
- else
- io_rsrc_node_switch(ctx, NULL);
return ret;
}