Commit f3baed39 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: use rsrc prealloc infra for files reg

Keep it consistent with update and use io_rsrc_node_prealloc() +
io_rsrc_node_get() in io_sqe_files_register() as well, that will be used
in future patches, not as error prone and allows to deduplicate
rsrc_node init.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/cf87321e6be5e38f4dc7fe5079d2aa6945b1ace0.1617287883.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 221aa924
...@@ -7623,13 +7623,6 @@ static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx) ...@@ -7623,13 +7623,6 @@ static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
return ref_node; return ref_node;
} }
static void init_fixed_file_ref_node(struct io_ring_ctx *ctx,
struct io_rsrc_node *ref_node)
{
ref_node->rsrc_data = ctx->file_data;
ref_node->rsrc_put = io_ring_file_put;
}
static void io_rsrc_node_destroy(struct io_rsrc_node *ref_node) static void io_rsrc_node_destroy(struct io_rsrc_node *ref_node)
{ {
percpu_ref_exit(&ref_node->refs); percpu_ref_exit(&ref_node->refs);
...@@ -7642,7 +7635,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7642,7 +7635,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
__s32 __user *fds = (__s32 __user *) arg; __s32 __user *fds = (__s32 __user *) arg;
unsigned nr_tables, i; unsigned nr_tables, i;
struct file *file; struct file *file;
int fd, ret = -ENOMEM; int fd, ret;
struct io_rsrc_node *ref_node; struct io_rsrc_node *ref_node;
struct io_rsrc_data *file_data; struct io_rsrc_data *file_data;
...@@ -7652,12 +7645,16 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7652,12 +7645,16 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return -EINVAL; return -EINVAL;
if (nr_args > IORING_MAX_FIXED_FILES) if (nr_args > IORING_MAX_FIXED_FILES)
return -EMFILE; return -EMFILE;
ret = io_rsrc_node_prealloc(ctx);
if (ret)
return ret;
file_data = io_rsrc_data_alloc(ctx); file_data = io_rsrc_data_alloc(ctx);
if (!file_data) if (!file_data)
return -ENOMEM; return -ENOMEM;
ctx->file_data = file_data; ctx->file_data = file_data;
ret = -ENOMEM;
nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE); nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE);
file_data->table = kcalloc(nr_tables, sizeof(*file_data->table), file_data->table = kcalloc(nr_tables, sizeof(*file_data->table),
GFP_KERNEL); GFP_KERNEL);
...@@ -7710,13 +7707,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7710,13 +7707,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return ret; return ret;
} }
ref_node = io_rsrc_node_alloc(ctx); ref_node = io_rsrc_node_get(ctx, ctx->file_data, io_ring_file_put);
if (!ref_node) {
io_sqe_files_unregister(ctx);
return -ENOMEM;
}
init_fixed_file_ref_node(ctx, ref_node);
io_rsrc_node_set(ctx, file_data, ref_node); io_rsrc_node_set(ctx, file_data, ref_node);
return ret; return ret;
out_fput: out_fput:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment