[Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Thu Nov 19 10:53:47 MSK 2026


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/ve: open_cg2_fd() fails instead of skipping when
  cgroup2 is not at /sys/fs/cgroup
- [Low] selftests/ve: stale 'cgroup2 mount' log messages in
  ve_cpuid_override_test.c
--

commit 35c219f99551e9d27fa90449ba5b0180826c3af5
Author: Mirian Shilakadze <mirian.shilakadze at virtuozzo.com>

selftests/ve: open the host cgroup2 mount instead of creating one

The commit replaces mount_cg2_fd(), which created a fresh cgroup2 mount with fsopen()/fsconfig()/fsmount(), with open_cg2_fd(). The new helper opens /sys/fs/cgroup and checks with fstatfs() that it is cgroup2. This stops each fixture setup from clearing nsdelegate and memory_recursiveprot on the host hierarchy. All callers are switched over.

> diff --git a/tools/testing/selftests/ve/ve_cpuid_override_test.c b/tools/testing/selftests/ve/ve_cpuid_override_test.c
> index b9f5e49d6c43..b52e4141ab99 100644
> --- a/tools/testing/selftests/ve/ve_cpuid_override_test.c
> +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c
> @@ -153,7 +153,7 @@ FIXTURE_SETUP(ve_cpuid_override)
>  		 self->host.edx & ~self->bit);
>  
>  	/* Last, so that a failed ASSERT above leaves no VE cgroup behind. */
> -	self->cgv2_fd = mount_cg2_fd();
> +	self->cgv2_fd = open_cg2_fd();
>  	ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cgroup2 mount: %s", strerror(errno));

[Severity: Low]
This isn't a bug, but this message still says "cgroup2 mount" although
open_cg2_fd() no longer mounts anything. The commit message says the
messages that said "mount" now say "open". The TH_LOG() in
FIXTURE_TEARDOWN_PARENT(ve_cpuid_override), "cgroup2 mount: %s, VE cgroup
%d left behind", was missed in the same way. Could both be changed to
"cgroup2 open"?

[ ... ]

> diff --git a/tools/testing/selftests/ve/ve_perms_test.c b/tools/testing/selftests/ve/ve_perms_test.c
> index c57325d10901..375f98c36f87 100644
> --- a/tools/testing/selftests/ve/ve_perms_test.c
> +++ b/tools/testing/selftests/ve/ve_perms_test.c
> @@ -189,7 +189,7 @@ static int default_granted(int cgv2_fd, const char *fs, const char *entry)
>  
>  FIXTURE_SETUP(ve_perms)
>  {
> -	self->cgv2_fd = mount_cg2_fd();
> +	self->cgv2_fd = open_cg2_fd();
>  	ASSERT_GE(self->cgv2_fd, 0);

[ ... ]

> diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h
> index 1fc3f8dcac18..af7725600453 100644
> --- a/tools/testing/selftests/ve/ve_selftest.h
> +++ b/tools/testing/selftests/ve/ve_selftest.h
> @@ -245,23 +245,26 @@ static inline int read_s32_at(int dirfd, const char *path,
[ ... ]
> +static inline int open_cg2_fd(void)
>  {
> -	int fs_fd, mnt_fd;
> +	struct statfs st;
> +	int fd;
>  
> -	fs_fd = fsopen("cgroup2", 0);
> -	if (fs_fd < 0)
> +	fd = open("/sys/fs/cgroup", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
> +	if (fd < 0)
>  		return -1;
> -
> -	if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) {
> -		close(fs_fd);
> +	if (fstatfs(fd, &st) < 0 || st.f_type != CGROUP2_SUPER_MAGIC) {
> +		close(fd);
> +		errno = ENODEV;
>  		return -1;

[Severity: Low]
Should a missing cgroup2 at /sys/fs/cgroup be treated as a skip rather
than a failure? On a host with a cgroup v1 or hybrid layout, or where the
path is absent, open_cg2_fd() returns -1 with errno set to ENODEV. Most
callers, such as the FIXTURE_SETUP(ve_perms) above, only do
ASSERT_GE(self->cgv2_fd, 0), so they report a hard failure. Only
ve_numa_migrate and ve_vtty_stress turn the error into a skip. The old
mount_cg2_fd() worked on those hosts, and the commit message does not
mention the new assumption about the host layout. Could the callers skip
with a reason in this case?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119074808.478064-1-mirian.shilakadze@virtuozzo.com?part=1



More information about the Devel mailing list