tools/testing/selftests/bpf/progs/map_in_map_btf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/map_in_map_btf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/map_in_map_btf.c- Extension
.c- Size
- 1453 bytes
- Lines
- 74
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- 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
vmlinux.hbpf/bpf_tracing.hbpf/bpf_helpers.hbpf_misc.hbpf_experimental.h
Detected Declarations
struct node_datastruct map_valuestruct inner_array_typefunction add_to_list_in_inner_array
Annotated Snippet
struct node_data {
__u64 data;
struct bpf_list_node node;
};
struct map_value {
struct bpf_list_head head __contains(node_data, node);
struct bpf_spin_lock lock;
};
struct inner_array_type {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, int);
__type(value, struct map_value);
__uint(max_entries, 1);
} inner_array SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(key_size, 4);
__uint(value_size, 4);
__uint(max_entries, 1);
__array(values, struct inner_array_type);
} outer_array SEC(".maps") = {
.values = {
[0] = &inner_array,
},
};
char _license[] SEC("license") = "GPL";
int pid = 0;
bool done = false;
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int add_to_list_in_inner_array(void *ctx)
{
struct map_value *value;
struct node_data *new;
struct bpf_map *map;
int zero = 0;
if (done || (u32)bpf_get_current_pid_tgid() != pid)
return 0;
map = bpf_map_lookup_elem(&outer_array, &zero);
if (!map)
return 0;
value = bpf_map_lookup_elem(map, &zero);
if (!value)
return 0;
new = bpf_obj_new(typeof(*new));
if (!new)
return 0;
bpf_spin_lock(&value->lock);
bpf_list_push_back(&value->head, &new->node);
bpf_spin_unlock(&value->lock);
done = true;
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `bpf_experimental.h`.
- Detected declarations: `struct node_data`, `struct map_value`, `struct inner_array_type`, `function add_to_list_in_inner_array`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.