io_uring/rsrc: simplify single file node switching

At maximum io_install_fixed_file() removes only one file, so no need to
keep needs_switch state and we can call io_rsrc_node_switch() right after
removal.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/37cfb46f46160f81dced79f646e97db608994574.1681395792.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Pavel Begunkov 2023-04-13 15:28:13 +01:00 committed by Jens Axboe
parent 9a57fffedc
commit c87fd583f3

View File

@ -64,7 +64,6 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
u32 slot_index) u32 slot_index)
__must_hold(&req->ctx->uring_lock) __must_hold(&req->ctx->uring_lock)
{ {
bool needs_switch = false;
struct io_fixed_file *file_slot; struct io_fixed_file *file_slot;
int ret; int ret;
@ -83,16 +82,17 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
ret = io_rsrc_node_switch_start(ctx); ret = io_rsrc_node_switch_start(ctx);
if (ret) if (ret)
goto err; return ret;
old_file = (struct file *)(file_slot->file_ptr & FFS_MASK); old_file = (struct file *)(file_slot->file_ptr & FFS_MASK);
ret = io_queue_rsrc_removal(ctx->file_data, slot_index, ret = io_queue_rsrc_removal(ctx->file_data, slot_index,
ctx->rsrc_node, old_file); ctx->rsrc_node, old_file);
if (ret) if (ret)
goto err; return ret;
file_slot->file_ptr = 0; file_slot->file_ptr = 0;
io_file_bitmap_clear(&ctx->file_table, slot_index); io_file_bitmap_clear(&ctx->file_table, slot_index);
needs_switch = true; io_rsrc_node_switch(ctx, ctx->file_data);
} }
ret = io_scm_file_account(ctx, file); ret = io_scm_file_account(ctx, file);
@ -101,9 +101,6 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
io_fixed_file_set(file_slot, file); io_fixed_file_set(file_slot, file);
io_file_bitmap_set(&ctx->file_table, slot_index); io_file_bitmap_set(&ctx->file_table, slot_index);
} }
err:
if (needs_switch)
io_rsrc_node_switch(ctx, ctx->file_data);
return ret; return ret;
} }