2014-04-19 04:55:06 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2014-04-21 01:35:33 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2014-06-04 00:25:07 +00:00
|
|
|
"time"
|
2014-04-30 23:07:12 +00:00
|
|
|
|
2014-05-14 22:21:44 +00:00
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
2014-04-19 04:55:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type freezerGroup struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *freezerGroup) Set(d *data) error {
|
2014-06-03 22:15:11 +00:00
|
|
|
switch d.c.Freezer {
|
|
|
|
case cgroups.Frozen, cgroups.Thawed:
|
|
|
|
dir, err := d.path("freezer")
|
|
|
|
if err != nil {
|
2014-04-30 23:07:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-05-30 22:09:07 +00:00
|
|
|
if err := writeFile(dir, "freezer.state", string(d.c.Freezer)); err != nil {
|
2014-04-30 23:07:12 +00:00
|
|
|
return err
|
|
|
|
}
|
2014-06-04 00:25:07 +00: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-03 22:15:11 +00:00
|
|
|
default:
|
|
|
|
if _, err := d.join("freezer"); err != nil && err != cgroups.ErrNotFound {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-19 04:55:06 +00:00
|
|
|
}
|
2014-05-30 22:09:07 +00:00
|
|
|
|
2014-04-19 04:55:06 +00:00
|
|
|
return nil
|
|
|
|
}
|
2014-04-19 05:17:31 +00:00
|
|
|
|
|
|
|
func (s *freezerGroup) Remove(d *data) error {
|
|
|
|
return removePath(d.path("freezer"))
|
|
|
|
}
|
2014-04-20 19:02:39 +00:00
|
|
|
|
2014-05-28 00:01:08 +00:00
|
|
|
func getFreezerFileData(path string) (string, error) {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
return strings.TrimSuffix(string(data), "\n"), err
|
|
|
|
}
|
2014-04-21 01:35:33 +00:00
|
|
|
|
2014-05-28 00:01:08 +00:00
|
|
|
func (s *freezerGroup) GetStats(d *data, stats *cgroups.Stats) error {
|
2014-04-21 01:35:33 +00:00
|
|
|
path, err := d.path("freezer")
|
|
|
|
if err != nil {
|
2014-05-28 00:01:08 +00:00
|
|
|
return err
|
2014-04-21 01:35:33 +00:00
|
|
|
}
|
2014-05-28 00:01:08 +00:00
|
|
|
var data string
|
|
|
|
if data, err = getFreezerFileData(filepath.Join(path, "freezer.parent_freezing")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
stats.FreezerStats.ParentState = data
|
|
|
|
if data, err = getFreezerFileData(filepath.Join(path, "freezer.self_freezing")); err != nil {
|
|
|
|
return err
|
2014-04-21 01:35:33 +00:00
|
|
|
}
|
2014-05-28 00:01:08 +00:00
|
|
|
stats.FreezerStats.SelfState = data
|
|
|
|
|
|
|
|
return nil
|
2014-04-20 19:02:39 +00:00
|
|
|
}
|