[LTP] [RFC PATCH] tst_cgroup: Avoid mixing mounts V1 and V2 simultaneously

Li Wang liwang@redhat.com
Fri Apr 28 10:49:22 CEST 2023


There is a tiny problem with the test logic of this tst_cgroup library,
that it potentially mixes Cgroup V1 and V2 together to be mounted at
the same time. The scenario happens once people just requests CTRL_BASE
(or a V2 controller not enabled) on a only V1-mounted system.

Cgroup community always objected to enabling Cgroup like that (V1&V2),
which may bring unexpected issues along the way.

So this patch cancels LTP mount V1&V2 simultaneously even if there is
no overlap in specific controller files.

Note:
  This patch is a follow-up on GAO Wei's work about adding CTRL_BASE.
  So we need to apply after that patchset.

Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Richard Palethorpe <rpalethorpe@suse.de>
Cc: Wei Gao <wegao@suse.com>
---
 lib/tst_cgroup.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index d08a31651..bceb10d1d 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -786,6 +786,10 @@ static void cgroup_copy_cpuset(const struct cgroup_root *const root)
  * If we can't mount V2 or the controller is not on V2, then we try
  * mounting it on its own V1 tree.
  *
+ * The worth mentioning here is that once there detect V1 mounted,
+ * we skip mounting V2 because LTP doesn't allow V1 and V2 mixes to
+ * be tested in any scenario, and vice versa.
+ *
  * Once we have mounted the controller somehow, we create a hierarchy
  * of cgroups. If we are on V2 we first need to enable the controller
  * for all children of root. Then we create hierarchy described in
@@ -828,13 +832,14 @@ void tst_cg_require(const char *const ctrl_name,
 	if (ctrl->ctrl_root)
 		goto mkdirs;
 
-	if (!cgroup_v2_mounted() && options->needs_ver != TST_CG_V1)
+	if (!cgroup_v2_mounted() && options->needs_ver != TST_CG_V1
+			&& !cgroup_v1_mounted())
 		cgroup_mount_v2();
 
 	if (ctrl->ctrl_root)
 		goto mkdirs;
 
-	if (options->needs_ver != TST_CG_V2)
+	if (options->needs_ver != TST_CG_V2 && !cgroup_v2_mounted())
 		cgroup_mount_v1(ctrl);
 
 	if (base)
-- 
2.40.0



More information about the ltp mailing list