mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-15 03:51:12 +08:00
new-api: add the Freezer method to cgroup.Manager
Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:

committed by
Andrew Vagin

parent
59e66b818d
commit
ba4257a146
@@ -12,6 +12,8 @@ type Manager interface {
|
|||||||
GetPids() ([]int, error)
|
GetPids() ([]int, error)
|
||||||
GetStats() (*Stats, error)
|
GetStats() (*Stats, error)
|
||||||
|
|
||||||
|
Freeze(state FreezerState) error
|
||||||
|
|
||||||
RemovePaths() error
|
RemovePaths() error
|
||||||
GetPaths() map[string]string
|
GetPaths() map[string]string
|
||||||
SetPaths(map[string]string)
|
SetPaths(map[string]string)
|
||||||
|
@@ -141,13 +141,13 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
|||||||
|
|
||||||
// Freeze toggles the container's freezer cgroup depending on the state
|
// Freeze toggles the container's freezer cgroup depending on the state
|
||||||
// provided
|
// provided
|
||||||
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
|
func (m *Manager) Freeze(state cgroups.FreezerState) error {
|
||||||
d, err := getCgroupData(c, 0)
|
d, err := getCgroupData(m.Cgroups, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Freezer = state
|
m.Cgroups.Freezer = state
|
||||||
|
|
||||||
freezer := subsystems["freezer"]
|
freezer := subsystems["freezer"]
|
||||||
|
|
||||||
|
@@ -39,6 +39,10 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
|||||||
return nil, fmt.Errorf("Systemd not supported")
|
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 {
|
func ApplyDevices(c *cgroups.Cgroup, pid int) error {
|
||||||
return fmt.Errorf("Systemd not supported")
|
return fmt.Errorf("Systemd not supported")
|
||||||
}
|
}
|
||||||
|
@@ -221,8 +221,8 @@ func getSubsystemPath(c *cgroups.Cgroup, subsystem string) (string, error) {
|
|||||||
return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
|
return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
|
func (m *Manager) Freeze(state cgroups.FreezerState) error {
|
||||||
path, err := getSubsystemPath(c, "freezer")
|
path, err := getSubsystemPath(m.Cgroups, "freezer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,10 @@ func (m *mockCgroupManager) GetPaths() map[string]string {
|
|||||||
func (m *mockCgroupManager) SetPaths(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) {
|
func TestGetContainerPids(t *testing.T) {
|
||||||
container := &linuxContainer{
|
container := &linuxContainer{
|
||||||
id: "myid",
|
id: "myid",
|
||||||
|
@@ -4,9 +4,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"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{
|
var pauseCommand = cli.Command{
|
||||||
@@ -22,28 +19,23 @@ var unpauseCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pauseAction(context *cli.Context) {
|
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)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unpauseAction(context *cli.Context) {
|
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)
|
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
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user