cgroups: replace SetPaths on LoadCgroupManager

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-01-14 18:47:26 +03:00 committed by Andrew Vagin
parent ba4257a146
commit ee6e585e21
7 changed files with 25 additions and 26 deletions

View File

@ -16,7 +16,6 @@ type Manager interface {
RemovePaths() error
GetPaths() map[string]string
SetPaths(map[string]string)
}
type FreezerState string

View File

@ -26,7 +26,7 @@ var (
type Manager struct {
Cgroups *cgroups.Cgroup
paths map[string]string
Paths map[string]string
}
// The absolute path to the root of the cgroup hierarchies.
@ -94,21 +94,17 @@ func (m *Manager) Apply(pid int) error {
}
paths[name] = p
}
m.paths = paths
m.Paths = paths
return nil
}
func (m *Manager) RemovePaths() error {
return cgroups.RemovePaths(m.paths)
return cgroups.RemovePaths(m.Paths)
}
func (m *Manager) GetPaths() map[string]string {
return m.paths
}
func (m *Manager) SetPaths(paths map[string]string) {
m.paths = paths
return m.Paths
}
// Symmetrical public function to update device based cgroups. Also available
@ -126,7 +122,7 @@ func ApplyDevices(c *cgroups.Cgroup, pid int) error {
func (m *Manager) GetStats() (*cgroups.Stats, error) {
stats := cgroups.NewStats()
for name, path := range m.paths {
for name, path := range m.Paths {
sys, ok := subsystems[name]
if !ok {
continue

View File

@ -17,3 +17,17 @@ func NewCgroupManager(cgroups *cgroups.Cgroup) cgroups.Manager {
Cgroups: cgroups,
}
}
func LoadCgroupManager(cgroups *cgroups.Cgroup, paths map[string]string) cgroups.Manager {
if systemd.UseSystemd() {
return &systemd.Manager{
Cgroups: cgroups,
Paths: paths,
}
}
return &fs.Manager{
Cgroups: cgroups,
Paths: paths,
}
}

View File

@ -10,6 +10,7 @@ import (
type Manager struct {
Cgroups *cgroups.Cgroup
Paths map[string]string
}
func UseSystemd() bool {
@ -32,9 +33,6 @@ func (m *Manager) GetPaths() map[string]string {
return nil
}
func (m *Manager) SetPaths(paths map[string]string) {
}
func (m *Manager) GetStats() (*cgroups.Stats, error) {
return nil, fmt.Errorf("Systemd not supported")
}

View File

@ -21,7 +21,7 @@ import (
type Manager struct {
Cgroups *cgroups.Cgroup
paths map[string]string
Paths map[string]string
}
type subsystem interface {
@ -168,21 +168,17 @@ func (m *Manager) Apply(pid int) error {
paths[sysname] = subsystemPath
}
m.paths = paths
m.Paths = paths
return nil
}
func (m *Manager) RemovePaths() error {
return cgroups.RemovePaths(m.paths)
return cgroups.RemovePaths(m.Paths)
}
func (m *Manager) GetPaths() map[string]string {
return m.paths
}
func (m *Manager) SetPaths(paths map[string]string) {
m.paths = paths
return m.Paths
}
func writeFile(dir, file, data string) error {

View File

@ -34,9 +34,6 @@ func (m *mockCgroupManager) GetPaths() map[string]string {
return nil
}
func (m *mockCgroupManager) SetPaths(map[string]string) {
}
func (m *mockCgroupManager) Freeze(state cgroups.FreezerState) error {
return nil
}

View File

@ -117,8 +117,7 @@ func (l *linuxFactory) Load(id string) (Container, error) {
return nil, err
}
cgroupManager := cgroups.NewCgroupManager(config.Cgroups)
cgroupManager.SetPaths(state.CgroupPaths)
cgroupManager := cgroups.LoadCgroupManager(config.Cgroups, state.CgroupPaths)
glog.Infof("using %s as cgroup manager", cgroupManager)
return &linuxContainer{
id: id,