rt-tests: deadline_test: Fix double mount of cgroups
PATCH 1/2 rt-tests: deadline_test: Fix double mount of cgroups
If /sys/fs/cgroup exists and it is type cgroup2, deadline mounts it a second time as cgroup.
systemd is creating cgroup2 for logins and this can hang the machine and not allow logins.
Fix this by:
If /sys/fs/cgroup exists, then use it for deadline_test.
If it exists but the type is not recognized, exit with an error. Do not simply mount is as type cgroup.
TODO: If the file doesn't exit but cgroups are supported in the kernel, the file could be created and mounted.
--- src/sched_deadline/deadline_test.c | 39 ++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-)
src/sched_deadline/deadline_test.c +32 -7
@@ -518,6 +518,32 @@ static int mounted(const char *path, long magic)#define CGROUP_PATH "/sys/fs/cgroup"#define CPUSET_PATH CGROUP_PATH "/cpuset" +/** +* cgroup_mounted - test if the path /sys/fs/cgroup exists +* and is a supported type +* +* Returns -1 if the path does not exist +* Returns 0 if the path exists but is not a cgroup type +* Returns 1 if the path exists and supports cgroups +*/ +static int cgroup_mounted (void ) +{ +int ret; + + ret =mounted (CGROUP_PATH ,TMPFS_MAGIC ); +if (ret ==-1 ) +return -1 ;/* path doesn't exist */ +if (ret ==1 ) +return 1 ;/* tmpfs */ + ret =mounted (CGROUP_PATH ,CGROUP_SUPER_MAGIC ); +if (ret ==1 ) +return 1 ;/* cgroup v1 */ + ret =mounted (CGROUP_PATH ,CGROUP2_SUPER_MAGIC ); +if (ret ==1 ) +return 1 ; +return 0 ;/* path exists but type is not recognized */ +} +/** * open_cpuset - open a file (usually a cpuset file) * @path: The path of the directory the file is in
@@ -568,14 +594,13 @@ static int mount_cpuset(void)int fd;/* Check if cgroups is already mounted. */ - ret =mounted (CGROUP_PATH ,TMPFS_MAGIC ); -if (ret <0 ) + ret =cgroup_mounted (); +if (ret <0 )/* /sys/fs/cgroup doesn't exist */ return ret; -if (!ret) { - ret =mount ("cgroup_root" ,CGROUP_PATH ,"tmpfs" ,0 ,NULL ); -if (ret <0 ) -return ret; - } + +if (!ret)/* /sys/fs/cgroup exists, but we don't recognize the type */ +return -1 ; + ret =stat (CPUSET_PATH , &st);if (ret <0 ) { ret =mkdir (CPUSET_PATH ,0755 );
Signature · 1 line
2.31.1
PATCH 2/2 rt-tests: cyclicdeadline: Fix double mount of cgroups
If /sys/fs/cgroup exists and it is type cgroup2, cyclicdeadline mounts it a second time as cgroup.
systemd is creating cgroup2 for logins and this can hang the machine and not allow logins.
Fix this by:
If /sys/fs/cgroup exists, then use it for cyclicdeadline_test.
If it exists but the type is not recognized, exit with an error. Do not simply mount is as type cgroup.
TODO: If the file doesn't exit but cgroups are supported in the kernel, the file could be created and mounted.
--- src/sched_deadline/cyclicdeadline.c | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-)
src/sched_deadline/cyclicdeadline.c +32 -7
@@ -358,6 +358,32 @@ static int mounted(const char *path, long magic)#define CGROUP_PATH "/sys/fs/cgroup"#define CPUSET_PATH CGROUP_PATH "/cpuset" +/** +* cgroup_mounted - test if the path /sys/fs/cgroup exists +* and is a supported type +* +* Returns -1 if the path does not exist +* Returns 0 if the path exists but is not a cgroup type +* Returns 1 if the path exists and supports cgroups +*/ +static int cgroup_mounted (void ) +{ +int ret; + + ret =mounted (CGROUP_PATH ,TMPFS_MAGIC ); +if (ret ==-1 ) +return -1 ;/* path doesn't exist */ +if (ret ==1 ) +return 1 ;/* tmpfs */ + ret =mounted (CGROUP_PATH ,CGROUP_SUPER_MAGIC ); +if (ret ==1 ) +return 1 ;/* cgroup v1 */ + ret =mounted (CGROUP_PATH ,CGROUP2_SUPER_MAGIC ); +if (ret ==1 ) +return 1 ; +return 0 ;/* path exists but type is not recognized */ +} +static int open_cpuset (const char *path,const char *name) {char buf[MAXPATH ];
@@ -383,14 +409,13 @@ static int mount_cpuset(void)int fd;/* Check if cgroups is already mounted. */ - ret =mounted (CGROUP_PATH ,TMPFS_MAGIC ); -if (ret <0 ) + ret =cgroup_mounted (); +if (ret <0 )/* /sys/fs/cgroup doesn't exist */ return ret; -if (!ret) { - ret =mount ("cgroup_root" ,CGROUP_PATH ,"tmpfs" ,0 ,NULL ); -if (ret <0 ) -return ret; - } + +if (!ret)/* /sys/fs/cgroup exists, but we don't recognize the type */ +return -1 ; + ret =stat (CPUSET_PATH , &st);if (ret <0 ) { ret =mkdir (CPUSET_PATH ,0755 );
Signature · 1 line
2.31.1