From c9ea11b598b5480c0ef415e8162ce703140b4b11 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" <mgrondona@llnl.gov> Date: Wed, 27 Jul 2011 16:58:41 -0700 Subject: [PATCH] cgroups: Allow cgroup mount point to be configurable cgroups code currently assumes cgroup subsystems will be mounted under /cgroup, which is not the ideal location for many situations. Add a new cgroup.conf parameter to redefine the mount point to an arbitrary location. (for example, some systems may already have cgroupfs mounted under /dev/cgroup or /sys/fs/cgroup) --- src/common/xcgroup.c | 7 +++++-- src/common/xcgroup.h | 8 +++----- src/common/xcgroup_read_config.c | 12 +++++++++++- src/common/xcgroup_read_config.h | 1 + src/plugins/proctrack/cgroup/proctrack_cgroup.c | 2 +- src/plugins/task/cgroup/task_cgroup_cpuset.c | 2 +- src/plugins/task/cgroup/task_cgroup_devices.c | 2 +- src/plugins/task/cgroup/task_cgroup_memory.c | 2 +- 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/common/xcgroup.c b/src/common/xcgroup.c index 8cc8b6376d2..64e0af11ca5 100644 --- a/src/common/xcgroup.c +++ b/src/common/xcgroup.c @@ -93,10 +93,13 @@ int _file_write_content(char* file_path, char* content, size_t csize); * - XCGROUP_ERROR * - XCGROUP_SUCCESS */ -int xcgroup_ns_create(xcgroup_ns_t* cgns, char* mnt_point, char* mnt_args, +int xcgroup_ns_create(slurm_cgroup_conf_t *conf, + xcgroup_ns_t* cgns, char* mnt_point, char* mnt_args, char* subsys, char* notify_prog) { - cgns->mnt_point = xstrdup(mnt_point); + cgns->mnt_point = xstrdup(conf->cgroup_mountpoint); + xstrcat(cgns->mnt_point, mnt_point); + cgns->mnt_args = xstrdup(mnt_args); cgns->subsystems = xstrdup(subsys); cgns->notify_prog = xstrdup(notify_prog); diff --git a/src/common/xcgroup.h b/src/common/xcgroup.h index cea81f99909..7b83d278889 100644 --- a/src/common/xcgroup.h +++ b/src/common/xcgroup.h @@ -43,14 +43,11 @@ #include <sys/types.h> #include <dirent.h> +#include "xcgroup_read_config.h" #define XCGROUP_ERROR 1 #define XCGROUP_SUCCESS 0 -#ifndef CGROUP_BASEDIR -#define CGROUP_BASEDIR "/cgroup" -#endif - typedef struct xcgroup_ns { char* mnt_point; /* mount point to use for the associated cgroup */ @@ -80,7 +77,8 @@ typedef struct xcgroup { * - XCGROUP_ERROR * - XCGROUP_SUCCESS */ -int xcgroup_ns_create(xcgroup_ns_t* cgns, +int xcgroup_ns_create(slurm_cgroup_conf_t *conf, + xcgroup_ns_t* cgns, char* mnt_point,char* mnt_args, char* subsys,char* notify_prog); diff --git a/src/common/xcgroup_read_config.c b/src/common/xcgroup_read_config.c index 6f711408452..ef2397d584f 100644 --- a/src/common/xcgroup_read_config.c +++ b/src/common/xcgroup_read_config.c @@ -54,6 +54,8 @@ #include "xcgroup_read_config.h" +#define DEFAULT_CGROUP_BASEDIR "/cgroup" + slurm_cgroup_conf_t *slurm_cgroup_conf = NULL; /* Local functions */ @@ -73,6 +75,7 @@ static void _clear_slurm_cgroup_conf(slurm_cgroup_conf_t *slurm_cgroup_conf) { if (slurm_cgroup_conf) { slurm_cgroup_conf->cgroup_automount = false ; + xfree(slurm_cgroup_conf->cgroup_mountpoint); xfree(slurm_cgroup_conf->cgroup_subsystems); xfree(slurm_cgroup_conf->cgroup_release_agent); slurm_cgroup_conf->constrain_cores = false ; @@ -97,6 +100,7 @@ extern int read_slurm_cgroup_conf(slurm_cgroup_conf_t *slurm_cgroup_conf) { s_p_options_t options[] = { {"CgroupAutomount", S_P_BOOLEAN}, + {"CgroupMountpoint", S_P_STRING}, {"CgroupSubsystems", S_P_STRING}, {"CgroupReleaseAgentDir", S_P_STRING}, {"ConstrainCores", S_P_BOOLEAN}, @@ -137,8 +141,14 @@ extern int read_slurm_cgroup_conf(slurm_cgroup_conf_t *slurm_cgroup_conf) /* cgroup initialisation parameters */ if (!s_p_get_boolean(&slurm_cgroup_conf->cgroup_automount, - "CgroupAutomount", tbl)) + "CgroupAutomount", tbl)) slurm_cgroup_conf->cgroup_automount = false; + + if (!s_p_get_string(&slurm_cgroup_conf->cgroup_mountpoint, + "CgroupMountpoint", tbl)) + slurm_cgroup_conf->cgroup_mountpoint = + xstrdup(DEFAULT_CGROUP_BASEDIR); + s_p_get_string(&slurm_cgroup_conf->cgroup_subsystems, "CgroupSubsystems", tbl); s_p_get_string(&slurm_cgroup_conf->cgroup_release_agent, diff --git a/src/common/xcgroup_read_config.h b/src/common/xcgroup_read_config.h index 7693b0e2f3b..bdbe472133c 100644 --- a/src/common/xcgroup_read_config.h +++ b/src/common/xcgroup_read_config.h @@ -55,6 +55,7 @@ typedef struct slurm_cgroup_conf { bool cgroup_automount; + char * cgroup_mountpoint; char * cgroup_subsystems; char * cgroup_release_agent; diff --git a/src/plugins/proctrack/cgroup/proctrack_cgroup.c b/src/plugins/proctrack/cgroup/proctrack_cgroup.c index b38211be6b2..1265326d287 100644 --- a/src/plugins/proctrack/cgroup/proctrack_cgroup.c +++ b/src/plugins/proctrack/cgroup/proctrack_cgroup.c @@ -129,7 +129,7 @@ int _slurm_cgroup_init(void) } /* initialize freezer cgroup namespace */ - if (xcgroup_ns_create(&freezer_ns, CGROUP_BASEDIR "/freezer", "", + if (xcgroup_ns_create(&slurm_cgroup_conf, &freezer_ns, "/freezer", "", "freezer", release_agent_path) != XCGROUP_SUCCESS) { error("unable to create freezer cgroup namespace"); diff --git a/src/plugins/task/cgroup/task_cgroup_cpuset.c b/src/plugins/task/cgroup/task_cgroup_cpuset.c index 59f46512d39..5fe8fba482d 100644 --- a/src/plugins/task/cgroup/task_cgroup_cpuset.c +++ b/src/plugins/task/cgroup/task_cgroup_cpuset.c @@ -94,7 +94,7 @@ extern int task_cgroup_cpuset_init(slurm_cgroup_conf_t *slurm_cgroup_conf) error("task/cgroup: unable to build cpuset release agent path"); goto error; } - if (xcgroup_ns_create(&cpuset_ns,CGROUP_BASEDIR "/cpuset","", + if (xcgroup_ns_create(slurm_cgroup_conf, &cpuset_ns, "/cpuset", "", "cpuset",release_agent_path) != XCGROUP_SUCCESS) { error("task/cgroup: unable to create cpuset namespace"); diff --git a/src/plugins/task/cgroup/task_cgroup_devices.c b/src/plugins/task/cgroup/task_cgroup_devices.c index 9053bec0e91..da1eb58d3d3 100644 --- a/src/plugins/task/cgroup/task_cgroup_devices.c +++ b/src/plugins/task/cgroup/task_cgroup_devices.c @@ -102,7 +102,7 @@ extern int task_cgroup_devices_init(slurm_cgroup_conf_t *slurm_cgroup_conf) error("task/cgroup: unable to build devices release agent path"); goto error; } - if ( xcgroup_ns_create(&devices_ns,CGROUP_BASEDIR "/devices","", + if (xcgroup_ns_create(slurm_cgroup_conf, &devices_ns, "/devices","", "devices",release_agent_path) != XCGROUP_SUCCESS ) { error("task/cgroup: unable to create devices namespace"); diff --git a/src/plugins/task/cgroup/task_cgroup_memory.c b/src/plugins/task/cgroup/task_cgroup_memory.c index 70de4c76f2d..321495d7c1f 100644 --- a/src/plugins/task/cgroup/task_cgroup_memory.c +++ b/src/plugins/task/cgroup/task_cgroup_memory.c @@ -84,7 +84,7 @@ extern int task_cgroup_memory_init(slurm_cgroup_conf_t *slurm_cgroup_conf) error("task/cgroup: unable to build memory release agent path"); goto error; } - if (xcgroup_ns_create(&memory_ns,CGROUP_BASEDIR "/memory","", + if (xcgroup_ns_create(slurm_cgroup_conf, &memory_ns, "/memory", "", "memory",release_agent_path) != XCGROUP_SUCCESS) { error("task/cgroup: unable to create memory namespace"); -- GitLab