io_uring/uring_cmd.c
Source file repositories/reference/linux-study-clean/io_uring/uring_cmd.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/uring_cmd.c- Extension
.c- Size
- 11102 bytes
- Lines
- 409
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/file.hlinux/io_uring/cmd.hlinux/security.hlinux/nospec.huapi/linux/io_uring.hio_uring.halloc_cache.hrsrc.hkbuf.huring_cmd.hpoll.h
Detected Declarations
function io_cmd_cache_freefunction io_req_uring_cleanupfunction io_uring_cmd_cleanupfunction io_uring_try_cancel_uring_cmdfunction hlist_for_each_entry_safefunction io_uring_cmd_del_cancelablefunction io_uring_cmd_mark_cancelablefunction __io_uring_cmd_do_in_taskfunction io_req_set_cqe32_extrafunction __io_uring_cmd_donefunction io_uring_cmd_prepfunction uring_sqe_sizefunction io_uring_cmd_sqe_copyfunction io_uring_cmdfunction io_uring_cmd_import_fixedfunction io_uring_cmd_import_fixed_vecfunction io_uring_cmd_issue_blockingfunction io_cmd_poll_multishotfunction io_uring_cmd_post_mshot_cqe32function io_uring_mshot_cmd_post_cqefunction io_uring_cmd_buffer_selectexport io_uring_cmd_mark_cancelableexport __io_uring_cmd_do_in_taskexport __io_uring_cmd_doneexport io_uring_cmd_import_fixedexport io_uring_cmd_import_fixed_vecexport io_uring_cmd_buffer_selectexport io_uring_mshot_cmd_post_cqe
Annotated Snippet
if (cmd->flags & IORING_URING_CMD_CANCELABLE) {
file->f_op->uring_cmd(cmd, IO_URING_F_CANCEL |
IO_URING_F_COMPLETE_DEFER);
ret = true;
}
}
io_submit_flush_completions(ctx);
return ret;
}
static void io_uring_cmd_del_cancelable(struct io_uring_cmd *cmd,
unsigned int issue_flags)
{
struct io_kiocb *req = cmd_to_io_kiocb(cmd);
struct io_ring_ctx *ctx = req->ctx;
if (!(cmd->flags & IORING_URING_CMD_CANCELABLE))
return;
cmd->flags &= ~IORING_URING_CMD_CANCELABLE;
io_ring_submit_lock(ctx, issue_flags);
hlist_del(&req->hash_node);
io_ring_submit_unlock(ctx, issue_flags);
}
/*
* Mark this command as concelable, then io_uring_try_cancel_uring_cmd()
* will try to cancel this issued command by sending ->uring_cmd() with
* issue_flags of IO_URING_F_CANCEL.
*
* The command is guaranteed to not be done when calling ->uring_cmd()
* with IO_URING_F_CANCEL, but it is driver's responsibility to deal
* with race between io_uring canceling and normal completion.
*/
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
unsigned int issue_flags)
{
struct io_kiocb *req = cmd_to_io_kiocb(cmd);
struct io_ring_ctx *ctx = req->ctx;
/*
* Doing cancelations on IOPOLL requests are not supported. Both
* because they can't get canceled in the block stack, but also
* because iopoll completion data overlaps with the hash_node used
* for tracking.
*/
if (req->flags & REQ_F_IOPOLL)
return;
if (!(cmd->flags & IORING_URING_CMD_CANCELABLE)) {
cmd->flags |= IORING_URING_CMD_CANCELABLE;
io_ring_submit_lock(ctx, issue_flags);
hlist_add_head(&req->hash_node, &ctx->cancelable_uring_cmd);
io_ring_submit_unlock(ctx, issue_flags);
}
}
EXPORT_SYMBOL_GPL(io_uring_cmd_mark_cancelable);
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
io_req_tw_func_t task_work_cb,
unsigned flags)
{
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
if (WARN_ON_ONCE(req->flags & REQ_F_APOLL_MULTISHOT))
return;
req->io_task_work.func = task_work_cb;
__io_req_task_work_add(req, flags);
}
EXPORT_SYMBOL_GPL(__io_uring_cmd_do_in_task);
static inline void io_req_set_cqe32_extra(struct io_kiocb *req,
u64 extra1, u64 extra2)
{
req->big_cqe.extra1 = extra1;
req->big_cqe.extra2 = extra2;
}
/*
* Called by consumers of io_uring_cmd, if they originally returned
* -EIOCBQUEUED upon receiving the command.
*/
void __io_uring_cmd_done(struct io_uring_cmd *ioucmd, s32 ret, u64 res2,
unsigned issue_flags, bool is_cqe32)
{
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
if (WARN_ON_ONCE(req->flags & REQ_F_APOLL_MULTISHOT))
return;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/file.h`, `linux/io_uring/cmd.h`, `linux/security.h`, `linux/nospec.h`, `uapi/linux/io_uring.h`, `io_uring.h`.
- Detected declarations: `function io_cmd_cache_free`, `function io_req_uring_cleanup`, `function io_uring_cmd_cleanup`, `function io_uring_try_cancel_uring_cmd`, `function hlist_for_each_entry_safe`, `function io_uring_cmd_del_cancelable`, `function io_uring_cmd_mark_cancelable`, `function __io_uring_cmd_do_in_task`, `function io_req_set_cqe32_extra`, `function __io_uring_cmd_done`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.