fs/cachefiles/interface.c
Source file repositories/reference/linux-study-clean/fs/cachefiles/interface.c
File Facts
- System
- Linux kernel
- Corpus path
fs/cachefiles/interface.c- Extension
.c- Size
- 12855 bytes
- Lines
- 462
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/mount.hlinux/xattr.hlinux/file.hlinux/namei.hlinux/falloc.htrace/events/fscache.hinternal.h
Detected Declarations
function cachefiles_see_objectfunction cachefiles_put_objectfunction cachefiles_adjust_sizefunction cachefiles_lookup_cookiefunction cachefiles_shorten_objectfunction cachefiles_resize_cookiefunction cachefiles_commit_objectfunction cachefiles_clean_up_objectfunction cachefiles_withdraw_cookiefunction cachefiles_invalidate_cookie
Annotated Snippet
if (ret < 0) {
trace_cachefiles_io_error(object, file_inode(file), ret,
cachefiles_trace_fallocate_error);
cachefiles_io_error_obj(object, "Trunc-to-dio-size failed %d", ret);
cachefiles_remove_object_xattr(cache, object, file->f_path.dentry);
return false;
}
}
return true;
}
/*
* Resize the backing object.
*/
static void cachefiles_resize_cookie(struct netfs_cache_resources *cres,
loff_t new_size)
{
struct cachefiles_object *object = cachefiles_cres_object(cres);
struct cachefiles_cache *cache = object->volume->cache;
struct fscache_cookie *cookie = object->cookie;
const struct cred *saved_cred;
struct file *file = cachefiles_cres_file(cres);
loff_t old_size = cookie->object_size;
_enter("%llu->%llu", old_size, new_size);
if (new_size < old_size) {
cachefiles_begin_secure(cache, &saved_cred);
cachefiles_shorten_object(object, file, new_size);
cachefiles_end_secure(cache, saved_cred);
object->cookie->object_size = new_size;
return;
}
/* The file is being expanded. We don't need to do anything
* particularly. cookie->initial_size doesn't change and so the point
* at which we have to download before doesn't change.
*/
cookie->object_size = new_size;
}
/*
* Commit changes to the object as we drop it.
*/
static void cachefiles_commit_object(struct cachefiles_object *object,
struct cachefiles_cache *cache)
{
bool update = false;
if (test_and_clear_bit(FSCACHE_COOKIE_LOCAL_WRITE, &object->cookie->flags))
update = true;
if (test_and_clear_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &object->cookie->flags))
update = true;
if (update)
cachefiles_set_object_xattr(object);
if (test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags))
cachefiles_commit_tmpfile(cache, object);
}
/*
* Finalise and object and close the VFS structs that we have.
*/
static void cachefiles_clean_up_object(struct cachefiles_object *object,
struct cachefiles_cache *cache)
{
struct file *file;
if (test_bit(FSCACHE_COOKIE_RETIRED, &object->cookie->flags)) {
if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {
cachefiles_see_object(object, cachefiles_obj_see_clean_delete);
_debug("- inval object OBJ%x", object->debug_id);
cachefiles_delete_object(object, FSCACHE_OBJECT_WAS_RETIRED);
} else {
cachefiles_see_object(object, cachefiles_obj_see_clean_drop_tmp);
_debug("- inval object OBJ%x tmpfile", object->debug_id);
}
} else {
cachefiles_see_object(object, cachefiles_obj_see_clean_commit);
cachefiles_commit_object(object, cache);
}
cachefiles_unmark_inode_in_use(object, object->file);
spin_lock(&object->lock);
file = object->file;
object->file = NULL;
spin_unlock(&object->lock);
Annotation
- Immediate include surface: `linux/slab.h`, `linux/mount.h`, `linux/xattr.h`, `linux/file.h`, `linux/namei.h`, `linux/falloc.h`, `trace/events/fscache.h`, `internal.h`.
- Detected declarations: `function cachefiles_see_object`, `function cachefiles_put_object`, `function cachefiles_adjust_size`, `function cachefiles_lookup_cookie`, `function cachefiles_shorten_object`, `function cachefiles_resize_cookie`, `function cachefiles_commit_object`, `function cachefiles_clean_up_object`, `function cachefiles_withdraw_cookie`, `function cachefiles_invalidate_cookie`.
- 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.