Skip to content

Commit

Permalink
io-wq: add io_wq_cancel_pid() to cancel based on a specific pid
Browse files Browse the repository at this point in the history
Add a helper that allows the caller to cancel work based on what mm
it belongs to. This allows io_uring to cancel work from a given
task or thread when it exits.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Feb 9, 2020
1 parent 00bcda1 commit 3628288
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions fs/io-wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,35 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
return ret;
}

static bool io_wq_pid_match(struct io_wq_work *work, void *data)
{
pid_t pid = (pid_t) (unsigned long) data;

if (work)
return work->task_pid == pid;
return false;
}

enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid)
{
struct work_match match = {
.fn = io_wq_pid_match,
.data = (void *) (unsigned long) pid
};
enum io_wq_cancel ret = IO_WQ_CANCEL_NOTFOUND;
int node;

for_each_node(node) {
struct io_wqe *wqe = wq->wqes[node];

ret = io_wqe_cancel_work(wqe, &match);
if (ret != IO_WQ_CANCEL_NOTFOUND)
break;
}

return ret;
}

struct io_wq_flush_data {
struct io_wq_work work;
struct completion done;
Expand Down
2 changes: 2 additions & 0 deletions fs/io-wq.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct io_wq_work {
const struct cred *creds;
struct fs_struct *fs;
unsigned flags;
pid_t task_pid;
};

#define INIT_IO_WORK(work, _func) \
Expand Down Expand Up @@ -109,6 +110,7 @@ void io_wq_flush(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_pid(struct io_wq *wq, pid_t pid);

typedef bool (work_cancel_fn)(struct io_wq_work *, void *);

Expand Down

0 comments on commit 3628288

Please sign in to comment.