tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c- Extension
.c- Size
- 6926 bytes
- Lines
- 376
- 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
sched.hstdio.herrno.hstring.hsys/stat.hsys/types.hsys/mount.hsys/wait.hstdlib.hunistd.hfcntl.hstdbool.hstdarg.hsys/syscall.hkselftest_harness.h
Detected Declarations
struct child_argsfunction write_nointrfunction write_filefunction create_and_enter_usernsfunction prepare_unpriv_mountnsfunction null_endofwordfunction is_shared_mountfunction move_mount_set_group_supportedfunction do_clonefunction wait_for_pidfunction get_nestedns_mount_cb
Annotated Snippet
struct child_args {
int unsfd;
int mntnsfd;
bool shared;
int mntfd;
};
static int get_nestedns_mount_cb(void *data)
{
struct child_args *ca = (struct child_args *)data;
int ret;
ret = prepare_unpriv_mountns();
if (ret)
return 1;
if (ca->shared) {
ret = mount(NULL, SET_GROUP_A, NULL, MS_SHARED, 0);
if (ret)
return 1;
}
ret = open("/proc/self/ns/user", O_RDONLY);
if (ret < 0)
return 1;
ca->unsfd = ret;
ret = open("/proc/self/ns/mnt", O_RDONLY);
if (ret < 0)
return 1;
ca->mntnsfd = ret;
ret = open(SET_GROUP_A, O_RDONLY);
if (ret < 0)
return 1;
ca->mntfd = ret;
return 0;
}
TEST_F(move_mount_set_group, complex_sharing_copying)
{
struct child_args ca_from = {
.shared = true,
};
struct child_args ca_to = {
.shared = false,
};
pid_t pid;
bool ret;
ret = move_mount_set_group_supported();
ASSERT_GE(ret, 0);
if (!ret)
SKIP(return, "move_mount(MOVE_MOUNT_SET_GROUP) is not supported");
pid = do_clone(get_nestedns_mount_cb, (void *)&ca_from, CLONE_VFORK |
CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
ASSERT_EQ(wait_for_pid(pid), 0);
pid = do_clone(get_nestedns_mount_cb, (void *)&ca_to, CLONE_VFORK |
CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
ASSERT_EQ(wait_for_pid(pid), 0);
ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
| MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
0);
ASSERT_EQ(setns(ca_to.mntnsfd, CLONE_NEWNS), 0);
ASSERT_EQ(is_shared_mount(SET_GROUP_A), 1);
}
TEST_HARNESS_MAIN
Annotation
- Immediate include surface: `sched.h`, `stdio.h`, `errno.h`, `string.h`, `sys/stat.h`, `sys/types.h`, `sys/mount.h`, `sys/wait.h`.
- Detected declarations: `struct child_args`, `function write_nointr`, `function write_file`, `function create_and_enter_userns`, `function prepare_unpriv_mountns`, `function null_endofword`, `function is_shared_mount`, `function move_mount_set_group_supported`, `function do_clone`, `function wait_for_pid`.
- 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.