2014-05-15 06:21:44 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
|
|
|
)
|
|
|
|
|
|
|
|
type freezerGroup struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *freezerGroup) Set(d *data) error {
|
|
|
|
dir, err := d.join("freezer")
|
|
|
|
if err != nil {
|
|
|
|
if err != cgroups.ErrNotFound {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.c.Freezer != "" {
|
|
|
|
if err := writeFile(dir, "freezer.state", d.c.Freezer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *freezerGroup) Remove(d *data) error {
|
|
|
|
return removePath(d.path("freezer"))
|
|
|
|
}
|
|
|
|
|
2014-05-28 08:01:08 +08:00
|
|
|
func getFreezerFileData(path string) (string, error) {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
return strings.TrimSuffix(string(data), "\n"), err
|
|
|
|
}
|
2014-05-15 06:21:44 +08:00
|
|
|
|
2014-05-28 08:01:08 +08:00
|
|
|
func (s *freezerGroup) GetStats(d *data, stats *cgroups.Stats) error {
|
2014-05-15 06:21:44 +08:00
|
|
|
path, err := d.path("freezer")
|
|
|
|
if err != nil {
|
2014-05-28 08:01:08 +08:00
|
|
|
return err
|
2014-05-15 06:21:44 +08:00
|
|
|
}
|
2014-05-28 08:01:08 +08: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-05-15 06:21:44 +08:00
|
|
|
}
|
2014-05-28 08:01:08 +08:00
|
|
|
stats.FreezerStats.SelfState = data
|
|
|
|
|
|
|
|
return nil
|
2014-05-15 06:21:44 +08:00
|
|
|
}
|