tools/testing/selftests/filesystems/fsmount_ns/fsmount_ns_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/fsmount_ns/fsmount_ns_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/fsmount_ns/fsmount_ns_test.c
Extension
.c
Size
24466 bytes
Lines
1136
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!sm) {
			TH_LOG("  [%zd] mnt_id %llu: statmount failed: %s",
			       i, (unsigned long long)list[i], strerror(errno));
			continue;
		}

		log_mount(_metadata, sm);
		free(sm);
	}
}

static int create_tmpfs_fd(void)
{
	int fs_fd, ret;

	fs_fd = sys_fsopen("tmpfs", FSOPEN_CLOEXEC);
	if (fs_fd < 0)
		return -errno;

	ret = sys_fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
	if (ret < 0) {
		close(fs_fd);
		return -errno;
	}

	return fs_fd;
}

FIXTURE(fsmount_ns)
{
	int fd;
	int fs_fd;
	uint64_t current_ns_id;
};

FIXTURE_VARIANT(fsmount_ns)
{
	const char *fstype;
	unsigned int flags;
	bool expect_success;
	bool expect_different_ns;
	int min_mounts;
};

FIXTURE_VARIANT_ADD(fsmount_ns, basic_tmpfs)
{
	.fstype = "tmpfs",
	.flags = FSMOUNT_NAMESPACE | FSMOUNT_CLOEXEC,
	.expect_success = true,
	.expect_different_ns = true,
	.min_mounts = 1,
};

FIXTURE_VARIANT_ADD(fsmount_ns, cloexec_only)
{
	.fstype = "tmpfs",
	.flags = FSMOUNT_CLOEXEC,
	.expect_success = true,
	.expect_different_ns = false,
	.min_mounts = 1,
};

FIXTURE_VARIANT_ADD(fsmount_ns, namespace_only)
{
	.fstype = "tmpfs",
	.flags = FSMOUNT_NAMESPACE,
	.expect_success = true,
	.expect_different_ns = true,
	.min_mounts = 1,
};

FIXTURE_SETUP(fsmount_ns)
{
	int ret;

	self->fd = -1;
	self->fs_fd = -1;

	/* Check if fsopen syscall is supported */
	ret = sys_fsopen("tmpfs", 0);
	if (ret == -1 && errno == ENOSYS)
		SKIP(return, "fsopen() syscall not supported");
	if (ret >= 0)
		close(ret);

	/* Check if statmount/listmount are supported */
	ret = statmount(0, 0, 0, 0, NULL, 0, 0);
	if (ret == -1 && errno == ENOSYS)
		SKIP(return, "statmount() syscall not supported");

Annotation

Implementation Notes