prplOS: procd: LCM: Add patch to fix cgroups mount

Properly mount cgroups in a root tmpfs where every controller is mounted
in a seperate subdirectory, recommended by the kernel documentation of
cgroupsv1.

Signed-off-by: Matthias FRANCK <matthias.franck_ext@softathome.com>
(cherry picked from commit af84ad24a6acd355ec39c8355eccb02e47b3bec6)
This commit is contained in:
Matthias FRANCK 2022-03-23 13:42:48 +01:00 committed by Petr Štetiar
parent 2f71787c0f
commit 85dabba53d
No known key found for this signature in database
GPG Key ID: 58EE120F30CC02D3

View File

@ -0,0 +1,61 @@
--- a/initd/early.c
+++ b/initd/early.c
@@ -27,6 +27,9 @@
#include "../libc-compat.h"
#include "../container.h"
+#define PATH_CGROUP "/sys/fs/cgroup"
+#define PATH_PROC_CGROUPS "/proc/cgroups"
+
static void
early_dev(void)
{
@@ -53,6 +56,37 @@ early_console(const char *dev)
}
static void
+mount_cgroup_controllers(void){
+ char cgroups_line[256] = {0};
+ // Getting supported cgroup controllers from the kernel
+ FILE *filp_cgroups = fopen(PATH_PROC_CGROUPS, "r");
+ if(! filp_cgroups ){
+ ERROR("Failed to open " PATH_PROC_CGROUPS);
+ return;
+ }
+ while( fgets(cgroups_line, 256, filp_cgroups) ){
+ char *space;
+ char fullpath[256] = {0};
+ if(cgroups_line[0] == '#') continue;
+ space = strchr(cgroups_line, '\t');
+ if(! space) continue;
+ *space = '\0';
+
+ if( snprintf(fullpath, 255, PATH_CGROUP "/%s", cgroups_line) < 1){
+ ERROR("Cannot make controller path: %s\n", cgroups_line);
+ continue;
+ }
+ if( mkdir(fullpath, 0777) ){
+ ERROR("Cannot create controller path: %s\n", fullpath);
+ continue;
+ }
+ mount(cgroups_line, fullpath, "cgroup", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, cgroups_line);
+ LOG("Mounted %s\n", fullpath);
+ }
+ fclose(filp_cgroups);
+}
+
+static void
early_mounts(void)
{
unsigned int oldumask = umask(0);
@@ -60,7 +94,9 @@ early_mounts(void)
if (!is_container()) {
mount("proc", "/proc", "proc", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
mount("sysfs", "/sys", "sysfs", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
- mount("cgroup2", "/sys/fs/cgroup", "cgroup2", MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_RELATIME, "nsdelegate");
+ LOG("Attempting to mount cgroups (tmpfs + controller subdirs)\n");
+ mount("cgroup2", PATH_CGROUP, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID, "size=512K");
+ mount_cgroup_controllers();
mount("tmpfs", "/dev", "tmpfs", MS_NOATIME | MS_NOEXEC | MS_NOSUID, "mode=0755,size=512K");
ignore(symlink("/tmp/shm", "/dev/shm"));
mkdir("/dev/pts", 0755);