tools/testing/selftests/bpf/progs/read_cgroupfs_xattr.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/read_cgroupfs_xattr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/read_cgroupfs_xattr.c- Extension
.c- Size
- 1496 bytes
- Lines
- 61
- 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/bpf_core_read.hbpf_experimental.h
Detected Declarations
function BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include "bpf_experimental.h"
char _license[] SEC("license") = "GPL";
pid_t target_pid = 0;
char xattr_value[64];
static const char expected_value_a[] = "bpf_selftest_value_a";
static const char expected_value_b[] = "bpf_selftest_value_b";
bool found_value_a;
bool found_value_b;
SEC("lsm.s/file_open")
int BPF_PROG(test_file_open)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup_subsys_state *css, *tmp;
struct bpf_dynptr value_ptr;
struct cgroup *cgrp;
if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
return 0;
bpf_rcu_read_lock();
cgrp = bpf_cgroup_from_id(cgrp_id);
if (!cgrp) {
bpf_rcu_read_unlock();
return 0;
}
css = &cgrp->self;
bpf_dynptr_from_mem(xattr_value, sizeof(xattr_value), 0, &value_ptr);
bpf_for_each(css, tmp, css, BPF_CGROUP_ITER_ANCESTORS_UP) {
int ret;
ret = bpf_cgroup_read_xattr(tmp->cgroup, "user.bpf_test",
&value_ptr);
if (ret < 0)
continue;
if (ret == sizeof(expected_value_a) &&
!bpf_strncmp(xattr_value, sizeof(expected_value_a), expected_value_a))
found_value_a = true;
if (ret == sizeof(expected_value_b) &&
!bpf_strncmp(xattr_value, sizeof(expected_value_b), expected_value_b))
found_value_b = true;
}
bpf_rcu_read_unlock();
bpf_cgroup_release(cgrp);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf_experimental.h`.
- Detected declarations: `function BPF_PROG`.
- 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.