Split alloc_fixed_file_ref_node into resource generic/specific parts, rename destroy_fixed_file_ref_node, and factor out fixed_file_ref_node switching, to be be leveraged by fixed buffers. Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@xxxxxxxxxx> --- fs/io_uring.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 28e178b..e23f67f 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7672,7 +7672,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref) queue_delayed_work(system_wq, &ctx->rsrc_put_work, delay); } -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 fixed_rsrc_ref_node *ref_node; @@ -7688,9 +7688,21 @@ static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node( } INIT_LIST_HEAD(&ref_node->node); INIT_LIST_HEAD(&ref_node->rsrc_list); + ref_node->done = false; + return ref_node; +} + +static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node( + struct io_ring_ctx *ctx) +{ + 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_put = io_ring_file_put; - ref_node->done = false; return ref_node; } @@ -7870,6 +7882,17 @@ static inline int io_queue_file_removal(struct fixed_rsrc_data *data, return io_queue_rsrc_removal(data, (void *)file); } +static void switch_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node, + struct fixed_rsrc_data *data, + struct io_ring_ctx *ctx) +{ + percpu_ref_kill(&data->node->refs); + spin_lock_bh(&ctx->rsrc_ref_lock); + list_add_tail(&ref_node->node, &ctx->rsrc_ref_list); + data->node = ref_node; + spin_unlock_bh(&ctx->rsrc_ref_lock); +} + static int __io_sqe_files_update(struct io_ring_ctx *ctx, struct io_uring_rsrc_update *up, unsigned nr_args) @@ -7946,11 +7969,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, } if (needs_switch) { - percpu_ref_kill(&data->node->refs); - spin_lock_bh(&ctx->rsrc_ref_lock); - list_add_tail(&ref_node->node, &ctx->rsrc_ref_list); - data->node = ref_node; - spin_unlock_bh(&ctx->rsrc_ref_lock); + switch_fixed_rsrc_ref_node(ref_node, data, ctx); percpu_ref_get(&ctx->file_data->refs); } else destroy_fixed_rsrc_ref_node(ref_node); -- 1.8.3.1