helpers_linux.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cm
  14. import (
  15. "fmt"
  16. libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
  17. )
  18. // GetCgroupSubsystems returns information about the mounted cgroup subsystems
  19. func GetCgroupSubsystems() (*CgroupSubsystems, error) {
  20. // get all cgroup mounts.
  21. allCgroups, err := libcontainercgroups.GetCgroupMounts()
  22. if err != nil {
  23. return &CgroupSubsystems{}, err
  24. }
  25. if len(allCgroups) == 0 {
  26. return &CgroupSubsystems{}, fmt.Errorf("failed to find cgroup mounts")
  27. }
  28. mountPoints := make(map[string]string, len(allCgroups))
  29. for _, mount := range allCgroups {
  30. for _, subsystem := range mount.Subsystems {
  31. mountPoints[subsystem] = mount.Mountpoint
  32. }
  33. }
  34. return &CgroupSubsystems{
  35. Mounts: allCgroups,
  36. MountPoints: mountPoints,
  37. }, nil
  38. }