cgroups.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // +build linux
  2. package cgroups
  3. import (
  4. "fmt"
  5. "github.com/opencontainers/runc/libcontainer/configs"
  6. )
  7. type Manager interface {
  8. // Applies cgroup configuration to the process with the specified pid
  9. Apply(pid int) error
  10. // Returns the PIDs inside the cgroup set
  11. GetPids() ([]int, error)
  12. // Returns the PIDs inside the cgroup set & all sub-cgroups
  13. GetAllPids() ([]int, error)
  14. // Returns statistics for the cgroup set
  15. GetStats() (*Stats, error)
  16. // Toggles the freezer cgroup according with specified state
  17. Freeze(state configs.FreezerState) error
  18. // Destroys the cgroup set
  19. Destroy() error
  20. // The option func SystemdCgroups() and Cgroupfs() require following attributes:
  21. // Paths map[string]string
  22. // Cgroups *configs.Cgroup
  23. // Paths maps cgroup subsystem to path at which it is mounted.
  24. // Cgroups specifies specific cgroup settings for the various subsystems
  25. // Returns cgroup paths to save in a state file and to be able to
  26. // restore the object later.
  27. GetPaths() map[string]string
  28. // GetUnifiedPath returns the unified path when running in unified mode.
  29. // The value corresponds to the all values of GetPaths() map.
  30. //
  31. // GetUnifiedPath returns error when running in hybrid mode as well as
  32. // in legacy mode.
  33. GetUnifiedPath() (string, error)
  34. // Sets the cgroup as configured.
  35. Set(container *configs.Config) error
  36. // Gets the cgroup as configured.
  37. GetCgroups() (*configs.Cgroup, error)
  38. }
  39. type NotFoundError struct {
  40. Subsystem string
  41. }
  42. func (e *NotFoundError) Error() string {
  43. return fmt.Sprintf("mountpoint for %s not found", e.Subsystem)
  44. }
  45. func NewNotFoundError(sub string) error {
  46. return &NotFoundError{
  47. Subsystem: sub,
  48. }
  49. }
  50. func IsNotFound(err error) bool {
  51. if err == nil {
  52. return false
  53. }
  54. _, ok := err.(*NotFoundError)
  55. return ok
  56. }