func setupCGroups(partitions map[string]int64) error { subsystems, err := cgroups.GetAllSubsystems() if err != nil { return fmt.Errorf("error getting cgroup subsystems: %s", err) } else if len(subsystems) == 0 { return fmt.Errorf("failed to detect any cgroup subsystems") } for _, subsystem := range subsystems { if _, err := cgroups.FindCgroupMountpoint(subsystem); err == nil { // subsystem already mounted continue } path := filepath.Join(cgroupRoot, subsystem) if err := os.Mkdir(path, 0755); err != nil && !os.IsExist(err) { return fmt.Errorf("error creating %s cgroup directory: %s", subsystem, err) } if err := syscall.Mount("cgroup", path, "cgroup", 0, subsystem); err != nil { return fmt.Errorf("error mounting %s cgroup: %s", subsystem, err) } } for name, shares := range partitions { if err := createCGroupPartition(name, shares); err != nil { return err } } return nil }
// Return an map of susbystem -> absolute container cgroup path func cgroupPaths(containerID string) (map[string]string, error) { subsystems, err := cgroups.GetAllSubsystems() if err != nil { return nil, err } logrus.Debugf("subsystems: %s", subsystems) paths := make(map[string]string) for _, subsystem := range subsystems { cgroupRoot, cgroupDir, err := findCgroupRootAndDir(subsystem) logrus.Debugf("cgroup path %s %s", cgroupRoot, cgroupDir) if err != nil { //unsupported subystem continue } // if we are running dind dockerPathIdx := strings.LastIndex(cgroupDir, "docker") if dockerPathIdx != -1 { cgroupDir = cgroupDir[:dockerPathIdx-1] } path := filepath.Join(cgroupRoot, cgroupDir, "lxc", containerID) paths[subsystem] = path } return paths, nil }
// Return an map of susbystem -> absolute container cgroup path func cgroupPaths(containerID string) (map[string]string, error) { subsystems, err := cgroups.GetAllSubsystems() if err != nil { return nil, err } logrus.Debugf("subsystems: %s", subsystems) paths := make(map[string]string) for _, subsystem := range subsystems { cgroupRoot, cgroupDir, err := findCgroupRootAndDir(subsystem) logrus.Debugf("cgroup path %s %s", cgroupRoot, cgroupDir) if err != nil { //unsupported subystem continue } path := filepath.Join(cgroupRoot, cgroupDir, "lxc", containerID) paths[subsystem] = path } return paths, nil }