2015-05-14 06:42:16 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-05-15 06:21:44 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2015-03-31 21:25:06 +08:00
|
|
|
"fmt"
|
2014-05-15 06:21:44 +08:00
|
|
|
"strings"
|
2014-06-04 08:25:07 +08:00
|
|
|
"time"
|
2014-05-15 06:21:44 +08:00
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
2014-05-15 06:21:44 +08:00
|
|
|
)
|
|
|
|
|
2014-06-20 21:13:56 +08:00
|
|
|
type FreezerGroup struct {
|
2014-05-15 06:21:44 +08:00
|
|
|
}
|
|
|
|
|
2015-10-16 06:19:23 +08:00
|
|
|
func (s *FreezerGroup) Name() string {
|
|
|
|
return "freezer"
|
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:08 +08:00
|
|
|
func (s *FreezerGroup) Apply(d *cgroupData) error {
|
2015-12-20 19:30:35 +08:00
|
|
|
_, err := d.join("freezer")
|
2015-03-24 03:14:03 +08:00
|
|
|
if err != nil && !cgroups.IsNotFound(err) {
|
|
|
|
return err
|
2015-03-04 13:45:44 +08:00
|
|
|
}
|
2014-05-15 06:21:44 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-25 17:20:01 +08:00
|
|
|
func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
|
2015-12-15 08:26:29 +08:00
|
|
|
switch cgroup.Resources.Freezer {
|
2015-02-25 17:20:01 +08:00
|
|
|
case configs.Frozen, configs.Thawed:
|
2015-12-15 08:26:29 +08:00
|
|
|
if err := writeFile(path, "freezer.state", string(cgroup.Resources.Freezer)); err != nil {
|
2015-02-25 17:20:01 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
state, err := readFile(path, "freezer.state")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-15 08:26:29 +08:00
|
|
|
if strings.TrimSpace(state) == string(cgroup.Resources.Freezer) {
|
2015-02-25 17:20:01 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
}
|
2015-03-31 21:25:06 +08:00
|
|
|
case configs.Undefined:
|
|
|
|
return nil
|
|
|
|
default:
|
2015-12-15 08:26:29 +08:00
|
|
|
return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Resources.Freezer))
|
2015-02-25 17:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-05 18:41:08 +08:00
|
|
|
func (s *FreezerGroup) Remove(d *cgroupData) error {
|
2014-05-15 06:21:44 +08:00
|
|
|
return removePath(d.path("freezer"))
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:13:56 +08:00
|
|
|
func (s *FreezerGroup) GetStats(path string, stats *cgroups.Stats) error {
|
2014-05-28 08:01:08 +08:00
|
|
|
return nil
|
2014-05-15 06:21:44 +08:00
|
|
|
}
|