Skip to content

Commit

Permalink
Use 'cgm listcontrollers' list rather than /proc/self/cgroups
Browse files Browse the repository at this point in the history
to populate the list of subsystems to use.

Cgmanager can be started with some subsystems disabled (i.e.
cgmanager -M cpuset).  If lxc using cgmanager then uses the
/proc/self/cgroup output to determine which controllers to use,
it will fail when trying to do things to cpuset.  Instead, ask
cgmanager which controllers to use.

This still defers (per patch 1/1) to the lxc.cgroup.use values.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
hallyn authored and stgraber committed Aug 14, 2015
1 parent afdd5d4 commit 867c246
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/lxc/cgmanager.c
Expand Up @@ -810,6 +810,25 @@ static int cgm_get_nrtasks(void *hdata)
return pids_len;
}

static bool lxc_list_controllers(char ***list)
{
if (!cgm_dbus_connect()) {
ERROR("Error connecting to cgroup manager");
return false;
}
if (cgmanager_list_controllers_sync(NULL, cgroup_manager, list) != 0) {
NihError *nerr;
nerr = nih_error_get();
ERROR("call to cgmanager_list_controllers_sync failed: %s", nerr->message);
nih_free(nerr);
cgm_dbus_disconnect();
return false;
}

cgm_dbus_disconnect();
return true;
}

static inline void free_abs_cgroup(char *cgroup)
{
if (!cgroup)
Expand Down Expand Up @@ -1158,8 +1177,9 @@ static bool verify_and_prune(const char *cgroup_use)
static bool collect_subsytems(void)
{
char *line = NULL;
nih_local char **cgm_subsys_list = NULL;
size_t sz = 0;
FILE *f;
FILE *f = NULL;

if (subsystems) // already initialized
return true;
Expand All @@ -1170,6 +1190,20 @@ static bool collect_subsytems(void)
subsystems_inone[0] = "all";
subsystems_inone[1] = NULL;

if (lxc_list_controllers(&cgm_subsys_list)) {
while (cgm_subsys_list[nr_subsystems]) {
char **tmp = NIH_MUST( realloc(subsystems,
(nr_subsystems+2)*sizeof(char *)) );
tmp[nr_subsystems] = NIH_MUST(
strdup(cgm_subsys_list[nr_subsystems++]) );
subsystems = tmp;
}
if (nr_subsystems)
subsystems[nr_subsystems] = NULL;
goto collected;
}

INFO("cgmanager_list_controllers failed, falling back to /proc/self/cgroups");
f = fopen_cloexec("/proc/self/cgroup", "r");
if (!f) {
f = fopen_cloexec("/proc/1/cgroup", "r");
Expand Down Expand Up @@ -1211,6 +1245,8 @@ static bool collect_subsytems(void)
fclose(f);

free(line);

collected:
if (!nr_subsystems) {
ERROR("No cgroup subsystems found");
return false;
Expand All @@ -1232,7 +1268,8 @@ static bool collect_subsytems(void)

out_free:
free(line);
fclose(f);
if (f)
fclose(f);
free_subsystems();
return false;
}
Expand Down

0 comments on commit 867c246

Please sign in to comment.