diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-11 17:46:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 17:46:37 -0500 |
commit | 1b284a298c0bde20561321f325d4a7ad00e7bd25 (patch) | |
tree | 426d8db849f1f1f93435b4fe969cc18a4a3c88a6 /utils | |
parent | b38b1433b3ecd9a4f1aa3ce816a76886432d8ec0 (diff) | |
parent | 660a06f2f79fc1edf68e286ee452ceb9dcd5e03a (diff) | |
download | podman-1b284a298c0bde20561321f325d4a7ad00e7bd25.tar.gz podman-1b284a298c0bde20561321f325d4a7ad00e7bd25.tar.bz2 podman-1b284a298c0bde20561321f325d4a7ad00e7bd25.zip |
Merge pull request #9302 from giuseppe/cgroup-split-v1
utils: takes the longest path on cgroup v1
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils_supported.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/utils/utils_supported.go b/utils/utils_supported.go index 6f517dc72..73313cf5e 100644 --- a/utils/utils_supported.go +++ b/utils/utils_supported.go @@ -81,16 +81,9 @@ func getCgroupProcess(procFile string) (string, error) { cgroup = line[3:] break } - // root cgroup, skip it - if parts[2] == "/" { - continue - } - // The process must have the same cgroup path for all controllers - // The OCI runtime spec file allow us to specify only one path. - if cgroup != "/" && cgroup != parts[2] { - return "", errors.Errorf("cgroup configuration not supported, the process is in two different cgroups") + if len(parts[2]) > len(cgroup) { + cgroup = parts[2] } - cgroup = parts[2] } if cgroup == "/" { return "", errors.Errorf("could not find cgroup mount in %q", procFile) @@ -150,6 +143,11 @@ func moveUnderCgroup(cgroup, subtree string, processes []uint32) error { // If it is not using unified mode, the cgroup v2 hierarchy is // usually mounted under /sys/fs/cgroup/unified cgroupRoot = filepath.Join(cgroupRoot, "unified") + + // Ignore the unified mount if it doesn't exist + if _, err := os.Stat(cgroupRoot); err != nil && os.IsNotExist(err) { + continue + } } else if parts[1] != "" { // Assume the controller is mounted at /sys/fs/cgroup/$CONTROLLER. controller := strings.TrimPrefix(parts[1], "name=") @@ -161,7 +159,7 @@ func moveUnderCgroup(cgroup, subtree string, processes []uint32) error { parentCgroup = parts[2] } newCgroup := filepath.Join(cgroupRoot, parentCgroup, subtree) - if err := os.Mkdir(newCgroup, 0755); err != nil && !os.IsExist(err) { + if err := os.MkdirAll(newCgroup, 0755); err != nil && !os.IsExist(err) { return err } @@ -183,6 +181,9 @@ func moveUnderCgroup(cgroup, subtree string, processes []uint32) error { return err } for _, pid := range bytes.Split(processesData, []byte("\n")) { + if len(pid) == 0 { + continue + } if _, err := f.Write(pid); err != nil { logrus.Warnf("Cannot move process %s to cgroup %q", string(pid), newCgroup) } |