|
@@ -22,31 +22,41 @@ const (
|
|
|
)
|
|
|
|
|
|
// https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt
|
|
|
-func FindCgroupMountpoint(subsystem string) (string, error) {
|
|
|
- mnt, _, err := FindCgroupMountpointAndRoot(subsystem)
|
|
|
+func FindCgroupMountpoint(cgroupPath, subsystem string) (string, error) {
|
|
|
+ mnt, _, err := FindCgroupMountpointAndRoot(cgroupPath, subsystem)
|
|
|
return mnt, err
|
|
|
}
|
|
|
|
|
|
-func FindCgroupMountpointAndRoot(subsystem string) (string, string, error) {
|
|
|
+func FindCgroupMountpointAndRoot(cgroupPath, subsystem string) (string, string, error) {
|
|
|
// We are not using mount.GetMounts() because it's super-inefficient,
|
|
|
// parsing it directly sped up x10 times because of not using Sscanf.
|
|
|
// It was one of two major performance drawbacks in container start.
|
|
|
if !isSubsystemAvailable(subsystem) {
|
|
|
return "", "", NewNotFoundError(subsystem)
|
|
|
}
|
|
|
+
|
|
|
f, err := os.Open("/proc/self/mountinfo")
|
|
|
if err != nil {
|
|
|
return "", "", err
|
|
|
}
|
|
|
defer f.Close()
|
|
|
|
|
|
- scanner := bufio.NewScanner(f)
|
|
|
+ return findCgroupMountpointAndRootFromReader(f, cgroupPath, subsystem)
|
|
|
+}
|
|
|
+
|
|
|
+func findCgroupMountpointAndRootFromReader(reader io.Reader, cgroupPath, subsystem string) (string, string, error) {
|
|
|
+ scanner := bufio.NewScanner(reader)
|
|
|
for scanner.Scan() {
|
|
|
txt := scanner.Text()
|
|
|
- fields := strings.Split(txt, " ")
|
|
|
- for _, opt := range strings.Split(fields[len(fields)-1], ",") {
|
|
|
- if opt == subsystem {
|
|
|
- return fields[4], fields[3], nil
|
|
|
+ fields := strings.Fields(txt)
|
|
|
+ if len(fields) < 5 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if strings.HasPrefix(fields[4], cgroupPath) {
|
|
|
+ for _, opt := range strings.Split(fields[len(fields)-1], ",") {
|
|
|
+ if opt == subsystem {
|
|
|
+ return fields[4], fields[3], nil
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -257,7 +267,7 @@ func GetInitCgroupPath(subsystem string) (string, error) {
|
|
|
}
|
|
|
|
|
|
func getCgroupPathHelper(subsystem, cgroup string) (string, error) {
|
|
|
- mnt, root, err := FindCgroupMountpointAndRoot(subsystem)
|
|
|
+ mnt, root, err := FindCgroupMountpointAndRoot("", subsystem)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|