cgfsng: cg_legacy_handle_cpuset_hierarchy()

parent b095a8eb
...@@ -687,15 +687,16 @@ on_error: ...@@ -687,15 +687,16 @@ on_error:
return false; return false;
} }
/* /* Initialize the cpuset hierarchy in first directory of @gname and set
* Initialize the cpuset hierarchy in first directory of @gname and * cgroup.clone_children so that children inherit settings. Since the
* set cgroup.clone_children so that children inherit settings. * h->base_path is populated by init or ourselves, we know it is already
* Since the h->base_path is populated by init or ourselves, we know * initialized.
* it is already initialized.
*/ */
static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
{ {
char *cgpath, *clonechildrenpath, v, *slash; int ret;
char v;
char *cgpath, *clonechildrenpath, *slash;
if (!string_in_list(h->controllers, "cpuset")) if (!string_in_list(h->controllers, "cpuset"))
return true; return true;
...@@ -709,21 +710,28 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) ...@@ -709,21 +710,28 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
cgpath = must_make_path(h->mountpoint, h->base_cgroup, cgname, NULL); cgpath = must_make_path(h->mountpoint, h->base_cgroup, cgname, NULL);
if (slash) if (slash)
*slash = '/'; *slash = '/';
if (mkdir(cgpath, 0755) < 0 && errno != EEXIST) {
SYSERROR("Failed to create '%s'", cgpath); ret = mkdir(cgpath, 0755);
free(cgpath); if (ret < 0) {
return false; if (errno != EEXIST) {
SYSERROR("Failed to create directory \"%s\"", cgpath);
free(cgpath);
return false;
}
} }
clonechildrenpath = must_make_path(cgpath, "cgroup.clone_children", NULL); clonechildrenpath =
must_make_path(cgpath, "cgroup.clone_children", NULL);
/* unified hierarchy doesn't have clone_children */ /* unified hierarchy doesn't have clone_children */
if (!file_exists(clonechildrenpath)) { if (!file_exists(clonechildrenpath)) {
free(clonechildrenpath); free(clonechildrenpath);
free(cgpath); free(cgpath);
return true; return true;
} }
if (lxc_read_from_file(clonechildrenpath, &v, 1) < 0) {
SYSERROR("Failed to read '%s'", clonechildrenpath); ret = lxc_read_from_file(clonechildrenpath, &v, 1);
if (ret < 0) {
SYSERROR("Failed to read file \"%s\"", clonechildrenpath);
free(clonechildrenpath); free(clonechildrenpath);
free(cgpath); free(cgpath);
return false; return false;
...@@ -731,14 +739,15 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) ...@@ -731,14 +739,15 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
/* Make sure any isolated cpus are removed from cpuset.cpus. */ /* Make sure any isolated cpus are removed from cpuset.cpus. */
if (!cg_legacy_filter_and_set_cpus(cgpath, v == '1')) { if (!cg_legacy_filter_and_set_cpus(cgpath, v == '1')) {
SYSERROR("Failed to remove isolated cpus."); SYSERROR("Failed to remove isolated cpus");
free(clonechildrenpath); free(clonechildrenpath);
free(cgpath); free(cgpath);
return false; return false;
} }
if (v == '1') { /* already set for us by someone else */ /* Already set for us by someone else. */
DEBUG("\"cgroup.clone_children\" was already set to \"1\"."); if (v == '1') {
DEBUG("\"cgroup.clone_children\" was already set to \"1\"");
free(clonechildrenpath); free(clonechildrenpath);
free(cgpath); free(cgpath);
return true; return true;
...@@ -746,16 +755,17 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) ...@@ -746,16 +755,17 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
/* copy parent's settings */ /* copy parent's settings */
if (!copy_parent_file(cgpath, "cpuset.mems")) { if (!copy_parent_file(cgpath, "cpuset.mems")) {
SYSERROR("Failed to copy \"cpuset.mems\" settings."); SYSERROR("Failed to copy \"cpuset.mems\" settings");
free(cgpath); free(cgpath);
free(clonechildrenpath); free(clonechildrenpath);
return false; return false;
} }
free(cgpath); free(cgpath);
if (lxc_write_to_file(clonechildrenpath, "1", 1, false) < 0) { ret = lxc_write_to_file(clonechildrenpath, "1", 1, false);
if (ret < 0) {
/* Set clone_children so children inherit our settings */ /* Set clone_children so children inherit our settings */
SYSERROR("Failed to write 1 to %s", clonechildrenpath); SYSERROR("Failed to write 1 to \"%s\"", clonechildrenpath);
free(clonechildrenpath); free(clonechildrenpath);
return false; return false;
} }
......
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