func (daemon *Daemon) initCgroupsPath(path string) error { if path == "/" || path == "." { return nil } daemon.initCgroupsPath(filepath.Dir(path)) _, root, err := cgroups.FindCgroupMountpointAndRoot("cpu") if err != nil { return err } path = filepath.Join(root, path) sysinfo := sysinfo.New(false) if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) { return err } if sysinfo.CPURealtimePeriod && daemon.configStore.CPURealtimePeriod != 0 { if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_period_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimePeriod, 10)), 0700); err != nil { return err } } if sysinfo.CPURealtimeRuntime && daemon.configStore.CPURealtimeRuntime != 0 { if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_runtime_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimeRuntime, 10)), 0700); err != nil { return err } } return nil }
func (raw *data) path(subsystem string) (string, error) { mnt, root, err := cgroups.FindCgroupMountpointAndRoot(subsystem) // If we didn't mount the subsystem, there is no point we make the path. if err != nil { return "", err } // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(raw.cgroup) { return filepath.Join(raw.root, filepath.Base(mnt), raw.cgroup), nil } parent, err := raw.parent(subsystem, mnt, root) if err != nil { return "", err } return filepath.Join(parent, raw.cgroup), nil }
func (raw *cgroupData) path(subsystem string) (string, error) { mnt, root, err := cgroups.FindCgroupMountpointAndRoot(subsystem) // If we didn't mount the subsystem, there is no point we make the path. if err != nil { return "", err } // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(raw.innerPath) { // Sometimes subsystems can be mounted togethger as 'cpu,cpuacct'. return filepath.Join(raw.root, filepath.Base(mnt), raw.innerPath), nil } parentPath, err := raw.parentPath(subsystem, mnt, root) if err != nil { return "", err } return filepath.Join(parentPath, raw.innerPath), nil }
// getCgroupPath gets the file path to the "devices" subsystem of the desired cgroup. // cgroupPath is the path in the cgroup hierarchy. func getCgroupPath(cgroupPath string) (string, error) { cgroupPath = libcontainerutils.CleanPath(cgroupPath) mnt, root, err := libcontainercgroups.FindCgroupMountpointAndRoot("devices") // If we didn't mount the subsystem, there is no point we make the path. if err != nil { return "", err } // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(cgroupPath) { // Sometimes subsystems can be mounted togethger as 'cpu,cpuacct'. return filepath.Join(root, mnt, cgroupPath), nil } parentPath, err := getCgroupParentPath(mnt, root) if err != nil { return "", err } return filepath.Join(parentPath, cgroupPath), nil }
func (daemon *Daemon) initCgroupsPath(path string) error { if path == "/" || path == "." { return nil } if daemon.configStore.CPURealtimePeriod == 0 && daemon.configStore.CPURealtimeRuntime == 0 { return nil } // Recursively create cgroup to ensure that the system and all parent cgroups have values set // for the period and runtime as this limits what the children can be set to. daemon.initCgroupsPath(filepath.Dir(path)) _, root, err := cgroups.FindCgroupMountpointAndRoot("cpu") if err != nil { return err } path = filepath.Join(root, path) sysinfo := sysinfo.New(true) if sysinfo.CPURealtimePeriod && daemon.configStore.CPURealtimePeriod != 0 { if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) { return err } if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_period_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimePeriod, 10)), 0700); err != nil { return err } } if sysinfo.CPURealtimeRuntime && daemon.configStore.CPURealtimeRuntime != 0 { if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) { return err } if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_runtime_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimeRuntime, 10)), 0700); err != nil { return err } } return nil }