fs/cachefiles/io.c
Source file repositories/reference/linux-study-clean/fs/cachefiles/io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/cachefiles/io.c- Extension
.c- Size
- 21001 bytes
- Lines
- 763
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/mount.hlinux/slab.hlinux/file.hlinux/uio.hlinux/bio.hlinux/falloc.hlinux/sched/mm.htrace/events/fscache.htrace/events/netfs.hinternal.h
Detected Declarations
struct cachefiles_kiocbfunction cachefiles_put_kiocbfunction cachefiles_read_completefunction cachefiles_readfunction cachefiles_query_occupancyfunction cachefiles_write_completefunction __cachefiles_writefunction cachefiles_writefunction cachefiles_do_prepare_readfunction cachefiles_prepare_readfunction cachefiles_prepare_ondemand_readfunction __cachefiles_prepare_writefunction cachefiles_prepare_writefunction cachefiles_prepare_write_subreqfunction cachefiles_issue_writefunction cachefiles_end_operationfunction cachefiles_begin_operation
Annotated Snippet
struct cachefiles_kiocb {
struct kiocb iocb;
refcount_t ki_refcnt;
loff_t start;
union {
size_t skipped;
size_t len;
};
struct cachefiles_object *object;
netfs_io_terminated_t term_func;
void *term_func_priv;
bool was_async;
unsigned int inval_counter; /* Copy of cookie->inval_counter */
u64 b_writing;
};
static inline void cachefiles_put_kiocb(struct cachefiles_kiocb *ki)
{
if (refcount_dec_and_test(&ki->ki_refcnt)) {
cachefiles_put_object(ki->object, cachefiles_obj_put_ioreq);
fput(ki->iocb.ki_filp);
kfree(ki);
}
}
/*
* Handle completion of a read from the cache.
*/
static void cachefiles_read_complete(struct kiocb *iocb, long ret)
{
struct cachefiles_kiocb *ki = container_of(iocb, struct cachefiles_kiocb, iocb);
struct inode *inode = file_inode(ki->iocb.ki_filp);
_enter("%ld", ret);
if (ret < 0)
trace_cachefiles_io_error(ki->object, inode, ret,
cachefiles_trace_read_error);
if (ki->term_func) {
if (ret >= 0) {
if (ki->object->cookie->inval_counter == ki->inval_counter)
ki->skipped += ret;
else
ret = -ESTALE;
}
ki->term_func(ki->term_func_priv, ret);
}
cachefiles_put_kiocb(ki);
}
/*
* Initiate a read from the cache.
*/
static int cachefiles_read(struct netfs_cache_resources *cres,
loff_t start_pos,
struct iov_iter *iter,
enum netfs_read_from_hole read_hole,
netfs_io_terminated_t term_func,
void *term_func_priv)
{
struct cachefiles_object *object;
struct cachefiles_kiocb *ki;
struct file *file;
unsigned int old_nofs;
ssize_t ret = -ENOBUFS;
size_t len = iov_iter_count(iter), skipped = 0;
if (!fscache_wait_for_operation(cres, FSCACHE_WANT_READ))
goto presubmission_error;
fscache_count_read();
object = cachefiles_cres_object(cres);
file = cachefiles_cres_file(cres);
_enter("%pD,%llu,%llx,%zx/%llx",
file, file_inode(file)->i_ino, start_pos, len,
i_size_read(file_inode(file)));
/* If the caller asked us to seek for data before doing the read, then
* we should do that now. If we find a gap, we fill it with zeros.
*/
if (read_hole != NETFS_READ_HOLE_IGNORE) {
loff_t off = start_pos, off2;
off2 = cachefiles_inject_read_error();
if (off2 == 0)
off2 = vfs_llseek(file, off, SEEK_DATA);
Annotation
- Immediate include surface: `linux/mount.h`, `linux/slab.h`, `linux/file.h`, `linux/uio.h`, `linux/bio.h`, `linux/falloc.h`, `linux/sched/mm.h`, `trace/events/fscache.h`.
- Detected declarations: `struct cachefiles_kiocb`, `function cachefiles_put_kiocb`, `function cachefiles_read_complete`, `function cachefiles_read`, `function cachefiles_query_occupancy`, `function cachefiles_write_complete`, `function __cachefiles_write`, `function cachefiles_write`, `function cachefiles_do_prepare_read`, `function cachefiles_prepare_read`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.