From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 307AE80027 for ; Thu, 19 Nov 2026 07:49:40 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ7mMAB003649; Thu, 19 Nov 2026 10:48:22 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ7mMAB003649 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ly8Di8en" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ7mF7e003630 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 10:48:15 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ7mF7e003630 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4a589b28bddso982464f8f.0 for ; Wed, 18 Nov 2026 23:48:15 -0800 (PST) X-Gm-Message-State: APuU4Z9/CDBjxoB++V4zsPoHMI5qKzi8c1BP/UeAv0BDv5oDvKY5Aito 9mxP3+319cB4pAenZ27v3W7IFS7UOSZLkR16aJxpWB1y+0u9V9HnT/NeaVLilup/9WL4Xsrgz/4 0T3uEo32+X7PDba31xw1Drq909TEKK+gtfy7sxNTZoI2YlllAvnfc8Q== X-Gm-Gg: AZFdTZe4xJMJTXemBgRkTQvLqwpfGn4FNwKja1jCsS79JonD/y2RGkQBue/X17wG2WX PqWDgZ0RVqIlctpvlcDHfCoySsdpNZ4kpW7UGllf89DrPH7abWPHDQhds2jzAm1AFvrQUyiGzZW m/4pgfpQVVWhpICUG66PLY7aPBlyBoKxPiOoni8VqWWj7OIdPbffUkp0cL3Nx5sCn//qS6zoNzf GEGyrP/Suw3p7RmVtrU/G1DX2BeLCzAuFqKeV4emOhb4+G7d+Vg2rqIXg7abvadUKHm0O/9YVyq NGBI50/jyAJq8RUKyNMGoAZGo6pKKFhO81fwu0ef5i8wpcjDKKF/TG7FtcP9myfMHWB4VWkJK1/ bsw0Ll4c/tkKV/L1NhxC0vJgGdzvy X-Received: by 2002:a05:6000:144f:b0:4aa:76ce:4b9f with SMTP id ffacd0b85a97d-4aa76ce4cacmr475057f8f.56.1795074495339; Wed, 18 Nov 2026 23:48:15 -0800 (PST) X-Received: by 2002:a05:6000:144f:b0:4aa:76ce:4b9f with SMTP id ffacd0b85a97d-4aa76ce4cacmr475010f8f.56.1795074494823; Wed, 18 Nov 2026 23:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795074494; cv=none; d=google.com; s=arc-20260327; b=qPU9XvWCHjaOwEe2ohL1TrrOlwgGSYQa22REKOveko9LHkcEn1OIiEI9nDb+x/4wWe 5FksvTBjj8gDj+Q+aAKrvKtS99fJKJ+W/wLIy1ZhKcnzGy1hAs3ZALkRNoOvR6mRn2m/ JZPKKZ2HNyEjnXWsWpsoDhm9jxHWqbDkfDNT/eqrT25BuX8WY6dJ9fyZ5fmTzj963Lug qRjdDI5BA61TU7QXraUoEOZyRJFQXlKDzz6wkahVIc4FEPNpAKuAfMVzcTtOR5eiHR5e JlzwxYaOzZsLXL9oiSQq3QCep/KackUpg5NN8NuZgMThI0U5XOXWiHFafsEfAB+AeNIJ QqMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=GIkl0oau1l/C6b8erMyedtUMQJbotQ2FKdUHqQWoMFQ=; fh=teuuu96aRhCopkXuOxFj+Q2skgkILGdRv1xYtdVIE7A=; b=SeC6L8Podse7lKXAVcz2yUsz7uiC/fgPgU8/2UvlT65WVcslNGcr3kw8TebrviJml/ wQnXq8DxYIjFzcfH5Px3HsUYdbsJUddwIB3psbjufR/QMYpM8gItrTtWT5+Yf/vIfjD9 UmMSzo40PdUItyjsvzBqQwObotKwG4WBsrIU8Vs3gF3EpHcrTG3ZgylW/yo2GNDyWLAR ufHnSzB7gXdi6GpmGIozj6XcCJ0zucYW4++8WGjWAf9lYzaVb7Rj/ipbnISjqtbbqfXM u13qY/E0T/gam1jxYg+Tcp3cyK6qAK1+0PF9zYUTjFqxfkOSurQ7Ky3+3D5icy92jBm+ hF4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ly8Di8en; spf=pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=mirian.shilakadze@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a65b1101bcsi9017278f8f.465.2026.11.18.23.48.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 23:48:14 -0800 (PST) Received-SPF: pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ly8Di8en; spf=pass (google.com: domain of mirian.shilakadze@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=mirian.shilakadze@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=GIkl0oau1l/C6b8erMyedtUMQJbotQ2FKdUHqQWoMFQ=; b=ly8Di8enncGt AqIMf2SadlHL+FAHZiKJm4asTw3X4e0+bJaG/wz99plrNPPQZ7QHVvqKeMEHxw2JAaxeIgnVXWCCf 65yGA1kykxSZB5kPPT6GiWbIybEVf53RqaajhjOtN7Vk4HKWvVWsrbSUEQQB9F7OjcAtoGLgKzRf8 uwCg+BwRHP8Sf74mVHySsAG33bVFw5rm9x32H3ckZ14Fmswa8IIt+LcUNFs3guqfJjyudQR9E/37p pkKY3DOZQzq35U1L8p0GfHZo5qxUiSCJZG665Rm5zzIJoqwPuItnNug80fNQaFMFGszMmArbsrEpk 0yVv8apV2aKx7Xa/ii+VaA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=localhost.localdomain) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTwo7-008QkQ-0S; Thu, 19 Nov 2026 08:48:12 +0100 From: Mirian Shilakadze To: khorenko@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Thu, 19 Nov 2026 11:48:03 +0400 Message-ID: <20261119074808.478064-2-mirian.shilakadze@virtuozzo.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119074808.478064-1-mirian.shilakadze@virtuozzo.com> References: <20261119074808.478064-1-mirian.shilakadze@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org mount_cg2_fd() gave the tests their cgroup2 fd by creating a fresh mount with fsopen(), fsconfig() and fsmount(), with no options. That ends in cgroup_get_tree(), which calls apply_cgroup_root_flags() with the new mount's options once the tree is built. For a caller in the root cgroup namespace that function does not only set the flags the new mount asked for, it also clears on cgrp_dfl_root the nsdelegate, memory_recursiveprot and other root options the new mount did not carry, and cgrp_dfl_root is the one hierarchy behind every cgroup2 mount on the host. So every fixture setup switched nsdelegate and memory_recursiveprot off on the host /sys/fs/cgroup until something remounted it. A node the ve tests had run on shows its cgroup2 mount without either option, three untouched nodes of the same image still show both. Open the existing mount instead. open_cg2_fd() opens /sys/fs/cgroup as a directory fd and checks with fstatfs() that it is cgroup2. The *at() calls the tests make work on that fd as they did on the fsmount fd, and nothing is mounted, so the host flags stay as systemd set them. Every caller switches to it, and the skip messages that said "mount" now say "open". The header also no longer needs the glibc 2.36 mount API wrappers. Fixes: 2f614e4b0e5c ("selftests/ve: factor common helpers into ve_selftest.h") Feature: fix selftests https://virtuozzo.atlassian.net/browse/VSTOR-139515 Signed-off-by: Mirian Shilakadze --- tools/testing/selftests/ve/ve_aio_ring_test.c | 2 +- .../selftests/ve/ve_cpuid_override_test.c | 6 ++-- .../selftests/ve/ve_mount_accounting_test.c | 2 +- tools/testing/selftests/ve/ve_ns_owner_test.c | 2 +- .../selftests/ve/ve_numa_migrate_test.c | 4 +-- .../ve/ve_numa_syscalls_prohibited_test.c | 2 +- tools/testing/selftests/ve/ve_perms_test.c | 2 +- tools/testing/selftests/ve/ve_selftest.h | 36 ++++++++++--------- .../testing/selftests/ve/ve_tmpfs_mpol_test.c | 2 +- tools/testing/selftests/ve/ve_vtty_stress.c | 4 +-- 10 files changed, 33 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/ve/ve_aio_ring_test.c b/tools/testing/selftests/ve/ve_aio_ring_test.c index 1922a05aceef..c5b90427bdb3 100644 --- a/tools/testing/selftests/ve/ve_aio_ring_test.c +++ b/tools/testing/selftests/ve/ve_aio_ring_test.c @@ -152,7 +152,7 @@ FIXTURE_SETUP(ve_aio_ring) MAP_SHARED | MAP_ANONYMOUS, -1, 0); ASSERT_NE(self->arg, MAP_FAILED); - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); ASSERT_GE(self->cgv2_fd, 0); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", 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)); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", VE_CONTROLLERS), 0); @@ -164,7 +164,7 @@ FIXTURE_SETUP(ve_cpuid_override) /* * Runs after the test body in whichever process the harness picks, the test * process itself after a failed ASSERT, so the table is restored whether or - * not one fired. The setup fd may be gone by then, hence the fresh mount. + * not one fired. The setup fd may be gone by then, hence a fresh one. */ FIXTURE_TEARDOWN_PARENT(ve_cpuid_override) { @@ -179,7 +179,7 @@ FIXTURE_TEARDOWN_PARENT(ve_cpuid_override) if (self->child > 0) kill(self->child, SIGKILL); - cgv2_fd = mount_cg2_fd(); + cgv2_fd = open_cg2_fd(); if (cgv2_fd < 0) { TH_LOG("cgroup2 mount: %s, VE cgroup %d left behind", strerror(errno), self->ctid); diff --git a/tools/testing/selftests/ve/ve_mount_accounting_test.c b/tools/testing/selftests/ve/ve_mount_accounting_test.c index 8bb13e961542..3c0791e80527 100644 --- a/tools/testing/selftests/ve/ve_mount_accounting_test.c +++ b/tools/testing/selftests/ve/ve_mount_accounting_test.c @@ -294,7 +294,7 @@ FIXTURE_SETUP(ve_mnt_acc) int initial_mnt_avail_nr; char path[64]; - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); ASSERT_GE(self->cgv2_fd, 0); mkdir(TMP_DIR, 0755); diff --git a/tools/testing/selftests/ve/ve_ns_owner_test.c b/tools/testing/selftests/ve/ve_ns_owner_test.c index dcff4d54172d..a177514343a2 100644 --- a/tools/testing/selftests/ve/ve_ns_owner_test.c +++ b/tools/testing/selftests/ve/ve_ns_owner_test.c @@ -142,7 +142,7 @@ FIXTURE_SETUP(ve_ns_owner) char val[16]; char path[PATH_MAX]; - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); ASSERT_GE(self->cgv2_fd, 0); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", diff --git a/tools/testing/selftests/ve/ve_numa_migrate_test.c b/tools/testing/selftests/ve/ve_numa_migrate_test.c index 02e134bc914d..2223e770be62 100644 --- a/tools/testing/selftests/ve/ve_numa_migrate_test.c +++ b/tools/testing/selftests/ve/ve_numa_migrate_test.c @@ -363,9 +363,9 @@ static int prepare(FIXTURE_DATA(numa_migrate) *self, const char **why) { int fd; - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); if (self->cgv2_fd < 0) { - *why = "cannot mount cgroup2"; + *why = "cannot open cgroup2"; goto fail; } if (write_file_at(self->cgv2_fd, "cgroup.subtree_control", diff --git a/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c b/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c index c76fcb1c79ff..ef44b1191c70 100644 --- a/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c +++ b/tools/testing/selftests/ve/ve_numa_syscalls_prohibited_test.c @@ -126,7 +126,7 @@ FIXTURE_SETUP(numa_syscalls) } ASSERT_LT(i, NODE_BITS); - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); ASSERT_GE(self->cgv2_fd, 0); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", VE_CONTROLLERS), 0); 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); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", 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 @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * Shared helpers for the ve selftests: a private cgroup2 mount, small file and - * cgroup helpers, VE cgroup create and destroy, and a mount point query, used - * across the tests in this directory. + * Shared helpers for the ve selftests: the host cgroup2 mount as a directory + * fd, small file and cgroup helpers, VE cgroup create and destroy, and a mount + * point query, used across the tests in this directory. */ #ifndef __SELFTESTS_VE_VE_SELFTEST_H #define __SELFTESTS_VE_VE_SELFTEST_H @@ -15,8 +15,9 @@ #include #include #include -#include +#include #include +#include #include #ifndef CLONE_NEWVE @@ -245,23 +246,26 @@ static inline int read_s32_at(int dirfd, const char *path, return 0; } -/* A fresh, private cgroup2 mount, returned as an fd to use with *at() calls. */ -static inline int mount_cg2_fd(void) +/* + * The host cgroup2 mount as a directory fd to use with *at() calls. The mount + * is opened, not created: mounting cgroup2 from the root cgroup namespace + * applies the new mount's options to the whole hierarchy and clears the ones + * it does not carry, nsdelegate and memory_recursiveprot included. + */ +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; } - - mnt_fd = fsmount(fs_fd, 0, 0); - close(fs_fd); - return mnt_fd; + return fd; } /* Move the caller into cgroup @ctid (or the root when @ctid is 0). */ diff --git a/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c b/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c index 6254f95fadec..dbc1a51941a0 100644 --- a/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c +++ b/tools/testing/selftests/ve/ve_tmpfs_mpol_test.c @@ -57,7 +57,7 @@ FIXTURE_SETUP(tmpfs_mpol) SKIP(return, "no NUMA API on the host"); ASSERT_EQ(ret, 0); - self->cgv2_fd = mount_cg2_fd(); + self->cgv2_fd = open_cg2_fd(); ASSERT_GE(self->cgv2_fd, 0); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", VE_CONTROLLERS), 0); diff --git a/tools/testing/selftests/ve/ve_vtty_stress.c b/tools/testing/selftests/ve/ve_vtty_stress.c index f4bdd81133b8..318ccab5bcdb 100644 --- a/tools/testing/selftests/ve/ve_vtty_stress.c +++ b/tools/testing/selftests/ve/ve_vtty_stress.c @@ -192,9 +192,9 @@ int main(int argc, char **argv) "(vzdev, vzmon) are needed\n", strerror(errno)); - cg = mount_cg2_fd(); + cg = open_cg2_fd(); if (cg < 0) - ksft_exit_skip("cannot mount cgroup2: %s\n", strerror(errno)); + ksft_exit_skip("cannot open cgroup2: %s\n", strerror(errno)); if (write_file_at(cg, "cgroup.subtree_control", VE_CONTROLLERS) < 0) ksft_exit_skip("cannot enable the ve controller: %s\n", strerror(errno)); -- 2.47.3 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel