tools/testing/selftests/filesystems/statmount/statmount_test_ns.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/statmount/statmount_test_ns.c- Extension
.c- Size
- 8317 bytes
- Lines
- 362
- 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
assert.hfcntl.hlimits.hsched.hstdlib.hsys/mount.hsys/stat.hsys/wait.hlinux/nsfs.hlinux/stat.hstatmount.h../utils.hkselftest.h
Detected Declarations
function handle_resultfunction get_mnt_ns_idfunction setup_namespacefunction _test_statmount_mnt_ns_idfunction _test_statmount_mnt_ns_id_by_fdfunction test_statmount_mnt_ns_idfunction validate_external_listmountfunction test_listmount_nsfunction main
Annotated Snippet
if (ret < 0) {
ksft_print_msg("statmount mnt ns id: %s\n", strerror(errno));
return NSID_ERROR;
}
if (sm.mask != STATMOUNT_MNT_NS_ID) {
ksft_print_msg("statmount mnt ns id unavailable\n");
return NSID_SKIP;
}
if (sm.mnt_ns_id != mnt_ns_id) {
ksft_print_msg("listmount gave us the wrong ns id: 0x%llx != 0x%llx\n",
(unsigned long long)sm.mnt_ns_id,
(unsigned long long)mnt_ns_id);
return NSID_FAIL;
}
}
return NSID_PASS;
}
static void test_listmount_ns(void)
{
uint64_t nr_mounts;
char pval;
int child_ready_pipe[2];
int parent_ready_pipe[2];
pid_t pid;
int ret, child_ret;
if (pipe(child_ready_pipe) < 0)
ksft_exit_fail_msg("failed to create the child pipe: %s\n",
strerror(errno));
if (pipe(parent_ready_pipe) < 0)
ksft_exit_fail_msg("failed to create the parent pipe: %s\n",
strerror(errno));
pid = fork();
if (pid < 0)
ksft_exit_fail_msg("failed to fork: %s\n", strerror(errno));
if (pid == 0) {
char cval;
uint64_t list[256];
close(child_ready_pipe[0]);
close(parent_ready_pipe[1]);
ret = setup_namespace();
if (ret != NSID_PASS)
exit(ret);
nr_mounts = listmount(LSMT_ROOT, 0, 0, list, 256, 0);
if (nr_mounts == (uint64_t)-1) {
ksft_print_msg("listmount: %s\n", strerror(errno));
exit(NSID_FAIL);
}
/*
* Tell our parent how many mounts we have, and then wait for it
* to tell us we're done.
*/
if (write(child_ready_pipe[1], &nr_mounts, sizeof(nr_mounts)) !=
sizeof(nr_mounts))
ret = NSID_ERROR;
if (read(parent_ready_pipe[0], &cval, sizeof(cval)) != sizeof(cval))
ret = NSID_ERROR;
exit(NSID_PASS);
}
close(child_ready_pipe[1]);
close(parent_ready_pipe[0]);
/* Wait until the child has created everything. */
if (read(child_ready_pipe[0], &nr_mounts, sizeof(nr_mounts)) !=
sizeof(nr_mounts))
ret = NSID_ERROR;
ret = validate_external_listmount(pid, nr_mounts);
if (write(parent_ready_pipe[1], &pval, sizeof(pval)) != sizeof(pval))
ret = NSID_ERROR;
child_ret = wait_for_pid(pid);
if (child_ret != NSID_PASS)
ret = child_ret;
handle_result(ret, "test listmount ns id");
}
int main(void)
Annotation
- Immediate include surface: `assert.h`, `fcntl.h`, `limits.h`, `sched.h`, `stdlib.h`, `sys/mount.h`, `sys/stat.h`, `sys/wait.h`.
- Detected declarations: `function handle_result`, `function get_mnt_ns_id`, `function setup_namespace`, `function _test_statmount_mnt_ns_id`, `function _test_statmount_mnt_ns_id_by_fd`, `function test_statmount_mnt_ns_id`, `function validate_external_listmount`, `function test_listmount_ns`, `function main`.
- 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.