Skip to content

Commit 9b46571

Browse files
isilenceaxboe
authored andcommitted
io_uring: add generic callback_head helpers
We already have helpers to run/add callback_head but taking ctx and working with ctx->exit_task_work. Extract generic versions of them implemented in terms of struct callback_head, it will be used later. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 9e138a4 commit 9b46571

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

fs/io_uring.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,17 +1929,44 @@ static int io_req_task_work_add(struct io_kiocb *req)
19291929
return ret;
19301930
}
19311931

1932-
static void io_req_task_work_add_fallback(struct io_kiocb *req,
1933-
task_work_func_t cb)
1932+
static bool io_run_task_work_head(struct callback_head **work_head)
1933+
{
1934+
struct callback_head *work, *next;
1935+
bool executed = false;
1936+
1937+
do {
1938+
work = xchg(work_head, NULL);
1939+
if (!work)
1940+
break;
1941+
1942+
do {
1943+
next = work->next;
1944+
work->func(work);
1945+
work = next;
1946+
cond_resched();
1947+
} while (work);
1948+
executed = true;
1949+
} while (1);
1950+
1951+
return executed;
1952+
}
1953+
1954+
static void io_task_work_add_head(struct callback_head **work_head,
1955+
struct callback_head *task_work)
19341956
{
1935-
struct io_ring_ctx *ctx = req->ctx;
19361957
struct callback_head *head;
19371958

1938-
init_task_work(&req->task_work, cb);
19391959
do {
1940-
head = READ_ONCE(ctx->exit_task_work);
1941-
req->task_work.next = head;
1942-
} while (cmpxchg(&ctx->exit_task_work, head, &req->task_work) != head);
1960+
head = READ_ONCE(*work_head);
1961+
task_work->next = head;
1962+
} while (cmpxchg(work_head, head, task_work) != head);
1963+
}
1964+
1965+
static void io_req_task_work_add_fallback(struct io_kiocb *req,
1966+
task_work_func_t cb)
1967+
{
1968+
init_task_work(&req->task_work, cb);
1969+
io_task_work_add_head(&req->ctx->exit_task_work, &req->task_work);
19431970
}
19441971

19451972
static void __io_req_task_cancel(struct io_kiocb *req, int error)
@@ -8471,26 +8498,9 @@ static int io_unregister_personality(struct io_ring_ctx *ctx, unsigned id)
84718498
return -EINVAL;
84728499
}
84738500

8474-
static bool io_run_ctx_fallback(struct io_ring_ctx *ctx)
8501+
static inline bool io_run_ctx_fallback(struct io_ring_ctx *ctx)
84758502
{
8476-
struct callback_head *work, *next;
8477-
bool executed = false;
8478-
8479-
do {
8480-
work = xchg(&ctx->exit_task_work, NULL);
8481-
if (!work)
8482-
break;
8483-
8484-
do {
8485-
next = work->next;
8486-
work->func(work);
8487-
work = next;
8488-
cond_resched();
8489-
} while (work);
8490-
executed = true;
8491-
} while (1);
8492-
8493-
return executed;
8503+
return io_run_task_work_head(&ctx->exit_task_work);
84948504
}
84958505

84968506
struct io_tctx_exit {

0 commit comments

Comments
 (0)