2014-05-15 06:21:44 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2014-06-04 08:25:07 +08:00
|
|
|
"time"
|
2014-05-15 06:21:44 +08:00
|
|
|
|
2014-06-10 23:14:16 +08:00
|
|
|
"github.com/docker/libcontainer/cgroups"
|
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
|
|
|
}
|
|
|
|
|
2014-06-20 21:13:56 +08:00
|
|
|
func (s *FreezerGroup) Set(d *data) error {
|
2014-06-04 06:15:11 +08:00
|
|
|
switch d.c.Freezer {
|
|
|
|
case cgroups.Frozen, cgroups.Thawed:
|
|
|
|
dir, err := d.path("freezer")
|
|
|
|
if err != nil {
|
2014-05-15 06:21:44 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-05-31 06:09:07 +08:00
|
|
|
if err := writeFile(dir, "freezer.state", string(d.c.Freezer)); err != nil {
|
2014-05-15 06:21:44 +08:00
|
|
|
return err
|
|
|
|
}
|
2014-06-04 08:25:07 +08:00
|
|
|
|
|
|
|
for {
|
|
|
|
state, err := readFile(dir, "freezer.state")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if strings.TrimSpace(state) == string(d.c.Freezer) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
}
|
2014-06-04 06:15:11 +08:00
|
|
|
default:
|
2014-08-21 01:32:01 +08:00
|
|
|
if _, err := d.join("freezer"); err != nil && !cgroups.IsNotFound(err) {
|
2014-06-04 06:15:11 +08:00
|
|
|
return err
|
|
|
|
}
|
2014-05-15 06:21:44 +08:00
|
|
|
}
|
2014-05-31 06:09:07 +08:00
|
|
|
|
2014-05-15 06:21:44 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:13:56 +08:00
|
|
|
func (s *FreezerGroup) Remove(d *data) 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
|
|
|
}
|