freezer.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // +build linux
  2. package fs
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/opencontainers/runc/libcontainer/cgroups"
  8. "github.com/opencontainers/runc/libcontainer/configs"
  9. )
  10. type FreezerGroup struct {
  11. }
  12. func (s *FreezerGroup) Name() string {
  13. return "freezer"
  14. }
  15. func (s *FreezerGroup) Apply(d *cgroupData) error {
  16. _, err := d.join("freezer")
  17. if err != nil && !cgroups.IsNotFound(err) {
  18. return err
  19. }
  20. return nil
  21. }
  22. func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
  23. switch cgroup.Resources.Freezer {
  24. case configs.Frozen, configs.Thawed:
  25. if err := writeFile(path, "freezer.state", string(cgroup.Resources.Freezer)); err != nil {
  26. return err
  27. }
  28. for {
  29. state, err := readFile(path, "freezer.state")
  30. if err != nil {
  31. return err
  32. }
  33. if strings.TrimSpace(state) == string(cgroup.Resources.Freezer) {
  34. break
  35. }
  36. time.Sleep(1 * time.Millisecond)
  37. }
  38. case configs.Undefined:
  39. return nil
  40. default:
  41. return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Resources.Freezer))
  42. }
  43. return nil
  44. }
  45. func (s *FreezerGroup) Remove(d *cgroupData) error {
  46. return removePath(d.path("freezer"))
  47. }
  48. func (s *FreezerGroup) GetStats(path string, stats *cgroups.Stats) error {
  49. return nil
  50. }