fs/cachefiles/ondemand.c
Source file repositories/reference/linux-study-clean/fs/cachefiles/ondemand.c
File Facts
- System
- Linux kernel
- Corpus path
fs/cachefiles/ondemand.c- Extension
.c- Size
- 20033 bytes
- Lines
- 762
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/anon_inodes.hlinux/uio.hinternal.h
Detected Declarations
struct ondemand_anon_filestruct cachefiles_read_ctxfunction cachefiles_req_putfunction cachefiles_ondemand_fd_releasefunction cachefiles_ondemand_fd_write_iterfunction cachefiles_ondemand_fd_llseekfunction cachefiles_ondemand_fd_ioctlfunction Completionfunction xa_lockfunction cachefiles_ondemand_restorefunction cachefiles_ondemand_get_fdfunction ondemand_object_workerfunction xas_for_each_markedfunction cachefiles_ondemand_finish_reqfunction cachefiles_ondemand_daemon_readfunction cachefiles_ondemand_send_reqfunction cachefiles_ondemand_init_open_reqfunction cachefiles_ondemand_init_close_reqfunction cachefiles_ondemand_init_read_reqfunction cachefiles_ondemand_init_objectfunction cachefiles_ondemand_clean_objectfunction cachefiles_ondemand_init_obj_infofunction cachefiles_ondemand_deinit_obj_infofunction cachefiles_ondemand_read
Annotated Snippet
static const struct file_operations cachefiles_ondemand_fd_fops = {
.owner = THIS_MODULE,
.release = cachefiles_ondemand_fd_release,
.write_iter = cachefiles_ondemand_fd_write_iter,
.llseek = cachefiles_ondemand_fd_llseek,
.unlocked_ioctl = cachefiles_ondemand_fd_ioctl,
};
/*
* OPEN request Completion (copen)
* - command: "copen <id>,<cache_size>"
* <cache_size> indicates the object size if >=0, error code if negative
*/
int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
{
struct cachefiles_req *req;
struct fscache_cookie *cookie;
struct cachefiles_ondemand_info *info;
char *pid, *psize;
unsigned long id;
long size;
int ret;
XA_STATE(xas, &cache->reqs, 0);
if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags))
return -EOPNOTSUPP;
if (!*args) {
pr_err("Empty id specified\n");
return -EINVAL;
}
pid = args;
psize = strchr(args, ',');
if (!psize) {
pr_err("Cache size is not specified\n");
return -EINVAL;
}
*psize = 0;
psize++;
ret = kstrtoul(pid, 0, &id);
if (ret)
return ret;
xa_lock(&cache->reqs);
xas.xa_index = id;
req = xas_load(&xas);
if (!req || req->msg.opcode != CACHEFILES_OP_OPEN ||
!req->object->ondemand->ondemand_id) {
xa_unlock(&cache->reqs);
return -EINVAL;
}
xas_store(&xas, NULL);
xa_unlock(&cache->reqs);
info = req->object->ondemand;
/* fail OPEN request if copen format is invalid */
ret = kstrtol(psize, 0, &size);
if (ret) {
req->error = ret;
goto out;
}
/* fail OPEN request if daemon reports an error */
if (size < 0) {
if (!IS_ERR_VALUE(size)) {
req->error = -EINVAL;
ret = -EINVAL;
} else {
req->error = size;
ret = 0;
}
goto out;
}
spin_lock(&info->lock);
/*
* The anonymous fd was closed before copen ? Fail the request.
*
* t1 | t2
* ---------------------------------------------------------
* cachefiles_ondemand_copen
* req = xa_erase(&cache->reqs, id)
* // Anon fd is maliciously closed.
* cachefiles_ondemand_fd_release
* xa_lock(&cache->reqs)
* cachefiles_ondemand_set_object_close(object)
* xa_unlock(&cache->reqs)
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/uio.h`, `internal.h`.
- Detected declarations: `struct ondemand_anon_file`, `struct cachefiles_read_ctx`, `function cachefiles_req_put`, `function cachefiles_ondemand_fd_release`, `function cachefiles_ondemand_fd_write_iter`, `function cachefiles_ondemand_fd_llseek`, `function cachefiles_ondemand_fd_ioctl`, `function Completion`, `function xa_lock`, `function cachefiles_ondemand_restore`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.