cgroups: replace SetPaths on LoadCgroupManager
Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
parent
ba4257a146
commit
ee6e585e21
|
@ -16,7 +16,6 @@ type Manager interface {
|
||||||
|
|
||||||
RemovePaths() error
|
RemovePaths() error
|
||||||
GetPaths() map[string]string
|
GetPaths() map[string]string
|
||||||
SetPaths(map[string]string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FreezerState string
|
type FreezerState string
|
||||||
|
|
|
@ -26,7 +26,7 @@ var (
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
Cgroups *cgroups.Cgroup
|
Cgroups *cgroups.Cgroup
|
||||||
paths map[string]string
|
Paths map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// The absolute path to the root of the cgroup hierarchies.
|
// The absolute path to the root of the cgroup hierarchies.
|
||||||
|
@ -94,21 +94,17 @@ func (m *Manager) Apply(pid int) error {
|
||||||
}
|
}
|
||||||
paths[name] = p
|
paths[name] = p
|
||||||
}
|
}
|
||||||
m.paths = paths
|
m.Paths = paths
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) RemovePaths() error {
|
func (m *Manager) RemovePaths() error {
|
||||||
return cgroups.RemovePaths(m.paths)
|
return cgroups.RemovePaths(m.Paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) GetPaths() map[string]string {
|
func (m *Manager) GetPaths() map[string]string {
|
||||||
return m.paths
|
return m.Paths
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) SetPaths(paths map[string]string) {
|
|
||||||
m.paths = paths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Symmetrical public function to update device based cgroups. Also available
|
// 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) {
|
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
||||||
stats := cgroups.NewStats()
|
stats := cgroups.NewStats()
|
||||||
for name, path := range m.paths {
|
for name, path := range m.Paths {
|
||||||
sys, ok := subsystems[name]
|
sys, ok := subsystems[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -17,3 +17,17 @@ func NewCgroupManager(cgroups *cgroups.Cgroup) cgroups.Manager {
|
||||||
Cgroups: cgroups,
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
Cgroups *cgroups.Cgroup
|
Cgroups *cgroups.Cgroup
|
||||||
|
Paths map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func UseSystemd() bool {
|
func UseSystemd() bool {
|
||||||
|
@ -32,9 +33,6 @@ func (m *Manager) GetPaths() map[string]string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) SetPaths(paths map[string]string) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
||||||
return nil, fmt.Errorf("Systemd not supported")
|
return nil, fmt.Errorf("Systemd not supported")
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
Cgroups *cgroups.Cgroup
|
Cgroups *cgroups.Cgroup
|
||||||
paths map[string]string
|
Paths map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type subsystem interface {
|
type subsystem interface {
|
||||||
|
@ -168,21 +168,17 @@ func (m *Manager) Apply(pid int) error {
|
||||||
paths[sysname] = subsystemPath
|
paths[sysname] = subsystemPath
|
||||||
}
|
}
|
||||||
|
|
||||||
m.paths = paths
|
m.Paths = paths
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) RemovePaths() error {
|
func (m *Manager) RemovePaths() error {
|
||||||
return cgroups.RemovePaths(m.paths)
|
return cgroups.RemovePaths(m.Paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) GetPaths() map[string]string {
|
func (m *Manager) GetPaths() map[string]string {
|
||||||
return m.paths
|
return m.Paths
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) SetPaths(paths map[string]string) {
|
|
||||||
m.paths = paths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeFile(dir, file, data string) error {
|
func writeFile(dir, file, data string) error {
|
||||||
|
|
|
@ -34,9 +34,6 @@ func (m *mockCgroupManager) GetPaths() map[string]string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) SetPaths(map[string]string) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockCgroupManager) Freeze(state cgroups.FreezerState) error {
|
func (m *mockCgroupManager) Freeze(state cgroups.FreezerState) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,8 +117,7 @@ func (l *linuxFactory) Load(id string) (Container, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cgroupManager := cgroups.NewCgroupManager(config.Cgroups)
|
cgroupManager := cgroups.LoadCgroupManager(config.Cgroups, state.CgroupPaths)
|
||||||
cgroupManager.SetPaths(state.CgroupPaths)
|
|
||||||
glog.Infof("using %s as cgroup manager", cgroupManager)
|
glog.Infof("using %s as cgroup manager", cgroupManager)
|
||||||
return &linuxContainer{
|
return &linuxContainer{
|
||||||
id: id,
|
id: id,
|
||||||
|
|
Loading…
Reference in New Issue