tools/testing/selftests/bpf/prog_tests/cgrp_local_storage.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/cgrp_local_storage.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/cgrp_local_storage.c- Extension
.c- Size
- 9186 bytes
- Lines
- 375
- 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
unistd.hsys/syscall.hsys/types.htest_progs.hcgrp_ls_tp_btf.skel.hcgrp_ls_recursion.skel.hcgrp_ls_attach_cgroup.skel.hcgrp_ls_negative.skel.hcgrp_ls_sleepable.skel.hnetwork_helpers.hcgroup_helpers.h
Detected Declarations
struct socket_cookiefunction cgroup_mode_value_initfunction test_tp_btffunction test_attach_cgroupfunction test_recursionfunction test_negativefunction test_cgroup_iter_sleepablefunction test_yes_rcu_lockfunction test_no_rcu_lockfunction test_cgrp1_no_rcu_lockfunction cgrp2_local_storagefunction cgrp1_local_storagefunction test_cgrp_local_storage
Annotated Snippet
struct socket_cookie {
__u64 cookie_key;
__u64 cookie_value;
};
static bool is_cgroup1;
static int target_hid;
#define CGROUP_MODE_SET(skel) \
{ \
skel->bss->is_cgroup1 = is_cgroup1; \
skel->bss->target_hid = target_hid; \
}
static void cgroup_mode_value_init(bool cgroup, int hid)
{
is_cgroup1 = cgroup;
target_hid = hid;
}
static void test_tp_btf(int cgroup_fd)
{
struct cgrp_ls_tp_btf *skel;
long val1 = 1, val2 = 0;
int err;
skel = cgrp_ls_tp_btf__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
return;
CGROUP_MODE_SET(skel);
/* populate a value in map_b */
err = bpf_map_update_elem(bpf_map__fd(skel->maps.map_b), &cgroup_fd, &val1, BPF_ANY);
if (!ASSERT_OK(err, "map_update_elem"))
goto out;
/* check value */
err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.map_b), &cgroup_fd, &val2);
if (!ASSERT_OK(err, "map_lookup_elem"))
goto out;
if (!ASSERT_EQ(val2, 1, "map_lookup_elem, invalid val"))
goto out;
/* delete value */
err = bpf_map_delete_elem(bpf_map__fd(skel->maps.map_b), &cgroup_fd);
if (!ASSERT_OK(err, "map_delete_elem"))
goto out;
skel->bss->target_pid = sys_gettid();
err = cgrp_ls_tp_btf__attach(skel);
if (!ASSERT_OK(err, "skel_attach"))
goto out;
sys_gettid();
sys_gettid();
skel->bss->target_pid = 0;
/* 3x syscalls: 1x attach and 2x gettid */
ASSERT_EQ(skel->bss->enter_cnt, 3, "enter_cnt");
ASSERT_EQ(skel->bss->exit_cnt, 3, "exit_cnt");
ASSERT_EQ(skel->bss->mismatch_cnt, 0, "mismatch_cnt");
out:
cgrp_ls_tp_btf__destroy(skel);
}
static void test_attach_cgroup(int cgroup_fd)
{
int server_fd = 0, client_fd = 0, err = 0;
socklen_t addr_len = sizeof(struct sockaddr_in6);
struct cgrp_ls_attach_cgroup *skel;
__u32 cookie_expected_value;
struct sockaddr_in6 addr;
struct socket_cookie val;
skel = cgrp_ls_attach_cgroup__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_open"))
return;
skel->links.set_cookie = bpf_program__attach_cgroup(
skel->progs.set_cookie, cgroup_fd);
if (!ASSERT_OK_PTR(skel->links.set_cookie, "prog_attach"))
goto out;
skel->links.update_cookie_sockops = bpf_program__attach_cgroup(
skel->progs.update_cookie_sockops, cgroup_fd);
if (!ASSERT_OK_PTR(skel->links.update_cookie_sockops, "prog_attach"))
goto out;
Annotation
- Immediate include surface: `unistd.h`, `sys/syscall.h`, `sys/types.h`, `test_progs.h`, `cgrp_ls_tp_btf.skel.h`, `cgrp_ls_recursion.skel.h`, `cgrp_ls_attach_cgroup.skel.h`, `cgrp_ls_negative.skel.h`.
- Detected declarations: `struct socket_cookie`, `function cgroup_mode_value_init`, `function test_tp_btf`, `function test_attach_cgroup`, `function test_recursion`, `function test_negative`, `function test_cgroup_iter_sleepable`, `function test_yes_rcu_lock`, `function test_no_rcu_lock`, `function test_cgrp1_no_rcu_lock`.
- 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.