tools/testing/selftests/filesystems/file_stressor.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/file_stressor.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/file_stressor.c- Extension
.c- Size
- 4984 bytes
- Lines
- 195
- 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
fcntl.hlimits.hpthread.hsched.hstdio.hstring.hsys/stat.hsys/mount.hunistd.hkselftest_harness.hlinux/types.hlinux/mount.hsys/syscall.h
Detected Declarations
function sys_fsopenfunction sys_fsconfigfunction sys_fsmountfunction sys_move_mountfunction ASSERT_EQ
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#define __SANE_USERSPACE_TYPES__
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <unistd.h>
#include "kselftest_harness.h"
#include <linux/types.h>
#include <linux/mount.h>
#include <sys/syscall.h>
static inline int sys_fsopen(const char *fsname, unsigned int flags)
{
return syscall(__NR_fsopen, fsname, flags);
}
static inline int sys_fsconfig(int fd, unsigned int cmd, const char *key,
const char *value, int aux)
{
return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
}
static inline int sys_fsmount(int fd, unsigned int flags,
unsigned int attr_flags)
{
return syscall(__NR_fsmount, fd, flags, attr_flags);
}
#ifndef MOVE_MOUNT_F_EMPTY_PATH
#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
#endif
static inline int sys_move_mount(int from_dfd, const char *from_pathname,
int to_dfd, const char *to_pathname,
unsigned int flags)
{
return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd,
to_pathname, flags);
}
FIXTURE(file_stressor) {
int fd_tmpfs;
int nr_procs;
int max_fds;
pid_t *pids_openers;
pid_t *pids_getdents;
int *fd_proc_pid;
};
FIXTURE_SETUP(file_stressor)
{
int fd_context;
ASSERT_EQ(unshare(CLONE_NEWNS), 0);
ASSERT_EQ(mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL), 0);
ASSERT_EQ(mkdir("/slab_typesafe_by_rcu", 0755), 0);
fd_context = sys_fsopen("tmpfs", 0);
ASSERT_GE(fd_context, 0);
ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);
self->fd_tmpfs = sys_fsmount(fd_context, 0, 0);
ASSERT_GE(self->fd_tmpfs, 0);
ASSERT_EQ(close(fd_context), 0);
ASSERT_EQ(sys_move_mount(self->fd_tmpfs, "", -EBADF, "/slab_typesafe_by_rcu", MOVE_MOUNT_F_EMPTY_PATH), 0);
self->nr_procs = sysconf(_SC_NPROCESSORS_ONLN);
self->pids_openers = malloc(sizeof(pid_t) * self->nr_procs);
ASSERT_NE(self->pids_openers, NULL);
self->pids_getdents = malloc(sizeof(pid_t) * self->nr_procs);
ASSERT_NE(self->pids_getdents, NULL);
self->fd_proc_pid = malloc(sizeof(int) * self->nr_procs);
ASSERT_NE(self->fd_proc_pid, NULL);
self->max_fds = 500;
}
FIXTURE_TEARDOWN(file_stressor)
{
for (int i = 0; i < self->nr_procs; i++) {
int wstatus;
Annotation
- Immediate include surface: `fcntl.h`, `limits.h`, `pthread.h`, `sched.h`, `stdio.h`, `string.h`, `sys/stat.h`, `sys/mount.h`.
- Detected declarations: `function sys_fsopen`, `function sys_fsconfig`, `function sys_fsmount`, `function sys_move_mount`, `function ASSERT_EQ`.
- 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.