Commit 2a63b2d9 authored by Bijan Mottahedeh's avatar Bijan Mottahedeh Committed by Jens Axboe

io_uring: add rsrc_ref locking routines

Encapsulate resource reference locking into separate routines.
Signed-off-by: default avatarBijan Mottahedeh <bijan.mottahedeh@oracle.com>
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Reviewed-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent d67d2263
...@@ -7350,14 +7350,24 @@ static void io_rsrc_ref_kill(struct percpu_ref *ref) ...@@ -7350,14 +7350,24 @@ static void io_rsrc_ref_kill(struct percpu_ref *ref)
complete(&data->done); complete(&data->done);
} }
static inline void io_rsrc_ref_lock(struct io_ring_ctx *ctx)
{
spin_lock_bh(&ctx->rsrc_ref_lock);
}
static inline void io_rsrc_ref_unlock(struct io_ring_ctx *ctx)
{
spin_unlock_bh(&ctx->rsrc_ref_lock);
}
static void io_sqe_rsrc_set_node(struct io_ring_ctx *ctx, static void io_sqe_rsrc_set_node(struct io_ring_ctx *ctx,
struct fixed_rsrc_data *rsrc_data, struct fixed_rsrc_data *rsrc_data,
struct fixed_rsrc_ref_node *ref_node) struct fixed_rsrc_ref_node *ref_node)
{ {
spin_lock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_lock(ctx);
rsrc_data->node = ref_node; rsrc_data->node = ref_node;
list_add_tail(&ref_node->node, &ctx->rsrc_ref_list); list_add_tail(&ref_node->node, &ctx->rsrc_ref_list);
spin_unlock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_unlock(ctx);
percpu_ref_get(&rsrc_data->refs); percpu_ref_get(&rsrc_data->refs);
} }
...@@ -7374,9 +7384,9 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx) ...@@ -7374,9 +7384,9 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
if (!backup_node) if (!backup_node)
return -ENOMEM; return -ENOMEM;
spin_lock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_lock(ctx);
ref_node = data->node; ref_node = data->node;
spin_unlock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_unlock(ctx);
if (ref_node) if (ref_node)
percpu_ref_kill(&ref_node->refs); percpu_ref_kill(&ref_node->refs);
...@@ -7766,7 +7776,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref) ...@@ -7766,7 +7776,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref)
data = ref_node->rsrc_data; data = ref_node->rsrc_data;
ctx = data->ctx; ctx = data->ctx;
spin_lock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_lock(ctx);
ref_node->done = true; ref_node->done = true;
while (!list_empty(&ctx->rsrc_ref_list)) { while (!list_empty(&ctx->rsrc_ref_list)) {
...@@ -7778,7 +7788,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref) ...@@ -7778,7 +7788,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref)
list_del(&ref_node->node); list_del(&ref_node->node);
first_add |= llist_add(&ref_node->llist, &ctx->rsrc_put_llist); first_add |= llist_add(&ref_node->llist, &ctx->rsrc_put_llist);
} }
spin_unlock_bh(&ctx->rsrc_ref_lock); io_rsrc_ref_unlock(ctx);
if (percpu_ref_is_dying(&data->refs)) if (percpu_ref_is_dying(&data->refs))
delay = 0; delay = 0;
......
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