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 1A98480027 for ; Thu, 19 Nov 2026 08:18:24 +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 6AJ8H8OT003927; Thu, 19 Nov 2026 11:17:09 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ8H8OT003927 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="vB01T8+Y" Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ8H0GE003903 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 11:17:00 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ8H0GE003903 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49febef74e3so3958265e9.0 for ; Thu, 19 Nov 2026 00:17:00 -0800 (PST) X-Gm-Message-State: APuU4Z88NFrf1r9fQqYAE+3r1cKzPe+cuqxzXmtt1hVgzIa1Pr5bD+b/ TT8eUzG5DikGMRERmLi59rJWuRHbIGX3aoBr0FidmxnfNhvXXH+B2wPAsZDIMawgQoi+O22I1q0 wwRS9+sCfq1KX1Y8uVkD4ajaqe7Io6Nnsv/pZHxpJXDnbu6z71eBseg== X-Gm-Gg: AYBFou2esSQYfAhh6j9At9bkzjH6fKx0rnHI8bTzq+bp3VGF+WqDrWiwUqdpro3STpB F9dvSEBSCmTo9fL8P/NOuU0FMvPY23alwLZwxkXFm2BOmJSDPzMRXS9/N5Znp9FSyJ7+oAk0SDk PMQ1RbwQpFBFzI5WD2dctlRQuXggKXHoGD4pd3tvGPdonfnqXHGrDiA7TqJv1IfcwmpctCnVl9N /6dhtQ7p71m56SmOJ9FwG1jKDGRQdTTo8FlYxNxryOJ8p35yp+T5c5mpsQ/mb5smVvlRUakaXAP T/hzPs22rEgDc8EeuBAsekZIVkUqKaPZz3hYgXD/9uHKOp03vBSi5HSBzyS6DqCG+vE+ACtCfg7 +5LavD1bBbIRR04/Q+j8emMqLHY8b X-Received: by 2002:a05:600c:5901:b0:4bb:5e8a:7c9c with SMTP id 5b1f17b1804b1-4bb861467c8mr6115705e9.7.1795076220375; Thu, 19 Nov 2026 00:17:00 -0800 (PST) X-Received: by 2002:a05:600c:5901:b0:4bb:5e8a:7c9c with SMTP id 5b1f17b1804b1-4bb861467c8mr6115365e9.7.1795076219951; Thu, 19 Nov 2026 00:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795076219; cv=none; d=google.com; s=arc-20260327; b=KIG3IeYd2sJZFnvPq39r1KFxb6MdgJj/wSZajGnyLI2jMoZpHdZ3xeX5xGZbvV4wKG gV0g4h42aWv7XsmpAr/0WRBxGEHCiNlLu9wIWOE7+RksKNSTcfsNvslCfZLMDzuaTgMl 0wpJcYDhMXgogq2MY5A7cJsRJ/9qO54t7pFespBsiTO8ketH++Ood/RBkwcyV3hTlW+g 7umZBJxm5jIdXz+rjLhr/ptzrZOKEMwXqsGGvsobkdxKlqzmypsymP1vU2z8rHTd3VoY qmde/xgO/Yu0TbeTYkHE78CSDOYUweYQZPjealHH1a95K3Aq0UW0MG7t2xkP1ue8axaz wSnw== 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=/Eq4c7Jm8A3RXfhFX1qKqO0eQIkF4Z9Px9ZFSXnHero=; fh=DyeaEZPHV4v28duuFe2DGUlI2E+s+GAoStNDx0CyIL0=; b=Hm97pqV+Gv15DH4ZcUqGgT5vDkXd0mKw/sK1MCB9gTh/RmpEdqtKivaXc0eEuZy5Kd 2MPQXQKx1F2JZ4BnXJgHVNKvUYVrZ2nqnL1ZkWieRjdjC1C9nPFE4wN/vDvhuxgB1hb/ /7xBma/9sDwrS7E6cCApIIT2oYvwwrjxHC0i1DpO5U7VDy9/Q01JigdnRIyUe4d7LxvP +mMRlrVyl457cyWwBSsv8/j/CZT+HpZrnRxf+Xz+Ygnb/bg/tRz5XJbYLeVZhvqyr0Kl K7nawSRfHrZdvuYqt4z6F8jegxXyG2i2Bjf+Rpp/x3FdLsiMibTpXzlJh38aypIgguQC cBQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=vB01T8+Y; 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-4a6574b13a3si9237780f8f.81.2026.11.19.00.16.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 00:16:59 -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=vB01T8+Y; 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=/Eq4c7Jm8A3RXfhFX1qKqO0eQIkF4Z9Px9ZFSXnHero=; b=vB01T8+Y0GxP l0YFrFRbkZkbykffVvakAnlWqQWq1eHSlRkcm2cim1DDSQgN2fatdJ4uB2+I4gAjjjjgXifK1mDx2 /KY9Q0l87gv5gpq5gS722hFZDvju7cefzelBYmup8F3WnQRMMiBbAjPG8lt0ibV40i4YrBfEQ2ovn qf1kGvtAt8g7y7PZwDJ3zR/IKGMzTTryMa+9TUfo7gHrpxyMS/pgvhRNBLkLinGNFof2Yf0YZSJBr jq8FwFXomOXG1Pl1XtvGaLLmarb8e0LE+9IXxDhAiKSIa97navKtx3V93jlBNCaqJWjdwNpTFfhJN oCJsRYZ3+iBy/1j2wYIBzQ==; 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 1xTxFw-008ys0-0s; Thu, 19 Nov 2026 09:16:57 +0100 From: Mirian Shilakadze To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 19 Nov 2026 12:16:26 +0400 Message-ID: <20261119081654.484107-2-mirian.shilakadze@virtuozzo.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119081654.484107-1-mirian.shilakadze@virtuozzo.com> References: <20261119081654.484107-1-mirian.shilakadze@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 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. The tests now need the host cgroup2 mount at /sys/fs/cgroup, which every vz10 host has. Every caller switches to it, and the 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 | 10 +++--- .../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, 35 insertions(+), 31 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..fe8959b2adf3 100644 --- a/tools/testing/selftests/ve/ve_cpuid_override_test.c +++ b/tools/testing/selftests/ve/ve_cpuid_override_test.c @@ -153,8 +153,8 @@ 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(); - ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cgroup2 mount: %s", strerror(errno)); + self->cgv2_fd = open_cg2_fd(); + ASSERT_GE(self->cgv2_fd, 0) TH_LOG("cannot open cgroup2: %s", strerror(errno)); ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control", VE_CONTROLLERS), 0); self->ctid = make_ve(self->cgv2_fd, CTID_MIN); @@ -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,9 +179,9 @@ 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", + TH_LOG("cannot open cgroup2: %s, VE cgroup %d left behind", strerror(errno), self->ctid); return; } 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