Skip to content

Commit 3628288

Browse files
committed
io-wq: add io_wq_cancel_pid() to cancel based on a specific pid
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 <[email protected]>
1 parent 00bcda1 commit 3628288

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

fs/io-wq.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,35 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
10291029
return ret;
10301030
}
10311031

1032+
static bool io_wq_pid_match(struct io_wq_work *work, void *data)
1033+
{
1034+
pid_t pid = (pid_t) (unsigned long) data;
1035+
1036+
if (work)
1037+
return work->task_pid == pid;
1038+
return false;
1039+
}
1040+
1041+
enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid)
1042+
{
1043+
struct work_match match = {
1044+
.fn = io_wq_pid_match,
1045+
.data = (void *) (unsigned long) pid
1046+
};
1047+
enum io_wq_cancel ret = IO_WQ_CANCEL_NOTFOUND;
1048+
int node;
1049+
1050+
for_each_node(node) {
1051+
struct io_wqe *wqe = wq->wqes[node];
1052+
1053+
ret = io_wqe_cancel_work(wqe, &match);
1054+
if (ret != IO_WQ_CANCEL_NOTFOUND)
1055+
break;
1056+
}
1057+
1058+
return ret;
1059+
}
1060+
10321061
struct io_wq_flush_data {
10331062
struct io_wq_work work;
10341063
struct completion done;

fs/io-wq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct io_wq_work {
7676
const struct cred *creds;
7777
struct fs_struct *fs;
7878
unsigned flags;
79+
pid_t task_pid;
7980
};
8081

8182
#define INIT_IO_WORK(work, _func) \
@@ -109,6 +110,7 @@ void io_wq_flush(struct io_wq *wq);
109110

110111
void io_wq_cancel_all(struct io_wq *wq);
111112
enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
113+
enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
112114

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

0 commit comments

Comments
 (0)