2014-04-19 04:55:06 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2014-04-21 01:35:33 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
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-04-30 23:07:12 +00:00
|
|
|
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
|
|
|
|
}
|
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-22 20:50:51 +00:00
|
|
|
func (s *freezerGroup) Stats(d *data) (map[string]int64, error) {
|
2014-04-21 01:35:33 +00:00
|
|
|
var (
|
2014-05-22 20:50:51 +00:00
|
|
|
paramData = make(map[string]int64)
|
2014-04-21 01:35:33 +00:00
|
|
|
params = []string{
|
|
|
|
"parent_freezing",
|
|
|
|
"self_freezing",
|
|
|
|
// comment out right now because this is string "state",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
path, err := d.path("freezer")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-05-22 20:50:51 +00:00
|
|
|
// TODO(vmarmol): This currently outputs nothing since the output is a string, fix.
|
2014-04-21 01:35:33 +00:00
|
|
|
for _, param := range params {
|
|
|
|
f, err := os.Open(filepath.Join(path, fmt.Sprintf("freezer.%s", param)))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-05-22 20:50:51 +00:00
|
|
|
v, err := strconv.ParseInt(strings.TrimSuffix(string(data), "\n"), 10, 64)
|
2014-04-21 01:35:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
paramData[param] = v
|
|
|
|
}
|
|
|
|
return paramData, nil
|
2014-04-20 19:02:39 +00:00
|
|
|
}
|