From: Tycho Andersen Date: Wed, 14 Sep 2016 14:38:46 +0000 (+0000) Subject: cgroup: add new functions for interacting with hierachies X-Git-Tag: lxc-2.1.0~322^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36662416441b051bf9d3bb0e1b5d08a61b3a6420;p=thirdparty%2Flxc.git cgroup: add new functions for interacting with hierachies 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 --- diff --git a/src/lxc/cgroups/cgfs.c b/src/lxc/cgroups/cgfs.c index 2d0de0c11..80a336db9 100644 --- a/src/lxc/cgroups/cgfs.c +++ b/src/lxc/cgroups/cgfs.c @@ -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, diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 95f29cad1..5b615543c 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -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, diff --git a/src/lxc/cgroups/cgmanager.c b/src/lxc/cgroups/cgmanager.c index 4da891de9..f14eb1764 100644 --- a/src/lxc/cgroups/cgmanager.c +++ b/src/lxc/cgroups/cgmanager.c @@ -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, diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c index 91ef359a5..48cd403ba 100644 --- a/src/lxc/cgroups/cgroup.c +++ b/src/lxc/cgroups/cgroup.c @@ -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) diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index e56a115ed..f65cbfe49 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -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.