Commit 44e728b8 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: cancel all task's requests on exit

If a process is going away, io_uring_flush() will cancel only 1
request with a matching pid. Cancel all of them
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4f26bda1
...@@ -1018,20 +1018,6 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork) ...@@ -1018,20 +1018,6 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
return io_wq_cancel_cb(wq, io_wq_io_cb_cancel_data, (void *)cwork, false); return io_wq_cancel_cb(wq, io_wq_io_cb_cancel_data, (void *)cwork, false);
} }
static bool io_wq_pid_match(struct io_wq_work *work, void *data)
{
pid_t pid = (pid_t) (unsigned long) data;
return work->task_pid == pid;
}
enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid)
{
void *data = (void *) (unsigned long) pid;
return io_wq_cancel_cb(wq, io_wq_pid_match, data, false);
}
struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data) struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
{ {
int ret = -ENOMEM, node; int ret = -ENOMEM, node;
......
...@@ -125,7 +125,6 @@ static inline bool io_wq_is_hashed(struct io_wq_work *work) ...@@ -125,7 +125,6 @@ static inline bool io_wq_is_hashed(struct io_wq_work *work)
void io_wq_cancel_all(struct io_wq *wq); void io_wq_cancel_all(struct io_wq *wq);
enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork); enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
typedef bool (work_cancel_fn)(struct io_wq_work *, void *); typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
......
...@@ -7424,6 +7424,13 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx, ...@@ -7424,6 +7424,13 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
} }
} }
static bool io_cancel_pid_cb(struct io_wq_work *work, void *data)
{
pid_t pid = (pid_t) (unsigned long) data;
return work->task_pid == pid;
}
static int io_uring_flush(struct file *file, void *data) static int io_uring_flush(struct file *file, void *data)
{ {
struct io_ring_ctx *ctx = file->private_data; struct io_ring_ctx *ctx = file->private_data;
...@@ -7433,8 +7440,11 @@ static int io_uring_flush(struct file *file, void *data) ...@@ -7433,8 +7440,11 @@ static int io_uring_flush(struct file *file, void *data)
/* /*
* If the task is going away, cancel work it may have pending * If the task is going away, cancel work it may have pending
*/ */
if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) {
io_wq_cancel_pid(ctx->io_wq, task_pid_vnr(current)); void *data = (void *) (unsigned long)task_pid_vnr(current);
io_wq_cancel_cb(ctx->io_wq, io_cancel_pid_cb, data, true);
}
return 0; return 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