Fixed the CgroupsIsolator to check for the existence of the nested "test" cgroup.
Sometimes the cgroup tests fail because the "test" cgroup is already there. This ensures that it gets cleaned by the next test. We also check that it exists before we try creating it. If it already exists, we skip the creation. From: Brenden Matthews <bren...@diddyinc.com> Review: https://reviews.apache.org/r/11126 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e0977d7c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e0977d7c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e0977d7c Branch: refs/heads/master Commit: e0977d7c6136d754cd7f8c0a7b893b5515975464 Parents: 44c95b9 Author: Benjamin Mahler <bmah...@twitter.com> Authored: Sat Jul 20 11:57:45 2013 -0700 Committer: Benjamin Mahler <bmah...@twitter.com> Committed: Sat Jul 20 12:37:36 2013 -0700 ---------------------------------------------------------------------- src/slave/cgroups_isolator.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e0977d7c/src/slave/cgroups_isolator.cpp ---------------------------------------------------------------------- diff --git a/src/slave/cgroups_isolator.cpp b/src/slave/cgroups_isolator.cpp index 9d18886..0faf7d5 100644 --- a/src/slave/cgroups_isolator.cpp +++ b/src/slave/cgroups_isolator.cpp @@ -299,16 +299,27 @@ void CgroupsIsolator::initialize( << "Failed to create the '" << flags.cgroups_root << "' cgroup"; } - // Make sure this kernel supports creating nested cgroups. - Try<Nothing> create = - cgroups::create(hierarchy, path::join(flags.cgroups_root, "test")); + // Create the nested test cgroup if it doesn't exist. + exists = cgroups::exists( + hierarchy, path::join(flags.cgroups_root, "test")); + CHECK_SOME(exists) + << "Failed to determine if '"<< flags.cgroups_root << "/test'" + << " nested cgroup already exists in the hierarchy at '" + << hierarchy << "'"; - if (create.isError()) { - EXIT(1) << "Failed to create a nested 'test' cgroup. Your kernel " - << "might be too old to use the cgroups isolator: " - << create.error(); + if (!exists.get()) { + // Make sure this kernel supports creating nested cgroups. + Try<Nothing> create = + cgroups::create(hierarchy, path::join(flags.cgroups_root, "test")); + + if (create.isError()) { + EXIT(1) << "Failed to create a nested 'test' cgroup. Your kernel " + << "might be too old to use the cgroups isolator: " + << create.error(); + } } + // Remove the nested 'test' cgroup. Try<Nothing> remove = cgroups::remove(hierarchy, path::join(flags.cgroups_root, "test"));