Merge pull request #2496 from kolyshkin/freeze-nits
libct/cgroups/fs: simplify/speedup freezer code
This commit is contained in:
commit
e638eda0cb
|
@ -298,7 +298,7 @@ func (m *manager) Set(container *configs.Config) 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 (m *manager) Freeze(state configs.FreezerState) (Err error) {
|
func (m *manager) Freeze(state configs.FreezerState) error {
|
||||||
path := m.Path("freezer")
|
path := m.Path("freezer")
|
||||||
if m.cgroups == nil || path == "" {
|
if m.cgroups == nil || path == "" {
|
||||||
return errors.New("cannot toggle freezer: cgroups not configured for container")
|
return errors.New("cannot toggle freezer: cgroups not configured for container")
|
||||||
|
@ -306,17 +306,9 @@ func (m *manager) Freeze(state configs.FreezerState) (Err error) {
|
||||||
|
|
||||||
prevState := m.cgroups.Resources.Freezer
|
prevState := m.cgroups.Resources.Freezer
|
||||||
m.cgroups.Resources.Freezer = state
|
m.cgroups.Resources.Freezer = state
|
||||||
defer func() {
|
freezer := &FreezerGroup{}
|
||||||
if Err != nil {
|
|
||||||
m.cgroups.Resources.Freezer = prevState
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
freezer, err := m.getSubsystems().Get("freezer")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := freezer.Set(path, m.cgroups); err != nil {
|
if err := freezer.Set(path, m.cgroups); err != nil {
|
||||||
|
m.cgroups.Resources.Freezer = prevState
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -418,13 +410,12 @@ func (m *manager) GetCgroups() (*configs.Cgroup, error) {
|
||||||
|
|
||||||
func (m *manager) GetFreezerState() (configs.FreezerState, error) {
|
func (m *manager) GetFreezerState() (configs.FreezerState, error) {
|
||||||
dir := m.Path("freezer")
|
dir := m.Path("freezer")
|
||||||
freezer, err := m.getSubsystems().Get("freezer")
|
|
||||||
|
|
||||||
// If the container doesn't have the freezer cgroup, say it's undefined.
|
// If the container doesn't have the freezer cgroup, say it's undefined.
|
||||||
if err != nil || dir == "" {
|
if dir == "" {
|
||||||
return configs.Undefined, nil
|
return configs.Undefined, nil
|
||||||
}
|
}
|
||||||
return freezer.(*FreezerGroup).GetState(dir)
|
freezer := &FreezerGroup{}
|
||||||
|
return freezer.GetState(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *manager) Exists() bool {
|
func (m *manager) Exists() bool {
|
||||||
|
|
|
@ -319,10 +319,7 @@ func (m *legacyManager) Freeze(state configs.FreezerState) error {
|
||||||
}
|
}
|
||||||
prevState := m.cgroups.Resources.Freezer
|
prevState := m.cgroups.Resources.Freezer
|
||||||
m.cgroups.Resources.Freezer = state
|
m.cgroups.Resources.Freezer = state
|
||||||
freezer, err := legacySubsystems.Get("freezer")
|
freezer := &fs.FreezerGroup{}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = freezer.Set(path, m.cgroups)
|
err = freezer.Set(path, m.cgroups)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.cgroups.Resources.Freezer = prevState
|
m.cgroups.Resources.Freezer = prevState
|
||||||
|
@ -458,11 +455,8 @@ func (m *legacyManager) GetFreezerState() (configs.FreezerState, error) {
|
||||||
if err != nil && !cgroups.IsNotFound(err) {
|
if err != nil && !cgroups.IsNotFound(err) {
|
||||||
return configs.Undefined, err
|
return configs.Undefined, err
|
||||||
}
|
}
|
||||||
freezer, err := legacySubsystems.Get("freezer")
|
freezer := &fs.FreezerGroup{}
|
||||||
if err != nil {
|
return freezer.GetState(path)
|
||||||
return configs.Undefined, err
|
|
||||||
}
|
|
||||||
return freezer.(*fs.FreezerGroup).GetState(path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *legacyManager) Exists() bool {
|
func (m *legacyManager) Exists() bool {
|
||||||
|
|
Loading…
Reference in New Issue