|
|
5db3bf |
From 8100a3ae8c6abff99fb512d126055f4b603f4517 Mon Sep 17 00:00:00 2001
|
|
|
5db3bf |
From: John Kacur <jkacur@redhat.com>
|
|
|
5db3bf |
Date: Thu, 18 Nov 2021 13:48:10 -0500
|
|
|
5db3bf |
Subject: [PATCH 1/2] rt-tests: deadline_test: Fix double mount of cgroups
|
|
|
5db3bf |
|
|
|
5db3bf |
If /sys/fs/cgroup exists and it is type cgroup2, deadline mounts it a
|
|
|
5db3bf |
second time as cgroup.
|
|
|
5db3bf |
|
|
|
5db3bf |
systemd is creating cgroup2 for logins and this can hang the machine and
|
|
|
5db3bf |
not allow logins.
|
|
|
5db3bf |
|
|
|
5db3bf |
Fix this by:
|
|
|
5db3bf |
|
|
|
5db3bf |
If /sys/fs/cgroup exists, then use it for deadline_test.
|
|
|
5db3bf |
|
|
|
5db3bf |
If it exists but the type is not recognized, exit with an error.
|
|
|
5db3bf |
Do not simply mount it as type cgroup.
|
|
|
5db3bf |
|
|
|
5db3bf |
TODO: If the file doesn't exit but cgroups are supported in the kernel,
|
|
|
5db3bf |
the file could be created and mounted.
|
|
|
5db3bf |
|
|
|
5db3bf |
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
|
5db3bf |
---
|
|
|
5db3bf |
src/sched_deadline/deadline_test.c | 39 ++++++++++++++++++++++++------
|
|
|
5db3bf |
1 file changed, 32 insertions(+), 7 deletions(-)
|
|
|
5db3bf |
|
|
|
5db3bf |
diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
|
|
|
5db3bf |
index b7e1e045b57c..11d669025425 100644
|
|
|
5db3bf |
--- a/src/sched_deadline/deadline_test.c
|
|
|
5db3bf |
+++ b/src/sched_deadline/deadline_test.c
|
|
|
5db3bf |
@@ -518,6 +518,32 @@ static int mounted(const char *path, long magic)
|
|
|
5db3bf |
#define CGROUP_PATH "/sys/fs/cgroup"
|
|
|
5db3bf |
#define CPUSET_PATH CGROUP_PATH "/cpuset"
|
|
|
5db3bf |
|
|
|
5db3bf |
+/**
|
|
|
5db3bf |
+ * cgroup_mounted - test if the path /sys/fs/cgroup exists
|
|
|
5db3bf |
+ * and is a supported type
|
|
|
5db3bf |
+ *
|
|
|
5db3bf |
+ * Returns -1 if the path does not exist
|
|
|
5db3bf |
+ * Returns 0 if the path exists but is not a cgroup type
|
|
|
5db3bf |
+ * Returns 1 if the path exists and supports cgroups
|
|
|
5db3bf |
+ */
|
|
|
5db3bf |
+static int cgroup_mounted(void)
|
|
|
5db3bf |
+{
|
|
|
5db3bf |
+ int ret;
|
|
|
5db3bf |
+
|
|
|
5db3bf |
+ ret = mounted(CGROUP_PATH, TMPFS_MAGIC);
|
|
|
5db3bf |
+ if (ret == -1)
|
|
|
5db3bf |
+ return -1; /* path doesn't exist */
|
|
|
5db3bf |
+ if (ret == 1)
|
|
|
5db3bf |
+ return 1; /* tmpfs */
|
|
|
5db3bf |
+ ret = mounted(CGROUP_PATH, CGROUP_SUPER_MAGIC);
|
|
|
5db3bf |
+ if (ret == 1)
|
|
|
5db3bf |
+ return 1; /* cgroup v1 */
|
|
|
5db3bf |
+ ret = mounted(CGROUP_PATH, CGROUP2_SUPER_MAGIC);
|
|
|
5db3bf |
+ if (ret == 1)
|
|
|
5db3bf |
+ return 1;
|
|
|
5db3bf |
+ return 0; /* path exists but type is not recognized */
|
|
|
5db3bf |
+}
|
|
|
5db3bf |
+
|
|
|
5db3bf |
/**
|
|
|
5db3bf |
* open_cpuset - open a file (usually a cpuset file)
|
|
|
5db3bf |
* @path: The path of the directory the file is in
|
|
|
5db3bf |
@@ -568,14 +594,13 @@ static int mount_cpuset(void)
|
|
|
5db3bf |
int fd;
|
|
|
5db3bf |
|
|
|
5db3bf |
/* Check if cgroups is already mounted. */
|
|
|
5db3bf |
- ret = mounted(CGROUP_PATH, TMPFS_MAGIC);
|
|
|
5db3bf |
- if (ret < 0)
|
|
|
5db3bf |
+ ret = cgroup_mounted();
|
|
|
5db3bf |
+ if (ret < 0) /* /sys/fs/cgroup doesn't exist */
|
|
|
5db3bf |
return ret;
|
|
|
5db3bf |
- if (!ret) {
|
|
|
5db3bf |
- ret = mount("cgroup_root", CGROUP_PATH, "tmpfs", 0, NULL);
|
|
|
5db3bf |
- if (ret < 0)
|
|
|
5db3bf |
- return ret;
|
|
|
5db3bf |
- }
|
|
|
5db3bf |
+
|
|
|
5db3bf |
+ if (!ret) /* /sys/fs/cgroup exists, but we don't recognize the type */
|
|
|
5db3bf |
+ return -1;
|
|
|
5db3bf |
+
|
|
|
5db3bf |
ret = stat(CPUSET_PATH, &st);
|
|
|
5db3bf |
if (ret < 0) {
|
|
|
5db3bf |
ret = mkdir(CPUSET_PATH, 0755);
|
|
|
5db3bf |
--
|
|
|
5db3bf |
2.31.1
|
|
|
5db3bf |
|