From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1] tst_cgroup.c: Force tst_cg_scan only scan specific cgroup version if needs_ver exist
Date: Fri, 8 Nov 2024 00:37:10 -0500 [thread overview]
Message-ID: <20241108053710.8639-1-wegao@suse.com> (raw)
tst_cgroup.c will scan cgroup mount point and check system's cgroup support status, both
cgroupv1 and cgroupv2, if your case only need check cgroupv1(such as needs_cgroup_ver = TST_CG_V1)
but your system contain cgroupv2 mount point, then TCONF will happen tell you your system already
mount cgroupv2, so test case will be skipped.
This change will fix above scenario, force check specific version of cgroup once you set needs_ver,
then test will continue try to create needs_ver of cgroup mount point.
This patch can be used by following cpuset02 case:
https://patchwork.ozlabs.org/project/ltp/patch/20240930135809.9300-1-wegao@suse.com/
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_cgroup.h | 2 +-
lib/newlib_tests/tst_cgroup01.c | 2 +-
lib/newlib_tests/tst_cgroup02.c | 2 +-
lib/tst_cgroup.c | 15 +++++++--------
testcases/lib/tst_cgctl.c | 4 ++--
5 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index d23a8e652..ff1c4ece0 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -117,7 +117,7 @@ extern const struct tst_cg_group *const tst_cg_drain;
/* Search the system for mounted cgroups and available
* controllers. Called automatically by tst_cg_require.
*/
-void tst_cg_scan(void);
+void tst_cg_scan(enum tst_cg_ver needs_ver);
/* Print the config detected by tst_cg_scan and print the internal
* state associated with each controller. Output can be passed to
* tst_cg_load_config to configure the internal state to that of the
diff --git a/lib/newlib_tests/tst_cgroup01.c b/lib/newlib_tests/tst_cgroup01.c
index eda0c548d..00bced72b 100644
--- a/lib/newlib_tests/tst_cgroup01.c
+++ b/lib/newlib_tests/tst_cgroup01.c
@@ -23,7 +23,7 @@ static void setup(void)
{
cgopts.needs_ver = !!only_mount_v1 ? TST_CG_V1 : 0;
- tst_cg_scan();
+ tst_cg_scan(0);
tst_cg_print_config();
tst_cg_require("memory", &cgopts);
diff --git a/lib/newlib_tests/tst_cgroup02.c b/lib/newlib_tests/tst_cgroup02.c
index de2ca1812..47d1c6b2a 100644
--- a/lib/newlib_tests/tst_cgroup02.c
+++ b/lib/newlib_tests/tst_cgroup02.c
@@ -58,7 +58,7 @@ static void setup(void)
{
cgopts.needs_ver = !!only_mount_v1 ? TST_CG_V1 : 0;
- tst_cg_scan();
+ tst_cg_scan(0);
tst_cg_print_config();
tst_cg_require("memory", &cgopts);
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 1404116a5..652bb70b5 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -657,7 +657,7 @@ discard:
close(mnt_dfd);
}
-void tst_cg_scan(void)
+void tst_cg_scan(enum tst_cg_ver needs_ver)
{
struct mntent *mnt;
FILE *f = setmntent("/proc/self/mounts", "r");
@@ -674,10 +674,9 @@ void tst_cg_scan(void)
}
do {
- if (strncmp(mnt->mnt_type, "cgroup", 6))
- continue;
-
- cgroup_root_scan(mnt->mnt_type, mnt->mnt_dir, mnt->mnt_opts);
+ if ((!strcmp(mnt->mnt_type, "cgroup") && (needs_ver != TST_CG_V2)) ||
+ (!strcmp(mnt->mnt_type, "cgroup2") && (needs_ver != TST_CG_V1)))
+ cgroup_root_scan(mnt->mnt_type, mnt->mnt_dir, mnt->mnt_opts);
} while ((mnt = getmntent(f)));
}
@@ -717,7 +716,7 @@ mount:
if (!ret) {
tst_res(TINFO, "Mounted V2 CGroups on %s", mnt_path);
- tst_cg_scan();
+ tst_cg_scan(TST_CG_V2);
roots[0].we_mounted_it = 1;
return;
}
@@ -775,7 +774,7 @@ mount:
}
tst_res(TINFO, "Mounted V1 %s CGroup on %s", ctrl->ctrl_name, mnt_path);
- tst_cg_scan();
+ tst_cg_scan(TST_CG_V1);
if (!ctrl->ctrl_root)
return;
@@ -856,7 +855,7 @@ void tst_cg_require(const char *const ctrl_name,
if (ctrl->ctrl_root)
goto mkdirs;
- tst_cg_scan();
+ tst_cg_scan(options->needs_ver);
if (ctrl->ctrl_root)
goto mkdirs;
diff --git a/testcases/lib/tst_cgctl.c b/testcases/lib/tst_cgctl.c
index 2685bef81..6f324f780 100644
--- a/testcases/lib/tst_cgctl.c
+++ b/testcases/lib/tst_cgctl.c
@@ -30,7 +30,7 @@ static int cgctl_require(const char *ctrl, int test_pid)
static int cgctl_cleanup(const char *const config)
{
- tst_cg_scan();
+ tst_cg_scan(0);
tst_cg_load_config(config);
tst_cg_cleanup();
@@ -39,7 +39,7 @@ static int cgctl_cleanup(const char *const config)
static int cgctl_print(void)
{
- tst_cg_scan();
+ tst_cg_scan(0);
tst_cg_print_config();
return 0;
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-11-08 5:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 5:37 Wei Gao via ltp [this message]
2024-11-08 9:53 ` [LTP] [PATCH v1] tst_cgroup.c: Force tst_cg_scan only scan specific cgroup version if needs_ver exist Cyril Hrubis
2024-11-08 11:21 ` Wei Gao via ltp
2024-11-08 11:23 ` Cyril Hrubis
2024-11-11 2:47 ` Wei Gao via ltp
2024-11-11 12:08 ` Cyril Hrubis
[not found] ` <dnhjiv6iqwbref6kaq2amylqbwrksnph3l7ewxgqetp6crrz3s@3k5j5t4sy2gl>
2024-12-05 13:16 ` Cyril Hrubis
2024-12-09 11:25 ` Wei Gao via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241108053710.8639-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox