summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2020-11-06 13:00:23 +0000
committerJens Axboe <axboe@kernel.dk>2020-12-09 12:04:00 -0700
commitdf9923f96717d0aebb0a73adbcf6285fa79e38cb (patch)
treed11fdd48df051495601f17c3fc831b4d490f34bb /fs
parent08d23634643c239ddae706758f54d3a8e0c24962 (diff)
downloadlinux-df9923f96717d0aebb0a73adbcf6285fa79e38cb.tar.gz
linux-df9923f96717d0aebb0a73adbcf6285fa79e38cb.tar.bz2
linux-df9923f96717d0aebb0a73adbcf6285fa79e38cb.zip
io_uring: cancel only requests of current task
io_uring_cancel_files() cancels all request that match files regardless of task. There is no real need in that, cancel only requests of the specified task. That also handles SQPOLL case as it already changes task to it. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r--fs/io_uring.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 35828af37065..c42fd31cb314 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8665,14 +8665,6 @@ static int io_uring_release(struct inode *inode, struct file *file)
return 0;
}
-static bool io_wq_files_match(struct io_wq_work *work, void *data)
-{
- struct files_struct *files = data;
-
- return !files || ((work->flags & IO_WQ_WORK_FILES) &&
- work->identity->files == files);
-}
-
/*
* Returns true if 'preq' is the link parent of 'req'
*/
@@ -8805,21 +8797,20 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,
* Returns true if we found and killed one or more files pinning requests
*/
static bool io_uring_cancel_files(struct io_ring_ctx *ctx,
+ struct task_struct *task,
struct files_struct *files)
{
if (list_empty_careful(&ctx->inflight_list))
return false;
- /* cancel all at once, should be faster than doing it one by one*/
- io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);
-
while (!list_empty_careful(&ctx->inflight_list)) {
struct io_kiocb *cancel_req = NULL, *req;
DEFINE_WAIT(wait);
spin_lock_irq(&ctx->inflight_lock);
list_for_each_entry(req, &ctx->inflight_list, inflight_entry) {
- if (files && (req->work.flags & IO_WQ_WORK_FILES) &&
+ if (req->task == task &&
+ (req->work.flags & IO_WQ_WORK_FILES) &&
req->work.identity->files != files)
continue;
/* req is being completed, ignore */
@@ -8862,7 +8853,7 @@ static bool __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
{
bool ret;
- ret = io_uring_cancel_files(ctx, files);
+ ret = io_uring_cancel_files(ctx, task, files);
if (!files) {
enum io_wq_cancel cret;
@@ -8901,11 +8892,7 @@ static void io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
io_sq_thread_park(ctx->sq_data);
}
- if (files)
- io_cancel_defer_files(ctx, NULL, files);
- else
- io_cancel_defer_files(ctx, task, NULL);
-
+ io_cancel_defer_files(ctx, task, files);
io_cqring_overflow_flush(ctx, true, task, files);
while (__io_uring_cancel_task_requests(ctx, task, files)) {