kernel/bpf/bpf_inode_storage.c
Source file repositories/reference/linux-study-clean/kernel/bpf/bpf_inode_storage.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/bpf_inode_storage.c- Extension
.c- Size
- 5860 bytes
- Lines
- 225
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- 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/rculist.hlinux/list.hlinux/hash.hlinux/types.hlinux/spinlock.hlinux/bpf.hlinux/bpf_local_storage.hnet/sock.huapi/linux/sock_diag.huapi/linux/btf.hlinux/bpf_lsm.hlinux/btf_ids.hlinux/rcupdate_trace.h
Detected Declarations
function inode_storage_ptrfunction bpf_inode_storage_freefunction bpf_fd_inode_storage_update_elemfunction inode_storage_deletefunction bpf_fd_inode_storage_delete_elemfunction notsupp_get_next_keyfunction inode_storage_map_free
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 Facebook
* Copyright 2020 Google LLC.
*/
#include <linux/rculist.h>
#include <linux/list.h>
#include <linux/hash.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/bpf.h>
#include <linux/bpf_local_storage.h>
#include <net/sock.h>
#include <uapi/linux/sock_diag.h>
#include <uapi/linux/btf.h>
#include <linux/bpf_lsm.h>
#include <linux/btf_ids.h>
#include <linux/rcupdate_trace.h>
DEFINE_BPF_STORAGE_CACHE(inode_cache);
static struct bpf_local_storage __rcu **
inode_storage_ptr(void *owner)
{
struct inode *inode = owner;
struct bpf_storage_blob *bsb;
bsb = bpf_inode(inode);
if (!bsb)
return NULL;
return &bsb->storage;
}
static struct bpf_local_storage_data *inode_storage_lookup(struct inode *inode,
struct bpf_map *map,
bool cacheit_lockit)
{
struct bpf_local_storage *inode_storage;
struct bpf_local_storage_map *smap;
struct bpf_storage_blob *bsb;
bsb = bpf_inode(inode);
if (!bsb)
return NULL;
inode_storage =
rcu_dereference_check(bsb->storage, bpf_rcu_lock_held());
if (!inode_storage)
return NULL;
smap = (struct bpf_local_storage_map *)map;
return bpf_local_storage_lookup(inode_storage, smap, cacheit_lockit);
}
void bpf_inode_storage_free(struct inode *inode)
{
struct bpf_local_storage *local_storage;
struct bpf_storage_blob *bsb;
bsb = bpf_inode(inode);
if (!bsb)
return;
rcu_read_lock_dont_migrate();
local_storage = rcu_dereference(bsb->storage);
if (!local_storage)
goto out;
bpf_local_storage_destroy(local_storage);
out:
rcu_read_unlock_migrate();
}
static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
{
struct bpf_local_storage_data *sdata;
CLASS(fd_raw, f)(*(int *)key);
if (fd_empty(f))
return ERR_PTR(-EBADF);
sdata = inode_storage_lookup(file_inode(fd_file(f)), map, true);
return sdata ? sdata->data : NULL;
}
static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
void *value, u64 map_flags)
{
Annotation
- Immediate include surface: `linux/rculist.h`, `linux/list.h`, `linux/hash.h`, `linux/types.h`, `linux/spinlock.h`, `linux/bpf.h`, `linux/bpf_local_storage.h`, `net/sock.h`.
- Detected declarations: `function inode_storage_ptr`, `function bpf_inode_storage_free`, `function bpf_fd_inode_storage_update_elem`, `function inode_storage_delete`, `function bpf_fd_inode_storage_delete_elem`, `function notsupp_get_next_key`, `function inode_storage_map_free`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.