Commit 36662416 by Tycho Andersen

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: 's avatarTycho Andersen <tycho.andersen@canonical.com>
parent 5f178bc9
...@@ -2434,6 +2434,18 @@ out: ...@@ -2434,6 +2434,18 @@ out:
return ret; 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) static bool cgfs_unfreeze(void *hdata)
{ {
struct cgfs_data *d = hdata; struct cgfs_data *d = hdata;
...@@ -2627,6 +2639,8 @@ static struct cgroup_ops cgfs_ops = { ...@@ -2627,6 +2639,8 @@ static struct cgroup_ops cgfs_ops = {
.get_cgroup = cgfs_get_cgroup, .get_cgroup = cgfs_get_cgroup,
.canonical_path = cgfs_canonical_path, .canonical_path = cgfs_canonical_path,
.escape = cgfs_escape, .escape = cgfs_escape,
.num_hierarchies = cgfs_num_hierarchies,
.get_hierarchies = cgfs_get_hierarchies,
.get = lxc_cgroupfs_get, .get = lxc_cgroupfs_get,
.set = lxc_cgroupfs_set, .set = lxc_cgroupfs_set,
.unfreeze = cgfs_unfreeze, .unfreeze = cgfs_unfreeze,
......
...@@ -1457,6 +1457,31 @@ out: ...@@ -1457,6 +1457,31 @@ out:
return ret; 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 "THAWED"
#define THAWED_LEN (strlen(THAWED)) #define THAWED_LEN (strlen(THAWED))
...@@ -1674,6 +1699,8 @@ static struct cgroup_ops cgfsng_ops = { ...@@ -1674,6 +1699,8 @@ static struct cgroup_ops cgfsng_ops = {
.enter = cgfsng_enter, .enter = cgfsng_enter,
.canonical_path = cgfsng_canonical_path, .canonical_path = cgfsng_canonical_path,
.escape = cgfsng_escape, .escape = cgfsng_escape,
.num_hierarchies = cgfsng_num_hierarchies,
.get_hierarchies = cgfsng_get_hierarchies,
.get_cgroup = cgfsng_get_cgroup, .get_cgroup = cgfsng_get_cgroup,
.get = cgfsng_get, .get = cgfsng_get,
.set = cgfsng_set, .set = cgfsng_set,
......
...@@ -337,6 +337,18 @@ static bool cgm_escape(void *hdata) ...@@ -337,6 +337,18 @@ static bool cgm_escape(void *hdata)
return ret; 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 { struct chown_data {
const char *cgroup_path; const char *cgroup_path;
uid_t origuid; uid_t origuid;
...@@ -1657,6 +1669,8 @@ static struct cgroup_ops cgmanager_ops = { ...@@ -1657,6 +1669,8 @@ static struct cgroup_ops cgmanager_ops = {
.get_cgroup = cgm_get_cgroup, .get_cgroup = cgm_get_cgroup,
.canonical_path = cgm_canonical_path, .canonical_path = cgm_canonical_path,
.escape = cgm_escape, .escape = cgm_escape,
.num_hierarchies = cgm_num_hierarchies,
.get_hierarchies = cgm_get_hierarchies,
.get = cgm_get, .get = cgm_get,
.set = cgm_set, .set = cgm_set,
.unfreeze = cgm_unfreeze, .unfreeze = cgm_unfreeze,
......
...@@ -132,6 +132,22 @@ const char *cgroup_canonical_path(struct lxc_handler *handler) ...@@ -132,6 +132,22 @@ const char *cgroup_canonical_path(struct lxc_handler *handler)
return NULL; 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) bool cgroup_unfreeze(struct lxc_handler *handler)
{ {
if (ops) if (ops)
......
...@@ -49,6 +49,8 @@ struct cgroup_ops { ...@@ -49,6 +49,8 @@ struct cgroup_ops {
const char *(*get_cgroup)(void *hdata, const char *subsystem); const char *(*get_cgroup)(void *hdata, const char *subsystem);
const char *(*canonical_path)(void *hdata); const char *(*canonical_path)(void *hdata);
bool (*escape)(); 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 (*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); int (*get)(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
bool (*unfreeze)(void *hdata); bool (*unfreeze)(void *hdata);
...@@ -74,6 +76,8 @@ extern bool cgroup_create_legacy(struct lxc_handler *handler); ...@@ -74,6 +76,8 @@ extern bool cgroup_create_legacy(struct lxc_handler *handler);
extern int cgroup_nrtasks(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 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. * Currently, this call only makes sense for privileged containers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment