tools/testing/selftests/bpf/prog_tests/fd_htab_lookup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/fd_htab_lookup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/fd_htab_lookup.c- Extension
.c- Size
- 3916 bytes
- Lines
- 193
- 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
stdbool.htest_progs.hfd_htab_lookup.skel.h
Detected Declarations
struct htab_op_ctxfunction setup_htabfunction get_int_from_envfunction test_fd_htab_lookup
Annotated Snippet
struct htab_op_ctx {
int fd;
int loop;
unsigned int entries;
bool stop;
};
#define ERR_TO_RETVAL(where, err) ((void *)(long)(((where) << 12) | (-err)))
static void *htab_lookup_fn(void *arg)
{
struct htab_op_ctx *ctx = arg;
int i = 0;
while (i++ < ctx->loop && !ctx->stop) {
unsigned int j;
for (j = 0; j < ctx->entries; j++) {
unsigned int key = j, zero = 0, value;
int inner_fd, err;
err = bpf_map_lookup_elem(ctx->fd, &key, &value);
if (err) {
ctx->stop = true;
return ERR_TO_RETVAL(1, err);
}
inner_fd = bpf_map_get_fd_by_id(value);
if (inner_fd < 0) {
/* The old map has been freed */
if (inner_fd == -ENOENT)
continue;
ctx->stop = true;
return ERR_TO_RETVAL(2, inner_fd);
}
err = bpf_map_lookup_elem(inner_fd, &zero, &value);
if (err) {
close(inner_fd);
ctx->stop = true;
return ERR_TO_RETVAL(3, err);
}
close(inner_fd);
if (value != key) {
ctx->stop = true;
return ERR_TO_RETVAL(4, -EINVAL);
}
}
}
return NULL;
}
static void *htab_update_fn(void *arg)
{
struct htab_op_ctx *ctx = arg;
int i = 0;
while (i++ < ctx->loop && !ctx->stop) {
unsigned int j;
for (j = 0; j < ctx->entries; j++) {
unsigned int key = j, zero = 0;
int inner_fd, err;
inner_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 4, 1, NULL);
if (inner_fd < 0) {
ctx->stop = true;
return ERR_TO_RETVAL(1, inner_fd);
}
err = bpf_map_update_elem(inner_fd, &zero, &key, 0);
if (err) {
close(inner_fd);
ctx->stop = true;
return ERR_TO_RETVAL(2, err);
}
err = bpf_map_update_elem(ctx->fd, &key, &inner_fd, BPF_EXIST);
if (err) {
close(inner_fd);
ctx->stop = true;
return ERR_TO_RETVAL(3, err);
}
close(inner_fd);
}
}
return NULL;
Annotation
- Immediate include surface: `stdbool.h`, `test_progs.h`, `fd_htab_lookup.skel.h`.
- Detected declarations: `struct htab_op_ctx`, `function setup_htab`, `function get_int_from_env`, `function test_fd_htab_lookup`.
- 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.