]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: handle limits on the unified hierarchy
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 31 Jan 2018 15:45:04 +0000 (16:45 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 7 Feb 2018 11:03:42 +0000 (12:03 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfs.c
src/lxc/cgroups/cgfsng.c
src/lxc/cgroups/cgmanager.c
src/lxc/cgroups/cgroup.c
src/lxc/cgroups/cgroup.h

index fc25bc9b59a87231d31250c8b3d22cfc2633edee..89aec91f748e5a3839d531c1b4b297463a451931 100644 (file)
@@ -2525,14 +2525,14 @@ static bool cgfs_unfreeze(void *hdata)
        return ret == 0;
 }
 
-static bool cgroupfs_setup_limits(void *hdata, struct lxc_list *cgroup_conf,
+static bool cgroupfs_setup_limits(void *hdata, struct lxc_conf *conf,
                                  bool with_devices)
 {
        struct cgfs_data *d = hdata;
 
        if (!d)
                return false;
-       return do_setup_cgroup_limits(d, cgroup_conf, with_devices) == 0;
+       return do_setup_cgroup_limits(d, &conf->cgroup, with_devices) == 0;
 }
 
 static bool lxc_cgroupfs_attach(const char *name, const char *lxcpath, pid_t pid)
index fe3e26ec1b34807ddbd61e559f6a8a287d0364ad..37204c81f0cba5b2927c84467b0102680bb69e23 100644 (file)
@@ -2140,6 +2140,7 @@ static bool cgfsng_escape()
        return true;
 }
 
+/* TODO: handle the unified cgroup hierarchy */
 static int cgfsng_num_hierarchies(void)
 {
        int i;
@@ -2150,15 +2151,15 @@ static int cgfsng_num_hierarchies(void)
        return i;
 }
 
+/* TODO: handle the unified cgroup hierarchy */
 static bool cgfsng_get_hierarchies(int n, char ***out)
 {
        int i;
 
        /* sanity check n */
-       for (i = 0; i < n; i++) {
+       for (i = 0; i < n; i++)
                if (!hierarchies[i])
                        return false;
-       }
 
        *out = hierarchies[i]->controllers;
 
@@ -2520,8 +2521,9 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c
        return ret;
 }
 
-static bool cgfsng_setup_limits(void *hdata, struct lxc_list *cgroup_settings,
-                                 bool do_devices)
+static bool __cgfsng_setup_limits_legacy(void *hdata,
+                                        struct lxc_list *cgroup_settings,
+                                        bool do_devices)
 {
        struct cgfsng_handler_data *d = hdata;
        struct lxc_list *iterator, *sorted_cgroup_settings, *next;
@@ -2532,9 +2534,8 @@ static bool cgfsng_setup_limits(void *hdata, struct lxc_list *cgroup_settings,
                return true;
 
        sorted_cgroup_settings = sort_cgroup_settings(cgroup_settings);
-       if (!sorted_cgroup_settings) {
+       if (!sorted_cgroup_settings)
                return false;
-       }
 
        lxc_list_for_each(iterator, sorted_cgroup_settings) {
                cg = iterator->elem;
@@ -2555,7 +2556,7 @@ static bool cgfsng_setup_limits(void *hdata, struct lxc_list *cgroup_settings,
        }
 
        ret = true;
-       INFO("cgroup has been setup");
+       INFO("Limits for the legacy cgroup hierarchies have been setup");
 out:
        lxc_list_for_each_safe(iterator, sorted_cgroup_settings, next) {
                lxc_list_del(iterator);
@@ -2565,6 +2566,25 @@ out:
        return ret;
 }
 
+static bool __cgfsng_setup_limits_unified(void *hdata,
+                                         struct lxc_list *cgroup_settings)
+{
+       INFO("Setting limits on the unified cgroup hierarchy is not supported");
+       return true;
+}
+
+static bool cgfsng_setup_limits(void *hdata, struct lxc_conf *conf,
+                               bool do_devices)
+{
+       bool bret;
+
+       bret = __cgfsng_setup_limits_legacy(hdata, &conf->cgroup, do_devices);
+       if (!bret)
+               return false;
+
+       return __cgfsng_setup_limits_unified(NULL, NULL);
+}
+
 static struct cgroup_ops cgfsng_ops = {
        .init = cgfsng_init,
        .destroy = cgfsng_destroy,
index dccc04c3ccbe36b0583e18d3aafa6c4431b41daf..c23443c9fdecacaf31e112a03569afcc65f23064 100644 (file)
@@ -1479,11 +1479,12 @@ static bool cgm_unfreeze(void *hdata)
        return ret;
 }
 
-static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool do_devices)
+static bool cgm_setup_limits(void *hdata, struct lxc_conf *conf, bool do_devices)
 {
        struct cgm_data *d = hdata;
        struct lxc_list *iterator, *sorted_cgroup_settings, *next;
        struct lxc_cgroup *cg;
+       struct lxc_list *cgroup_settings = &conf->cgroup;
        bool ret = false;
 
        if (lxc_list_empty(cgroup_settings))
index 36a665b1c2cc8eedad7dfe3afcd7663826071e52..1f78a6317e09a229aebf52afd9bf306208c3c084 100644 (file)
@@ -150,7 +150,7 @@ bool cgroup_setup_limits(struct lxc_handler *handler, bool with_devices)
 {
        if (ops)
                return ops->setup_limits(handler->cgroup_data,
-                                        &handler->conf->cgroup, with_devices);
+                                        handler->conf, with_devices);
 
        return false;
 }
index f409eee7c050c072398f778f4113d0feacae7234..d288b4c728aaa1ad4db2a8e56da9d480ed506379 100644 (file)
@@ -60,7 +60,7 @@ struct cgroup_ops {
        int (*set)(const char *filename, const char *value, const char *name, const char *lxcpath);
        int (*get)(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
        bool (*unfreeze)(void *hdata);
-       bool (*setup_limits)(void *hdata, struct lxc_list *cgroup_conf, bool with_devices);
+       bool (*setup_limits)(void *hdata, struct lxc_conf *conf, bool with_devices);
        bool (*chown)(void *hdata, struct lxc_conf *conf);
        bool (*attach)(const char *name, const char *lxcpath, pid_t pid);
        bool (*mount_cgroup)(void *hdata, const char *root, int type);
@@ -80,7 +80,8 @@ extern bool cgroup_enter(struct lxc_handler *handler);
 extern void cgroup_cleanup(struct lxc_handler *handler);
 extern bool cgroup_create_legacy(struct lxc_handler *handler);
 extern int cgroup_nrtasks(struct lxc_handler *handler);
-extern const char *cgroup_get_cgroup(struct lxc_handler *handler, const char *subsystem);
+extern const char *cgroup_get_cgroup(struct lxc_handler *handler,
+                                    const char *subsystem);
 extern bool cgroup_escape();
 extern int cgroup_num_hierarchies();
 extern bool cgroup_get_hierarchies(int i, char ***out);