new-api: add the Freezer method to cgroup.Manager

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-01-13 14:52:14 +03:00 committed by Andrew Vagin
parent 59e66b818d
commit ba4257a146
6 changed files with 27 additions and 25 deletions

View File

@ -12,6 +12,8 @@ type Manager interface {
GetPids() ([]int, error)
GetStats() (*Stats, error)
Freeze(state FreezerState) error
RemovePaths() error
GetPaths() map[string]string
SetPaths(map[string]string)

View File

@ -141,13 +141,13 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
// Freeze toggles the container's freezer cgroup depending on the state
// provided
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
d, err := getCgroupData(c, 0)
func (m *Manager) Freeze(state cgroups.FreezerState) error {
d, err := getCgroupData(m.Cgroups, 0)
if err != nil {
return err
}
c.Freezer = state
m.Cgroups.Freezer = state
freezer := subsystems["freezer"]

View File

@ -39,6 +39,10 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
return nil, fmt.Errorf("Systemd not supported")
}
func (m *Manager) Freeze(state cgroups.FreezerState) error {
return fmt.Errorf("Systemd not supported")
}
func ApplyDevices(c *cgroups.Cgroup, pid int) error {
return fmt.Errorf("Systemd not supported")
}

View File

@ -221,8 +221,8 @@ func getSubsystemPath(c *cgroups.Cgroup, subsystem string) (string, error) {
return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
}
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
path, err := getSubsystemPath(c, "freezer")
func (m *Manager) Freeze(state cgroups.FreezerState) error {
path, err := getSubsystemPath(m.Cgroups, "freezer")
if err != nil {
return err
}

View File

@ -37,6 +37,10 @@ func (m *mockCgroupManager) GetPaths() map[string]string {
func (m *mockCgroupManager) SetPaths(map[string]string) {
}
func (m *mockCgroupManager) Freeze(state cgroups.FreezerState) error {
return nil
}
func TestGetContainerPids(t *testing.T) {
container := &linuxContainer{
id: "myid",

View File

@ -4,9 +4,6 @@ import (
"log"
"github.com/codegangsta/cli"
"github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd"
)
var pauseCommand = cli.Command{
@ -22,28 +19,23 @@ var unpauseCommand = cli.Command{
}
func pauseAction(context *cli.Context) {
if err := toggle(cgroups.Frozen); err != nil {
container, err := getContainer(context)
if err != nil {
log.Fatal(err)
}
if err = container.Pause(); err != nil {
log.Fatal(err)
}
}
func unpauseAction(context *cli.Context) {
if err := toggle(cgroups.Thawed); err != nil {
container, err := getContainer(context)
if err != nil {
log.Fatal(err)
}
if err = container.Resume(); err != nil {
log.Fatal(err)
}
}
func toggle(state cgroups.FreezerState) error {
container, err := loadConfig()
if err != nil {
return err
}
if systemd.UseSystemd() {
err = systemd.Freeze(container.Cgroups, state)
} else {
err = fs.Freeze(container.Cgroups, state)
}
return err
}