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

io_uring: split ref_node alloc and init

A simple prep patch allowing to set refnode callbacks after it was
allocated. This needed to 1) keep ourself off of hi-level functions
where it's not pretty and they are not necessary 2) amortise ref_node
allocation in the future, e.g. for updates.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 6802535d
...@@ -1009,8 +1009,10 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx, ...@@ -1009,8 +1009,10 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
struct task_struct *task); struct task_struct *task);
static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node); static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node);
static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node( static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
struct io_ring_ctx *ctx); struct io_ring_ctx *ctx);
static void init_fixed_file_ref_node(struct io_ring_ctx *ctx,
struct fixed_rsrc_ref_node *ref_node);
static void __io_complete_rw(struct io_kiocb *req, long res, long res2, static void __io_complete_rw(struct io_kiocb *req, long res, long res2,
struct io_comp_state *cs); struct io_comp_state *cs);
...@@ -7380,9 +7382,10 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx) ...@@ -7380,9 +7382,10 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
if (!data) if (!data)
return -ENXIO; return -ENXIO;
backup_node = alloc_fixed_file_ref_node(ctx); backup_node = alloc_fixed_rsrc_ref_node(ctx);
if (!backup_node) if (!backup_node)
return -ENOMEM; return -ENOMEM;
init_fixed_file_ref_node(ctx, backup_node);
io_rsrc_ref_lock(ctx); io_rsrc_ref_lock(ctx);
ref_node = data->node; ref_node = data->node;
...@@ -7819,18 +7822,11 @@ static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node( ...@@ -7819,18 +7822,11 @@ static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
return ref_node; return ref_node;
} }
static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node( static void init_fixed_file_ref_node(struct io_ring_ctx *ctx,
struct io_ring_ctx *ctx) struct fixed_rsrc_ref_node *ref_node)
{ {
struct fixed_rsrc_ref_node *ref_node;
ref_node = alloc_fixed_rsrc_ref_node(ctx);
if (!ref_node)
return NULL;
ref_node->rsrc_data = ctx->file_data; ref_node->rsrc_data = ctx->file_data;
ref_node->rsrc_put = io_ring_file_put; ref_node->rsrc_put = io_ring_file_put;
return ref_node;
} }
static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node) static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node)
...@@ -7915,11 +7911,12 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7915,11 +7911,12 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return ret; return ret;
} }
ref_node = alloc_fixed_file_ref_node(ctx); ref_node = alloc_fixed_rsrc_ref_node(ctx);
if (!ref_node) { if (!ref_node) {
io_sqe_files_unregister(ctx); io_sqe_files_unregister(ctx);
return -ENOMEM; return -ENOMEM;
} }
init_fixed_file_ref_node(ctx, ref_node);
io_sqe_rsrc_set_node(ctx, file_data, ref_node); io_sqe_rsrc_set_node(ctx, file_data, ref_node);
return ret; return ret;
...@@ -8022,9 +8019,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, ...@@ -8022,9 +8019,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
if (done > ctx->nr_user_files) if (done > ctx->nr_user_files)
return -EINVAL; return -EINVAL;
ref_node = alloc_fixed_file_ref_node(ctx); ref_node = alloc_fixed_rsrc_ref_node(ctx);
if (!ref_node) if (!ref_node)
return -ENOMEM; return -ENOMEM;
init_fixed_file_ref_node(ctx, ref_node);
done = 0; done = 0;
fds = u64_to_user_ptr(up->data); fds = u64_to_user_ptr(up->data);
......
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