tools/testing/selftests/bpf/map_tests/sk_storage_map.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/map_tests/sk_storage_map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/map_tests/sk_storage_map.c- Extension
.c- Size
- 15999 bytes
- Lines
- 628
- 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
linux/compiler.hlinux/err.hsys/resource.hsys/socket.hsys/types.hlinux/btf.hunistd.hsignal.herrno.hstring.hpthread.hbpf/bpf.hbpf/libbpf.htest_btf.htest_maps.h
Detected Declarations
function is_stoppedfunction threads_errfunction notify_thread_errfunction wait_for_threads_errfunction threads_donefunction notify_thread_donefunction notify_thread_redofunction wait_for_threads_donefunction wait_for_threads_redofunction wait_for_mapfunction wait_for_map_closefunction load_btffunction create_sk_storage_mapfunction do_sk_storage_map_stress_freefunction do_sk_storage_map_stress_changefunction stop_handlerfunction test_sk_storage_map_stress_freefunction test_sk_storage_map_stress_changefunction test_sk_storage_map_basicfunction test_sk_storage_map
Annotated Snippet
if (sk_fds[i] == -1) {
err = -errno;
fprintf(stderr, "socket(): errno:%d\n", errno);
goto errout;
}
err = bpf_map_update_elem(map_fd, &sk_fds[i], &value,
BPF_NOEXIST);
if (err) {
err = -errno;
fprintf(stderr,
"bpf_map_update_elem(): errno:%d\n",
errno);
goto errout;
}
}
notify_thread_done();
wait_for_map_close();
close_all:
for (i = 0; i < nr_sk_per_thread; i++) {
close(sk_fds[i]);
sk_fds[i] = -1;
}
notify_thread_redo();
}
free(sk_fds);
return NULL;
errout:
for (i = 0; i < nr_sk_per_thread && sk_fds[i] != -1; i++)
close(sk_fds[i]);
free(sk_fds);
notify_thread_err();
return ERR_PTR(err);
}
static int do_sk_storage_map_stress_free(void)
{
int i, map_fd = -1, err = 0, nr_threads_created = 0;
pthread_t *sk_thread_ids;
void *thread_ret;
sk_thread_ids = malloc(sizeof(pthread_t) * nr_sk_threads);
if (!sk_thread_ids) {
fprintf(stderr, "malloc(sk_threads): NULL\n");
return -ENOMEM;
}
for (i = 0; i < nr_sk_threads; i++) {
err = pthread_create(&sk_thread_ids[i], NULL,
insert_close_thread, NULL);
if (err) {
err = -errno;
goto done;
}
nr_threads_created++;
}
while (!is_stopped()) {
map_fd = create_sk_storage_map();
WRITE_ONCE(sk_storage_map, map_fd);
if (!wait_for_threads_done())
break;
WRITE_ONCE(sk_storage_map, -1);
close(map_fd);
map_fd = -1;
if (!wait_for_threads_redo())
break;
}
done:
WRITE_ONCE(stop, 1);
for (i = 0; i < nr_threads_created; i++) {
pthread_join(sk_thread_ids[i], &thread_ret);
if (IS_ERR(thread_ret) && !err) {
err = PTR_ERR(thread_ret);
fprintf(stderr, "threads#%u: err:%d\n", i, err);
}
}
free(sk_thread_ids);
if (map_fd != -1)
close(map_fd);
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/err.h`, `sys/resource.h`, `sys/socket.h`, `sys/types.h`, `linux/btf.h`, `unistd.h`, `signal.h`.
- Detected declarations: `function is_stopped`, `function threads_err`, `function notify_thread_err`, `function wait_for_threads_err`, `function threads_done`, `function notify_thread_done`, `function notify_thread_redo`, `function wait_for_threads_done`, `function wait_for_threads_redo`, `function wait_for_map`.
- 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.