]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroup: add new functions for interacting with hierachies
authorTycho Andersen <tycho.andersen@canonical.com>
Wed, 14 Sep 2016 14:38:46 +0000 (14:38 +0000)
committerTycho Andersen <tycho.andersen@canonical.com>
Fri, 16 Sep 2016 21:17:03 +0000 (15:17 -0600)
N.B. that these are only implemented in cgfsng, but,

15:28:28    tych0 | do we still use cgfs anywhere? or the cgm backend?
15:29:19 stgraber | not anywhere we care about

...I think that's okay.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.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 2d0de0c11293c0c6ec78ae66ab1008f8a9a69525..80a336db9248c6f9caf67544e4e21441fafc2d85 100644 (file)
@@ -2434,6 +2434,18 @@ out:
        return ret;
 }
 
+static int cgfs_num_hierarchies(void)
+{
+       /* not implemented */
+       return -1;
+}
+
+static bool cgfs_get_hierarchies(int i, char ***out)
+{
+       /* not implemented */
+       return false;
+}
+
 static bool cgfs_unfreeze(void *hdata)
 {
        struct cgfs_data *d = hdata;
@@ -2627,6 +2639,8 @@ static struct cgroup_ops cgfs_ops = {
        .get_cgroup = cgfs_get_cgroup,
        .canonical_path = cgfs_canonical_path,
        .escape = cgfs_escape,
+       .num_hierarchies = cgfs_num_hierarchies,
+       .get_hierarchies = cgfs_get_hierarchies,
        .get = lxc_cgroupfs_get,
        .set = lxc_cgroupfs_set,
        .unfreeze = cgfs_unfreeze,
index 95f29cad11316bc4cef90be712901bf504e67b28..5b615543c403a2877daea95ec4f7af6361f7709e 100644 (file)
@@ -1457,6 +1457,31 @@ out:
        return ret;
 }
 
+static int cgfsng_num_hierarchies(void)
+{
+       int i;
+
+       for (i = 0; hierarchies[i]; i++)
+               ;
+
+       return i;
+}
+
+static bool cgfsng_get_hierarchies(int n, char ***out)
+{
+       int i;
+
+       /* sanity check n */
+       for (i = 0; i < n; i++) {
+               if (!hierarchies[i])
+                       return false;
+       }
+
+       *out = hierarchies[i]->controllers;
+
+       return true;
+}
+
 #define THAWED "THAWED"
 #define THAWED_LEN (strlen(THAWED))
 
@@ -1674,6 +1699,8 @@ static struct cgroup_ops cgfsng_ops = {
        .enter = cgfsng_enter,
        .canonical_path = cgfsng_canonical_path,
        .escape = cgfsng_escape,
+       .num_hierarchies = cgfsng_num_hierarchies,
+       .get_hierarchies = cgfsng_get_hierarchies,
        .get_cgroup = cgfsng_get_cgroup,
        .get = cgfsng_get,
        .set = cgfsng_set,
index 4da891de90784ff8dc444e917081ec0a002bc5a4..f14eb1764b6712d6082ac3b00beff4eb70a4c967 100644 (file)
@@ -337,6 +337,18 @@ static bool cgm_escape(void *hdata)
        return ret;
 }
 
+static int cgm_num_hierarchies(void)
+{
+       /* not implemented */
+       return -1;
+}
+
+static bool cgm_get_hierarchies(int i, char ***out)
+{
+       /* not implemented */
+       return false;
+}
+
 struct chown_data {
        const char *cgroup_path;
        uid_t origuid;
@@ -1657,6 +1669,8 @@ static struct cgroup_ops cgmanager_ops = {
        .get_cgroup = cgm_get_cgroup,
        .canonical_path = cgm_canonical_path,
        .escape = cgm_escape,
+       .num_hierarchies = cgm_num_hierarchies,
+       .get_hierarchies = cgm_get_hierarchies,
        .get = cgm_get,
        .set = cgm_set,
        .unfreeze = cgm_unfreeze,
index 91ef359a57b607cabeabde8e8ed8cd9257aaa5d7..48cd403ba61430b9c5b1699bfa251db4eb04a175 100644 (file)
@@ -132,6 +132,22 @@ const char *cgroup_canonical_path(struct lxc_handler *handler)
        return NULL;
 }
 
+int cgroup_num_hierarchies(void)
+{
+       if (!ops)
+               return -1;
+
+       return ops->num_hierarchies();
+}
+
+bool cgroup_get_hierarchies(int n, char ***out)
+{
+       if (!ops)
+               return false;
+
+       return ops->get_hierarchies(n, out);
+}
+
 bool cgroup_unfreeze(struct lxc_handler *handler)
 {
        if (ops)
index e56a115edd9f154d05080894d4b511118fe4d3f4..f65cbfe49de4f81ff5fe1a168596f28fe778e780 100644 (file)
@@ -49,6 +49,8 @@ struct cgroup_ops {
        const char *(*get_cgroup)(void *hdata, const char *subsystem);
        const char *(*canonical_path)(void *hdata);
        bool (*escape)();
+       int (*num_hierarchies)();
+       bool (*get_hierarchies)(int n, char ***out);
        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);
@@ -74,6 +76,8 @@ 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 bool cgroup_escape();
+extern int cgroup_num_hierarchies();
+extern bool cgroup_get_hierarchies(int i, char ***out);
 
 /*
  * Currently, this call  only makes sense for privileged containers.