]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Added support for named hierarchies to cgconfigparser.
authorJan Safranek <jsafrane@redhat.com>
Wed, 6 Apr 2011 06:37:45 +0000 (08:37 +0200)
committerJan Safranek <jsafrane@redhat.com>
Mon, 18 Apr 2011 12:14:19 +0000 (14:14 +0200)
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 <jsafrane@redhat.com>
src/config.c

index 5c4598c821a10f5cbd87db8b41977c066cb9bdec..f1873eaf8134c477f9193c03321e32b54f5cf2e9 100644 (file)
@@ -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);