libcontainer: add method to get cgroup config from cgroup Manager

`configs.Cgroup` contains the configuration used to create cgroups. This
configuration must be saved to disk, since it's required to restore the
cgroup manager that was used to create the cgroups.
Add method to get cgroup configuration from cgroup Manager to allow API users
save it to disk and restore a cgroup manager later.

fixes #2176

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-12-06 15:43:08 +00:00
parent cd7c59d042
commit 8ddd892072
6 changed files with 26 additions and 0 deletions

View File

@ -46,6 +46,9 @@ type Manager interface {
// Sets the cgroup as configured. // Sets the cgroup as configured.
Set(container *configs.Config) error Set(container *configs.Config) error
// Gets the cgroup as configured.
GetCgroups() (*configs.Cgroup, error)
} }
type NotFoundError struct { type NotFoundError struct {

View File

@ -467,3 +467,7 @@ func CheckCpushares(path string, c uint64) error {
return nil return nil
} }
func (m *Manager) GetCgroups() (*configs.Cgroup, error) {
return m.Cgroups, nil
}

View File

@ -61,3 +61,7 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
func Freeze(c *configs.Cgroup, state configs.FreezerState) error { func Freeze(c *configs.Cgroup, state configs.FreezerState) error {
return fmt.Errorf("Systemd not supported") return fmt.Errorf("Systemd not supported")
} }
func (m *Manager) GetCgroups() (*configs.Cgroup, error) {
return nil, fmt.Errorf("Systemd not supported")
}

View File

@ -528,3 +528,7 @@ func isUnitExists(err error) bool {
} }
return false return false
} }
func (m *LegacyManager) GetCgroups() (*configs.Cgroup, error) {
return m.Cgroups, nil
}

View File

@ -346,3 +346,7 @@ func (m *UnifiedManager) Set(container *configs.Config) error {
} }
return nil return nil
} }
func (m *UnifiedManager) GetCgroups() (*configs.Cgroup, error) {
return m.Cgroups, nil
}

View File

@ -61,6 +61,9 @@ func (m *mockCgroupManager) GetUnifiedPath() (string, error) {
func (m *mockCgroupManager) Freeze(state configs.FreezerState) error { func (m *mockCgroupManager) Freeze(state configs.FreezerState) error {
return nil return nil
} }
func (m *mockCgroupManager) GetCgroups() (*configs.Cgroup, error) {
return nil, nil
}
func (m *mockIntelRdtManager) Apply(pid int) error { func (m *mockIntelRdtManager) Apply(pid int) error {
return nil return nil
@ -82,6 +85,10 @@ func (m *mockIntelRdtManager) Set(container *configs.Config) error {
return nil return nil
} }
func (m *mockIntelRdtManager) GetCgroups() (*configs.Cgroup, error) {
return nil, nil
}
type mockProcess struct { type mockProcess struct {
_pid int _pid int
started uint64 started uint64