From: Jan Safranek Date: Wed, 6 Apr 2011 06:37:45 +0000 (+0200) Subject: Added support for named hierarchies to cgconfigparser. X-Git-Tag: v0.38~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=701d76513412a4d8ae9d98cc9e7017fe4b9cc5d2;p=thirdparty%2Flibcgroup.git Added support for named hierarchies to cgconfigparser. Add the missing parts to make cgconfigparser able to mount named hierarchies. It must add 'none' option to mount opts for mount without real controller and with 'name=xxx' only, the rest (surprisingly) works out of the box, only quoting needs special care. Following cgconfig.conf is usable with the patch: mount { "name=test" = /cgroup/test; "name=testwithcpu" = /cgroup/cpu; cpu = /cgroup/cpu; } group foo { "name=test" { } "name=testwithcpu" { } cpu { cpu.shares = 1024; } } Signed-off-by: Jan Safranek --- diff --git a/src/config.c b/src/config.c index 5c4598c8..f1873eaf 100644 --- a/src/config.c +++ b/src/config.c @@ -390,6 +390,39 @@ void cgroup_config_cleanup_namespace_table(void) sizeof(struct cg_mount_table_s) * CG_CONTROLLER_MAX); } +/** + * Add necessary options for mount. Currently only 'none' option is added + * for mounts with only 'name=xxx' and without real controller. + */ +static int cgroup_config_ajdust_mount_options(struct cg_mount_table_s *mount) +{ + char *save = NULL; + char *opts = strdup(mount->name); + char *token; + int name_only = 1; + + if (opts == NULL) + return ECGFAIL; + + token = strtok_r(opts, ",", &save); + while (token != NULL) { + if (strncmp(token, "name=", 5) != 0) { + name_only = 0; + break; + } + token = strtok_r(NULL, ",", &save); + } + + free(opts); + if (name_only) { + strncat(mount->name, ",", FILENAME_MAX - strlen(mount->name)-1); + strncat(mount->name, "none", + FILENAME_MAX - strlen(mount->name) - 1); + } + + return 0; +} + /* * Start mounting the mount table. */ @@ -419,6 +452,10 @@ static int cgroup_config_mount_fs(void) return ECGOTHER; } + ret = cgroup_config_ajdust_mount_options(curr); + if (ret) + return ret; + ret = mount(CGROUP_FILESYSTEM, curr->mount.path, CGROUP_FILESYSTEM, 0, curr->name);