staticint io_async_cancel_one(struct io_uring_task *tctx, struct io_cancel_data *cd)
{ enum io_wq_cancel cancel_ret; int ret = 0; bool all;
if (!tctx || !tctx->io_wq) return -ENOENT;
all = cd->flags & (IORING_ASYNC_CANCEL_ALL|IORING_ASYNC_CANCEL_ANY);
cancel_ret = io_wq_cancel_cb(tctx->io_wq, io_cancel_cb, cd, all); switch (cancel_ret) { case IO_WQ_CANCEL_OK:
ret = 0; break; case IO_WQ_CANCEL_RUNNING:
ret = -EALREADY; break; case IO_WQ_CANCEL_NOTFOUND:
ret = -ENOENT; break;
}
return ret;
}
int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd, unsigned issue_flags)
{ struct io_ring_ctx *ctx = cd->ctx; int ret;
/* fixed must be grabbed every time since we drop the uring_lock */ if ((cd->flags & IORING_ASYNC_CANCEL_FD) &&
(cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) { struct io_rsrc_node *node;
node = io_rsrc_node_lookup(&ctx->file_table.data, fd); if (unlikely(!node)) return -EBADF;
cd->file = io_slot_file(node); if (!cd->file) return -EBADF;
}
if (copy_from_user(&sc, arg, sizeof(sc))) return -EFAULT; if (sc.flags & ~CANCEL_FLAGS) return -EINVAL; for (i = 0; i < ARRAY_SIZE(sc.pad); i++) if (sc.pad[i]) return -EINVAL; for (i = 0; i < ARRAY_SIZE(sc.pad2); i++) if (sc.pad2[i]) return -EINVAL;
/* we can grab a normal file descriptor upfront */ if ((cd.flags & IORING_ASYNC_CANCEL_FD) &&
!(cd.flags & IORING_ASYNC_CANCEL_FD_FIXED)) {
file = fget(sc.fd); if (!file) return -EBADF;
cd.file = file;
}
ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);
/* found something, done! */ if (ret != -EALREADY) goto out;
/* * Keep looking until we get -ENOENT. we'll get woken everytime * every time a request completes and will retry the cancelation.
*/ do {
cd.seq = atomic_inc_return(&ctx->cancel_seq);
ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);
mutex_unlock(&ctx->uring_lock); if (ret != -EALREADY) break;
ret = io_run_task_work_sig(ctx); if (ret < 0) break;
ret = schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS); if (!ret) {
ret = -ETIME; break;
}
mutex_lock(&ctx->uring_lock);
} while (1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.