Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
always allow comounted controllers to be passed in together
Browse files Browse the repository at this point in the history
Methods which do not accept multiple cgroup hierarchies, like getvalue,
were insisting on getting only a single controller name.  However if
controllers are co-mounted, then 'cgm listcontrollers' will return
comma-separate lists of co-mounted controllers.  Accept those as
input - so long as they in fact represent a single hierarchy.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
hallyn committed Apr 2, 2015
1 parent 8dbb501 commit a368d8b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
44 changes: 43 additions & 1 deletion cgmanager.c
Expand Up @@ -32,11 +32,17 @@
static int maxdepth = 16;

/* GetPidCgroup */
int get_pid_cgroup_main(void *parent, const char *controller,struct ucred p,
int get_pid_cgroup_main(void *parent, const char *controller, struct ucred p,
struct ucred r, struct ucred v, char **output)
{
char rcgpath[MAXPATHLEN], vcgpath[MAXPATHLEN];

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

// Get r's current cgroup in rcgpath
if (!compute_proxy_cgroup(r.pid, controller, "", rcgpath, NULL)) {
nih_error("%s: Could not determine the requestor's cgroup for %s",
Expand Down Expand Up @@ -72,6 +78,12 @@ int get_pid_cgroup_abs_main(void *parent, const char *controller,struct ucred p,
{
char rcgpath[MAXPATHLEN], vcgpath[MAXPATHLEN];

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

// Get p's current cgroup in rcgpath
if (!compute_proxy_cgroup(p.pid, controller, "", rcgpath, NULL)) {
nih_error("%s: Could not determine the requestor's cgroup for %s",
Expand Down Expand Up @@ -559,6 +571,12 @@ int get_value_main(void *parent, const char *controller, const char *cgroup,
{
char path[MAXPATHLEN];

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

if (!sane_cgroup(cgroup)) {
nih_error("%s: unsafe cgroup", __func__);
return -1;
Expand Down Expand Up @@ -615,6 +633,12 @@ int set_value_main(const char *controller, const char *cgroup,
{
char path[MAXPATHLEN];

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

if (!sane_cgroup(cgroup)) {
nih_error("%s: unsafe cgroup", __func__);
return -1;
Expand Down Expand Up @@ -843,6 +867,12 @@ int get_tasks_main(void *parent, const char *controller, const char *cgroup,
return -1;
}

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

if (!compute_proxy_cgroup(r.pid, controller, cgroup, path, NULL)) {
nih_error("%s: Could not determine the requested cgroup (%s:%s)",
__func__, controller, cgroup);
Expand Down Expand Up @@ -1016,6 +1046,12 @@ int list_children_main(void *parent, const char *controller, const char *cgroup,
return -1;
}

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

if (!compute_proxy_cgroup(r.pid, controller, cgroup, path, NULL)) {
nih_error("%s: Could not determine the requested cgroup (%s:%s)",
__func__, controller, cgroup);
Expand Down Expand Up @@ -1272,6 +1308,12 @@ int list_keys_main(void *parent, const char *controller, const char *cgroup,
return -1;
}

if (!(prune_verify_comounts(controller))) {
nih_error("%s: Multiple controllers given: %s",
__func__, controller);
return -1;
}

if (!compute_proxy_cgroup(r.pid, controller, cgroup, path, NULL)) {
nih_error("%s: Could not determine the requested cgroup (%s:%s)",
__func__, controller, cgroup);
Expand Down
20 changes: 20 additions & 0 deletions fs.c
Expand Up @@ -749,6 +749,26 @@ void do_prune_comounts(char *controllers)
}
}

/*
* If we are passed 'cpu', do nothing and return true.
* If we are passed 'cpu,cpuacct,devices', and all three are comounted,
* set controllers to 'cpu' and return true.
* If we are passed 'cpu,cpuacct,devices', and all three are not comounted,
* return false.
*/
bool prune_verify_comounts(char *controllers)
{
char *comma;
do_prune_comounts(controllers);
comma = strchr(controllers, ',');
if (!comma)
return true;
if (*(comma+1) != '\0')
return false;
*comma = '\0';
return true;
}

/*
* @list is a comma-separated list of words.
* Return true if @word is in @list.
Expand Down
1 change: 1 addition & 0 deletions fs.h
Expand Up @@ -57,6 +57,7 @@ bool setup_base_run_path(void);
bool create_agent_symlinks(void);
bool was_premounted(const char *controller);
void do_prune_comounts(char *controllers);
bool prune_verify_comounts(char *controllers);
void do_list_controllers(void *parent, char ***output);
void convert_directory_contents(struct keys_return_type **keys, struct ucred r);
bool path_is_under_taskcg(pid_t pid, const char *contr,const char *path);

0 comments on commit a368d8b

Please sign in to comment.