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

io_uring: keep a pointer ref_node in file_data

->cur_refs of struct fixed_file_data always points to percpu_ref
embedded into struct fixed_file_ref_node. Don't overuse container_of()
and offsetting, and point directly to fixed_file_ref_node.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 600cf3f8
...@@ -210,7 +210,7 @@ struct fixed_file_data { ...@@ -210,7 +210,7 @@ struct fixed_file_data {
struct fixed_file_table *table; struct fixed_file_table *table;
struct io_ring_ctx *ctx; struct io_ring_ctx *ctx;
struct percpu_ref *cur_refs; struct fixed_file_ref_node *node;
struct percpu_ref refs; struct percpu_ref refs;
struct completion done; struct completion done;
struct list_head ref_list; struct list_head ref_list;
...@@ -5980,7 +5980,7 @@ static struct file *io_file_get(struct io_submit_state *state, ...@@ -5980,7 +5980,7 @@ static struct file *io_file_get(struct io_submit_state *state,
fd = array_index_nospec(fd, ctx->nr_user_files); fd = array_index_nospec(fd, ctx->nr_user_files);
file = io_file_from_index(ctx, fd); file = io_file_from_index(ctx, fd);
if (file) { if (file) {
req->fixed_file_refs = ctx->file_data->cur_refs; req->fixed_file_refs = &ctx->file_data->node->refs;
percpu_ref_get(req->fixed_file_refs); percpu_ref_get(req->fixed_file_refs);
} }
} else { } else {
...@@ -7362,7 +7362,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7362,7 +7362,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return PTR_ERR(ref_node); return PTR_ERR(ref_node);
} }
file_data->cur_refs = &ref_node->refs; file_data->node = ref_node;
spin_lock(&file_data->lock); spin_lock(&file_data->lock);
list_add(&ref_node->node, &file_data->ref_list); list_add(&ref_node->node, &file_data->ref_list);
spin_unlock(&file_data->lock); spin_unlock(&file_data->lock);
...@@ -7432,14 +7432,12 @@ static int io_queue_file_removal(struct fixed_file_data *data, ...@@ -7432,14 +7432,12 @@ static int io_queue_file_removal(struct fixed_file_data *data,
struct file *file) struct file *file)
{ {
struct io_file_put *pfile; struct io_file_put *pfile;
struct percpu_ref *refs = data->cur_refs; struct fixed_file_ref_node *ref_node = data->node;
struct fixed_file_ref_node *ref_node;
pfile = kzalloc(sizeof(*pfile), GFP_KERNEL); pfile = kzalloc(sizeof(*pfile), GFP_KERNEL);
if (!pfile) if (!pfile)
return -ENOMEM; return -ENOMEM;
ref_node = container_of(refs, struct fixed_file_ref_node, refs);
pfile->file = file; pfile->file = file;
list_add(&pfile->list, &ref_node->file_list); list_add(&pfile->list, &ref_node->file_list);
...@@ -7522,10 +7520,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, ...@@ -7522,10 +7520,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
} }
if (needs_switch) { if (needs_switch) {
percpu_ref_kill(data->cur_refs); percpu_ref_kill(&data->node->refs);
spin_lock(&data->lock); spin_lock(&data->lock);
list_add(&ref_node->node, &data->ref_list); list_add(&ref_node->node, &data->ref_list);
data->cur_refs = &ref_node->refs; data->node = ref_node;
spin_unlock(&data->lock); spin_unlock(&data->lock);
percpu_ref_get(&ctx->file_data->refs); percpu_ref_get(&ctx->file_data->refs);
} else } else
......
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