io_uring/timeout.c
Source file repositories/reference/linux-study-clean/io_uring/timeout.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/timeout.c- Extension
.c- Size
- 20086 bytes
- Lines
- 756
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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.hlinux/time_namespace.htrace/events/io_uring.huapi/linux/io_uring.hio_uring.hrefs.hcancel.htimeout.h
Detected Declarations
struct io_timeoutstruct io_timeout_remfunction io_flags_to_clockfunction io_parse_user_timefunction io_is_timeout_noseqfunction io_put_reqfunction io_timeout_finishfunction io_timeout_completefunction io_flush_killed_timeoutsfunction io_kill_timeoutfunction io_flush_timeoutsfunction list_for_each_entry_safefunction io_req_tw_fail_linksfunction io_req_task_completefunction io_fail_linksfunction io_remove_next_linkedfunction io_disarm_nextfunction io_timeout_fnfunction list_for_each_entryfunction io_timeout_cancelfunction io_req_task_link_timeoutfunction io_link_timeout_fnfunction io_req_task_link_timeoutfunction io_timeout_get_clockfunction io_linked_timeout_updatefunction list_for_each_entryfunction io_timeout_updatefunction io_timeout_remove_prepfunction io_translate_timeout_modefunction io_timeout_removefunction __io_timeout_prepfunction io_timeout_prepfunction io_link_timeout_prepfunction io_timeoutfunction io_queue_linked_timeoutfunction io_match_taskfunction io_for_each_linkfunction io_kill_timeouts
Annotated Snippet
struct io_timeout {
struct file *file;
u32 off;
u32 target_seq;
u32 repeats;
struct list_head list;
/* head of the link, used by linked timeouts only */
struct io_kiocb *head;
/* for linked completions */
struct io_kiocb *prev;
};
struct io_timeout_rem {
struct file *file;
u64 addr;
/* timeout update */
ktime_t time;
u32 flags;
bool ltimeout;
};
static clockid_t io_flags_to_clock(unsigned flags)
{
switch (flags & IORING_TIMEOUT_CLOCK_MASK) {
case IORING_TIMEOUT_BOOTTIME:
return CLOCK_BOOTTIME;
case IORING_TIMEOUT_REALTIME:
return CLOCK_REALTIME;
default:
/* can't happen, vetted at prep time */
WARN_ON_ONCE(1);
fallthrough;
case 0:
return CLOCK_MONOTONIC;
}
}
static int io_parse_user_time(ktime_t *time, u64 arg, unsigned flags)
{
struct timespec64 ts;
if (flags & IORING_TIMEOUT_IMMEDIATE_ARG) {
*time = ns_to_ktime(arg);
if (*time < 0)
return -EINVAL;
goto out;
}
if (get_timespec64(&ts, u64_to_user_ptr(arg)))
return -EFAULT;
if (ts.tv_sec < 0 || ts.tv_nsec < 0)
return -EINVAL;
*time = timespec64_to_ktime(ts);
out:
if (flags & IORING_TIMEOUT_ABS)
*time = timens_ktime_to_host(io_flags_to_clock(flags), *time);
return 0;
}
static struct io_kiocb *__io_disarm_linked_timeout(struct io_kiocb *req,
struct io_kiocb *link);
static inline bool io_is_timeout_noseq(struct io_kiocb *req)
{
struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout);
struct io_timeout_data *data = req->async_data;
return !timeout->off || data->flags & IORING_TIMEOUT_MULTISHOT;
}
static inline void io_put_req(struct io_kiocb *req)
{
if (req_ref_put_and_test(req)) {
io_queue_next(req);
io_free_req(req);
}
}
static inline bool io_timeout_finish(struct io_timeout *timeout,
struct io_timeout_data *data)
{
if (!(data->flags & IORING_TIMEOUT_MULTISHOT))
return true;
if (!timeout->off || (timeout->repeats && --timeout->repeats))
return false;
return true;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/file.h`, `linux/io_uring.h`, `linux/time_namespace.h`, `trace/events/io_uring.h`, `uapi/linux/io_uring.h`, `io_uring.h`.
- Detected declarations: `struct io_timeout`, `struct io_timeout_rem`, `function io_flags_to_clock`, `function io_parse_user_time`, `function io_is_timeout_noseq`, `function io_put_req`, `function io_timeout_finish`, `function io_timeout_complete`, `function io_flush_killed_timeouts`, `function io_kill_timeout`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.