fs/aio.c
Source file repositories/reference/linux-study-clean/fs/aio.c
File Facts
- System
- Linux kernel
- Corpus path
fs/aio.c- Extension
.c- Size
- 64017 bytes
- Lines
- 2499
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/errno.hlinux/time.hlinux/aio_abi.hlinux/export.hlinux/syscalls.hlinux/backing-dev.hlinux/refcount.hlinux/uio.hlinux/sched/signal.hlinux/fs.hlinux/file.hlinux/mm.hlinux/mman.hlinux/percpu.hlinux/slab.hlinux/timer.hlinux/aio.hlinux/highmem.hlinux/workqueue.hlinux/security.hlinux/eventfd.hlinux/blkdev.hlinux/compat.hlinux/migrate.hlinux/ramfs.hlinux/percpu-refcount.hlinux/mount.hlinux/pseudo_fs.hlinux/uaccess.hlinux/nospec.h
Detected Declarations
syscall io_setupsyscall io_destroysyscall io_submitsyscall io_cancelsyscall io_geteventssyscall io_pgeteventssyscall io_pgetevents_time32syscall io_getevents_time32struct aio_ringstruct kioctx_tablestruct kioctx_cpustruct ctx_rq_waitstruct kioctxstruct fsync_iocbstruct poll_iocbstruct aio_kiocbstruct aio_inode_infostruct aio_waiterstruct aio_poll_tablestruct __aio_sigsetstruct __compat_aio_sigsetfunction aio_sysctl_initfunction aio_free_inodefunction aio_init_fs_contextfunction init_oncefunction aio_setupfunction put_aio_ring_filefunction aio_free_ringfunction aio_ring_mremapfunction aio_ring_mmap_preparefunction aio_migrate_foliofunction aio_setup_ringfunction kiocb_set_cancel_fnfunction free_ioctxfunction free_ioctx_reqsfunction free_ioctx_usersfunction ioctx_add_tablefunction aio_nr_subfunction kill_ioctxfunction exit_aiofunction put_reqs_availablefunction __get_reqs_availablefunction aio_completefunction aio_get_reqfunction get_reqs_availablefunction iocb_destroyfunction aio_completefunction list_for_each_entry_safe
Annotated Snippet
SYSCALL_DEFINE2(io_setup, unsigned, nr_events, aio_context_t __user *, ctxp)
{
struct kioctx *ioctx = NULL;
unsigned long ctx;
long ret;
ret = get_user(ctx, ctxp);
if (unlikely(ret))
goto out;
ret = -EINVAL;
if (unlikely(ctx || nr_events == 0)) {
pr_debug("EINVAL: ctx %lu nr_events %u\n",
ctx, nr_events);
goto out;
}
ioctx = ioctx_alloc(nr_events);
ret = PTR_ERR(ioctx);
if (!IS_ERR(ioctx)) {
ret = put_user(ioctx->user_id, ctxp);
if (ret)
kill_ioctx(current->mm, ioctx, NULL);
percpu_ref_put(&ioctx->users);
}
out:
return ret;
}
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_events, u32 __user *, ctx32p)
{
struct kioctx *ioctx = NULL;
unsigned long ctx;
long ret;
ret = get_user(ctx, ctx32p);
if (unlikely(ret))
goto out;
ret = -EINVAL;
if (unlikely(ctx || nr_events == 0)) {
pr_debug("EINVAL: ctx %lu nr_events %u\n",
ctx, nr_events);
goto out;
}
ioctx = ioctx_alloc(nr_events);
ret = PTR_ERR(ioctx);
if (!IS_ERR(ioctx)) {
/* truncating is ok because it's a user address */
ret = put_user((u32)ioctx->user_id, ctx32p);
if (ret)
kill_ioctx(current->mm, ioctx, NULL);
percpu_ref_put(&ioctx->users);
}
out:
return ret;
}
#endif
/* sys_io_destroy:
* Destroy the aio_context specified. May cancel any outstanding
* AIOs and block on completion. Will fail with -ENOSYS if not
* implemented. May fail with -EINVAL if the context pointed to
* is invalid.
*/
SYSCALL_DEFINE1(io_destroy, aio_context_t, ctx)
{
struct kioctx *ioctx = lookup_ioctx(ctx);
if (likely(NULL != ioctx)) {
struct ctx_rq_wait wait;
int ret;
init_completion(&wait.comp);
atomic_set(&wait.count, 1);
/* Pass requests_done to kill_ioctx() where it can be set
* in a thread-safe way. If we try to set it here then we have
* a race condition if two io_destroy() called simultaneously.
*/
ret = kill_ioctx(current->mm, ioctx, &wait);
percpu_ref_put(&ioctx->users);
/* Wait until all IO for the context are done. Otherwise kernel
* keep using user-space buffers even if user thinks the context
* is destroyed.
*/
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/errno.h`, `linux/time.h`, `linux/aio_abi.h`, `linux/export.h`, `linux/syscalls.h`, `linux/backing-dev.h`.
- Detected declarations: `syscall io_setup`, `syscall io_destroy`, `syscall io_submit`, `syscall io_cancel`, `syscall io_getevents`, `syscall io_pgetevents`, `syscall io_pgetevents_time32`, `syscall io_getevents_time32`, `struct aio_ring`, `struct kioctx_table`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.