MCPcopy Create free account
hub / github.com/apache/mesos / create

Function create

src/linux/cgroups.cpp:714–761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

712
713
714Try<Nothing> create(
715 const string& hierarchy,
716 const string& cgroup,
717 bool recursive)
718{
719 vector<string> missingCgroups;
720 string currentCgroup;
721 Path cgroupPath(cgroup);
722 for (auto it = cgroupPath.begin(); it != cgroupPath.end(); ++it) {
723 currentCgroup = path::join(currentCgroup, *it);
724 if (!missingCgroups.empty() ||
725 !os::exists(path::join(hierarchy, currentCgroup))) {
726 missingCgroups.push_back(currentCgroup);
727 }
728 }
729
730 string path = path::join(hierarchy, cgroup);
731
732 Try<Nothing> mkdir = os::mkdir(path, recursive);
733 if (mkdir.isError()) {
734 return Error(
735 "Failed to create directory '" + path + "': " + mkdir.error());
736 }
737
738 // Now clone 'cpuset.cpus' and 'cpuset.mems' if the 'cpuset'
739 // subsystem is attached to the hierarchy.
740 Try<set<string>> attached = cgroups::subsystems(hierarchy);
741 if (attached.isError()) {
742 return Error(
743 "Failed to determine if hierarchy '" + hierarchy +
744 "' has the 'cpuset' subsystem attached: " + attached.error());
745 } else if (attached->count("cpuset") > 0) {
746 foreach (const string& cgroup, missingCgroups) {
747 string parent = Path(cgroup).dirname();
748
749 Try<Nothing> clone =
750 internal::cloneCpusetCpusMems(hierarchy, parent, cgroup);
751
752 if (clone.isError()) {
753 return Error(
754 "Failed to clone `cpuset.cpus` and `cpuset.mems` from '" +
755 parent + "' to '" + cgroup + "': " + clone.error());
756 }
757 }
758 }
759
760 return Nothing();
761}
762
763
764bool exists(const string& hierarchy, const string& cgroup)

Callers 3

prepareFunction · 0.70
isolateFunction · 0.70
statFunction · 0.70

Calls 12

subsystemsFunction · 0.85
NothingClass · 0.85
existsFunction · 0.70
errorMethod · 0.65
joinFunction · 0.50
mkdirFunction · 0.50
ErrorFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
isErrorMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected