cgroups.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // NewCgroupManager() and LoadCgroupManager() require following attributes:
  21. // Paths map[string]string
  22. // Cgroups *cgroups.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. // Set the cgroup as configured.
  29. Set(container *configs.Config) error
  30. }
  31. type NotFoundError struct {
  32. Subsystem string
  33. }
  34. func (e *NotFoundError) Error() string {
  35. return fmt.Sprintf("mountpoint for %s not found", e.Subsystem)
  36. }
  37. func NewNotFoundError(sub string) error {
  38. return &NotFoundError{
  39. Subsystem: sub,
  40. }
  41. }
  42. func IsNotFound(err error) bool {
  43. if err == nil {
  44. return false
  45. }
  46. _, ok := err.(*NotFoundError)
  47. return ok
  48. }