Skip to content

Commit

Permalink
io-wq: fix IO_WQ_WORK_NO_CANCEL cancellation
Browse files Browse the repository at this point in the history
To cancel a work, io-wq sets IO_WQ_WORK_CANCEL and executes the
callback. However, IO_WQ_WORK_NO_CANCEL works will just execute and may
return next work, which will be ignored and lost.

Cancel the whole link.

Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
isilence authored and axboe committed Mar 2, 2020
1 parent 98d54f8 commit fc04c39
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions fs/io-wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,17 @@ static bool io_wq_can_queue(struct io_wqe *wqe, struct io_wqe_acct *acct,
return true;
}

static void io_run_cancel(struct io_wq_work *work)
{
do {
struct io_wq_work *old_work = work;

work->flags |= IO_WQ_WORK_CANCEL;
work->func(&work);
work = (work == old_work) ? NULL : work;
} while (work);
}

static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
{
struct io_wqe_acct *acct = io_work_get_acct(wqe, work);
Expand All @@ -760,8 +771,7 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
* It's close enough to not be an issue, fork() has the same delay.
*/
if (unlikely(!io_wq_can_queue(wqe, acct, work))) {
work->flags |= IO_WQ_WORK_CANCEL;
work->func(&work);
io_run_cancel(work);
return;
}

Expand Down Expand Up @@ -900,8 +910,7 @@ static enum io_wq_cancel io_wqe_cancel_cb_work(struct io_wqe *wqe,
spin_unlock_irqrestore(&wqe->lock, flags);

if (found) {
work->flags |= IO_WQ_WORK_CANCEL;
work->func(&work);
io_run_cancel(work);
return IO_WQ_CANCEL_OK;
}

Expand Down Expand Up @@ -976,8 +985,7 @@ static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
spin_unlock_irqrestore(&wqe->lock, flags);

if (found) {
work->flags |= IO_WQ_WORK_CANCEL;
work->func(&work);
io_run_cancel(work);
return IO_WQ_CANCEL_OK;
}

Expand Down

0 comments on commit fc04c39

Please sign in to comment.