|
|
5db3bf |
From a933af2b82ea90a51a2600cf88cfcc5f2fba9804 Mon Sep 17 00:00:00 2001
|
|
|
5db3bf |
From: John Kacur <jkacur@redhat.com>
|
|
|
5db3bf |
Date: Thu, 18 Nov 2021 14:12:23 -0500
|
|
|
5db3bf |
Subject: [PATCH 2/2] rt-tests: cyclicdeadline: Fix double mount of cgroups
|
|
|
5db3bf |
|
|
|
5db3bf |
If /sys/fs/cgroup exists and it is type cgroup2, cyclicdeadline 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 cyclicdeadline_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/cyclicdeadline.c | 39 +++++++++++++++++++++++------
|
|
|
5db3bf |
1 file changed, 32 insertions(+), 7 deletions(-)
|
|
|
5db3bf |
|
|
|
5db3bf |
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
|
|
|
5db3bf |
index 4860a40f5e6b..1f9a5df42d4f 100644
|
|
|
5db3bf |
--- a/src/sched_deadline/cyclicdeadline.c
|
|
|
5db3bf |
+++ b/src/sched_deadline/cyclicdeadline.c
|
|
|
5db3bf |
@@ -358,6 +358,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 |
static int open_cpuset(const char *path, const char *name)
|
|
|
5db3bf |
{
|
|
|
5db3bf |
char buf[MAXPATH];
|
|
|
5db3bf |
@@ -383,14 +409,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 |
|