fs/cachefiles/xattr.c
Source file repositories/reference/linux-study-clean/fs/cachefiles/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/cachefiles/xattr.c- Extension
.c- Size
- 8425 bytes
- Lines
- 305
- 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.
- 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/module.hlinux/sched.hlinux/file.hlinux/fs.hlinux/fsnotify.hlinux/quotaops.hlinux/xattr.hlinux/slab.hinternal.h
Detected Declarations
struct cachefiles_xattrstruct cachefiles_vol_xattrfunction cachefiles_set_object_xattrfunction cachefiles_check_auxdatafunction cachefiles_remove_object_xattrfunction cachefiles_prepare_to_writefunction cachefiles_set_volume_xattrfunction cachefiles_check_volume_xattr
Annotated Snippet
struct cachefiles_xattr {
__be64 object_size; /* Actual size of the object */
__be64 zero_point; /* Size after which server has no data not written by us */
__u8 type; /* Type of object */
__u8 content; /* Content presence (enum cachefiles_content) */
__u8 data[]; /* netfs coherency data */
} __packed;
static const char cachefiles_xattr_cache[] =
XATTR_USER_PREFIX "CacheFiles.cache";
struct cachefiles_vol_xattr {
__be32 reserved; /* Reserved, should be 0 */
__u8 data[]; /* netfs volume coherency data */
} __packed;
/*
* set the state xattr on a cache file
*/
int cachefiles_set_object_xattr(struct cachefiles_object *object)
{
struct cachefiles_xattr *buf;
struct dentry *dentry;
struct file *file = object->file;
unsigned int len = object->cookie->aux_len;
int ret;
if (!file)
return -ESTALE;
dentry = file->f_path.dentry;
_enter("%x,#%d", object->debug_id, len);
buf = kmalloc(sizeof(struct cachefiles_xattr) + len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
buf->object_size = cpu_to_be64(object->cookie->object_size);
buf->zero_point = 0;
buf->type = CACHEFILES_COOKIE_TYPE_DATA;
buf->content = object->content_info;
if (test_bit(FSCACHE_COOKIE_LOCAL_WRITE, &object->cookie->flags))
buf->content = CACHEFILES_CONTENT_DIRTY;
if (len > 0)
memcpy(buf->data, fscache_get_aux(object->cookie), len);
ret = cachefiles_inject_write_error();
if (ret == 0) {
ret = mnt_want_write_file(file);
if (ret == 0) {
ret = vfs_setxattr(&nop_mnt_idmap, dentry,
cachefiles_xattr_cache, buf,
sizeof(struct cachefiles_xattr) + len, 0);
mnt_drop_write_file(file);
}
}
if (ret < 0) {
trace_cachefiles_vfs_error(object, file_inode(file), ret,
cachefiles_trace_setxattr_error);
trace_cachefiles_coherency(object, file_inode(file)->i_ino,
be64_to_cpup((__be64 *)buf->data),
buf->content,
cachefiles_coherency_set_fail);
if (ret != -ENOMEM)
cachefiles_io_error_obj(
object,
"Failed to set xattr with error %d", ret);
} else {
trace_cachefiles_coherency(object, file_inode(file)->i_ino,
be64_to_cpup((__be64 *)buf->data),
buf->content,
cachefiles_coherency_set_ok);
}
kfree(buf);
_leave(" = %d", ret);
return ret;
}
/*
* check the consistency between the backing cache and the FS-Cache cookie
*/
int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file)
{
struct cachefiles_xattr *buf;
struct dentry *dentry = file->f_path.dentry;
unsigned int len = object->cookie->aux_len, tlen;
const void *p = fscache_get_aux(object->cookie);
enum cachefiles_coherency_trace why;
ssize_t xlen;
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/file.h`, `linux/fs.h`, `linux/fsnotify.h`, `linux/quotaops.h`, `linux/xattr.h`, `linux/slab.h`.
- Detected declarations: `struct cachefiles_xattr`, `struct cachefiles_vol_xattr`, `function cachefiles_set_object_xattr`, `function cachefiles_check_auxdata`, `function cachefiles_remove_object_xattr`, `function cachefiles_prepare_to_write`, `function cachefiles_set_volume_xattr`, `function cachefiles_check_volume_xattr`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.