| 712 | |
| 713 | |
| 714 | Try<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 | |
| 764 | bool exists(const string& hierarchy, const string& cgroup) |