tools/testing/selftests/bpf/progs/rhash.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/rhash.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/rhash.c- Extension
.c- Size
- 4439 bytes
- Lines
- 249
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hstdbool.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_misc.h
Detected Declarations
struct elemfunction test_rhash_lookup_updatefunction test_rhash_update_deletefunction test_rhash_update_elementsfunction test_rhash_update_existfunction test_rhash_update_anyfunction test_rhash_noexist_duplicatefunction test_rhash_delete_nonexistent
Annotated Snippet
struct elem {
char arr[128];
int val;
};
struct {
__uint(type, BPF_MAP_TYPE_RHASH);
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, 128);
__type(key, int);
__type(value, struct elem);
} rhmap SEC(".maps");
SEC("syscall")
int test_rhash_lookup_update(void *ctx)
{
int key = 5;
struct elem empty = {.val = 3, .arr = {0}};
struct elem *e;
err = 1;
e = bpf_map_lookup_elem(&rhmap, &key);
if (e)
return 1;
err = bpf_map_update_elem(&rhmap, &key, &empty, BPF_NOEXIST);
if (err)
return 1;
e = bpf_map_lookup_elem(&rhmap, &key);
if (!e || e->val != empty.val) {
err = 2;
return 2;
}
err = 0;
return 0;
}
SEC("syscall")
int test_rhash_update_delete(void *ctx)
{
int key = 6;
struct elem empty = {.val = 4, .arr = {0}};
struct elem *e;
err = 1;
e = bpf_map_lookup_elem(&rhmap, &key);
if (e)
return 1;
err = bpf_map_update_elem(&rhmap, &key, &empty, BPF_NOEXIST);
if (err)
return 2;
err = bpf_map_delete_elem(&rhmap, &key);
if (err)
return 3;
e = bpf_map_lookup_elem(&rhmap, &key);
if (e) {
err = 4;
return 4;
}
err = 0;
return 0;
}
SEC("syscall")
int test_rhash_update_elements(void *ctx)
{
int key = 0;
struct elem empty = {.val = 4, .arr = {0}};
struct elem *e;
int i;
err = 1;
for (i = 0; i < 128; ++i) {
key = i;
e = bpf_map_lookup_elem(&rhmap, &key);
if (e)
return 1;
empty.val = key;
err = bpf_map_update_elem(&rhmap, &key, &empty, BPF_NOEXIST);
if (err)
return 2;
Annotation
- Immediate include surface: `vmlinux.h`, `stdbool.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`.
- Detected declarations: `struct elem`, `function test_rhash_lookup_update`, `function test_rhash_update_delete`, `function test_rhash_update_elements`, `function test_rhash_update_exist`, `function test_rhash_update_any`, `function test_rhash_noexist_duplicate`, `function test_rhash_delete_nonexistent`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.