io_uring: add a {task,files} pair matching helper
Add io_match_task() that matches both task and files. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Родитель
06de5f5973
Коммит
08d2363464
|
@ -1039,6 +1039,26 @@ static inline void io_clean_op(struct io_kiocb *req)
|
||||||
__io_clean_op(req);
|
__io_clean_op(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool io_match_task(struct io_kiocb *head,
|
||||||
|
struct task_struct *task,
|
||||||
|
struct files_struct *files)
|
||||||
|
{
|
||||||
|
struct io_kiocb *req;
|
||||||
|
|
||||||
|
if (task && head->task != task)
|
||||||
|
return false;
|
||||||
|
if (!files)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
io_for_each_link(req, head) {
|
||||||
|
if ((req->flags & REQ_F_WORK_INITIALIZED) &&
|
||||||
|
(req->work.flags & IO_WQ_WORK_FILES) &&
|
||||||
|
req->work.identity->files == files)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void io_sq_thread_drop_mm_files(void)
|
static void io_sq_thread_drop_mm_files(void)
|
||||||
{
|
{
|
||||||
struct files_struct *files = current->files;
|
struct files_struct *files = current->files;
|
||||||
|
@ -1687,27 +1707,6 @@ static void io_cqring_mark_overflow(struct io_ring_ctx *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool __io_match_files(struct io_kiocb *req,
|
|
||||||
struct files_struct *files)
|
|
||||||
{
|
|
||||||
return ((req->flags & REQ_F_WORK_INITIALIZED) &&
|
|
||||||
(req->work.flags & IO_WQ_WORK_FILES)) &&
|
|
||||||
req->work.identity->files == files;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool io_match_files(struct io_kiocb *head, struct files_struct *files)
|
|
||||||
{
|
|
||||||
struct io_kiocb *req;
|
|
||||||
|
|
||||||
if (!files)
|
|
||||||
return true;
|
|
||||||
io_for_each_link(req, head) {
|
|
||||||
if (__io_match_files(req, files))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns true if there are no backlogged entries after the flush */
|
/* Returns true if there are no backlogged entries after the flush */
|
||||||
static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force,
|
static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force,
|
||||||
struct task_struct *tsk,
|
struct task_struct *tsk,
|
||||||
|
@ -1735,9 +1734,7 @@ static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force,
|
||||||
|
|
||||||
cqe = NULL;
|
cqe = NULL;
|
||||||
list_for_each_entry_safe(req, tmp, &ctx->cq_overflow_list, compl.list) {
|
list_for_each_entry_safe(req, tmp, &ctx->cq_overflow_list, compl.list) {
|
||||||
if (tsk && req->task != tsk)
|
if (!io_match_task(req, tsk, files))
|
||||||
continue;
|
|
||||||
if (!io_match_files(req, files))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
cqe = io_get_cqring(ctx);
|
cqe = io_get_cqring(ctx);
|
||||||
|
@ -8787,8 +8784,7 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,
|
||||||
|
|
||||||
spin_lock_irq(&ctx->completion_lock);
|
spin_lock_irq(&ctx->completion_lock);
|
||||||
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
|
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
|
||||||
if (io_task_match(de->req, task) &&
|
if (io_match_task(de->req, task, files)) {
|
||||||
io_match_files(de->req, files)) {
|
|
||||||
list_cut_position(&list, &ctx->defer_list, &de->list);
|
list_cut_position(&list, &ctx->defer_list, &de->list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче