cgroupv1/systemd: (re)use m.paths
In all these cases, getSubsystemPath() was already called, and its
result stored in m.paths map. It makes no sense to not reuse it.
@@ -289,15 +289,14 @@ func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
}
func (m *legacyManager) Freeze(state configs.FreezerState) error {
- path, err := getSubsystemPath(m.cgroups, "freezer")
- if err != nil {
- return err
+ path, ok := m.paths["freezer"]
+ if !ok {
+ return errSubsystemDoesNotExist
}
prevState := m.cgroups.Resources.Freezer
m.cgroups.Resources.Freezer = state
freezer := &fs.FreezerGroup{}
- err = freezer.Set(path, m.cgroups)
- if err != nil {
+ if err := freezer.Set(path, m.cgroups); err != nil {
m.cgroups.Resources.Freezer = prevState
return err
}
@@ -305,17 +304,17 @@ func (m *legacyManager) Freeze(state configs.FreezerState) error {
}
func (m *legacyManager) GetPids() ([]int, error) {
- path, err := getSubsystemPath(m.cgroups, "devices")
- if err != nil {
- return nil, err
+ path, ok := m.paths["devices"]
+ if !ok {
+ return nil, errSubsystemDoesNotExist
}
return cgroups.GetPids(path)
}
func (m *legacyManager) GetAllPids() ([]int, error) {
- path, err := getSubsystemPath(m.cgroups, "devices")
- if err != nil {
- return nil, err
+ path, ok := m.paths["devices"]
+ if !ok {
+ return nil, errSubsystemDoesNotExist
}
return cgroups.GetAllPids(path)
}
@@ -386,9 +385,9 @@ func (m *legacyManager) Set(container *configs.Config) error {
for _, sys := range legacySubsystems {
// Get the subsystem path, but don't error out for not found cgroups.
- path, err := getSubsystemPath(container.Cgroups, sys.Name())
- if err != nil && !cgroups.IsNotFound(err) {
- return err
+ path, ok := m.paths[sys.Name()]
+ if !ok {
+ continue
}
if err := sys.Set(path, container.Cgroups); err != nil {
return err
@@ -430,9 +429,9 @@ func (m *legacyManager) GetCgroups() (*configs.Cgroup, error) {
}
func (m *legacyManager) GetFreezerState() (configs.FreezerState, error) {
- path, err := getSubsystemPath(m.cgroups, "freezer")
- if err != nil && !cgroups.IsNotFound(err) {
- return configs.Undefined, err
+ path, ok := m.paths["freezer"]
+ if !ok {
+ return configs.Undefined, nil
}
freezer := &fs.FreezerGroup{}
return freezer.GetState(path)
