fs/netfs/fscache_cache.c
Source file repositories/reference/linux-study-clean/fs/netfs/fscache_cache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/netfs/fscache_cache.c- Extension
.c- Size
- 12429 bytes
- Lines
- 430
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/slab.hinternal.h
Detected Declarations
function fscache_get_cache_maybefunction list_for_each_entryfunction list_for_each_entryfunction fscache_put_cachefunction fscache_relinquish_cachefunction fscache_add_cachefunction fscache_begin_cache_accessfunction fscache_end_cache_accessfunction fscache_io_errorfunction fscache_withdraw_cachefunction fscache_caches_seq_showfunction fscache_caches_seq_stopexport fscache_addremove_semexport fscache_clearance_waitersexport fscache_acquire_cacheexport fscache_relinquish_cacheexport fscache_add_cacheexport fscache_io_errorexport fscache_withdraw_cache
Annotated Snippet
if (name) {
cache->name = kstrdup(name, GFP_KERNEL);
if (!cache->name) {
kfree(cache);
return NULL;
}
}
refcount_set(&cache->ref, 1);
INIT_LIST_HEAD(&cache->cache_link);
cache->debug_id = atomic_inc_return(&fscache_cache_debug_id);
}
return cache;
}
static bool fscache_get_cache_maybe(struct fscache_cache *cache,
enum fscache_cache_trace where)
{
bool success;
int ref;
success = __refcount_inc_not_zero(&cache->ref, &ref);
if (success)
trace_fscache_cache(cache->debug_id, ref + 1, where);
return success;
}
/*
* Look up a cache cookie.
*/
struct fscache_cache *fscache_lookup_cache(const char *name, bool is_cache)
{
struct fscache_cache *candidate, *cache, *unnamed = NULL;
/* firstly check for the existence of the cache under read lock */
down_read(&fscache_addremove_sem);
list_for_each_entry(cache, &fscache_caches, cache_link) {
if (cache->name && name && strcmp(cache->name, name) == 0 &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_r;
if (!cache->name && !name &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_r;
}
if (!name) {
list_for_each_entry(cache, &fscache_caches, cache_link) {
if (cache->name &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_r;
}
}
up_read(&fscache_addremove_sem);
/* the cache does not exist - create a candidate */
candidate = fscache_alloc_cache(name);
if (!candidate)
return ERR_PTR(-ENOMEM);
/* write lock, search again and add if still not present */
down_write(&fscache_addremove_sem);
list_for_each_entry(cache, &fscache_caches, cache_link) {
if (cache->name && name && strcmp(cache->name, name) == 0 &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_w;
if (!cache->name) {
unnamed = cache;
if (!name &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_w;
}
}
if (unnamed && is_cache &&
fscache_get_cache_maybe(unnamed, fscache_cache_get_acquire))
goto use_unnamed_cache;
if (!name) {
list_for_each_entry(cache, &fscache_caches, cache_link) {
if (cache->name &&
fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
goto got_cache_w;
}
}
list_add_tail(&candidate->cache_link, &fscache_caches);
trace_fscache_cache(candidate->debug_id,
refcount_read(&candidate->ref),
Annotation
- Immediate include surface: `linux/export.h`, `linux/slab.h`, `internal.h`.
- Detected declarations: `function fscache_get_cache_maybe`, `function list_for_each_entry`, `function list_for_each_entry`, `function fscache_put_cache`, `function fscache_relinquish_cache`, `function fscache_add_cache`, `function fscache_begin_cache_access`, `function fscache_end_cache_access`, `function fscache_io_error`, `function fscache_withdraw_cache`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.