From fc620fdf81a9e9eddea7216df5e8f73c60786b23 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 7 May 2020 19:33:51 -0700 Subject: [PATCH] libct/cgroups/fs: privatize Manager and its fields This was generated entirely by gorename -- nothing to review here. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/apply_raw.go | 86 ++++++++++++++-------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go index aa5012c3805..e4cbaedecca 100644 --- a/libcontainer/cgroups/fs/apply_raw.go +++ b/libcontainer/cgroups/fs/apply_raw.go @@ -61,18 +61,18 @@ type subsystem interface { Set(path string, cgroup *configs.Cgroup) error } -type Manager struct { +type manager struct { mu sync.Mutex - Cgroups *configs.Cgroup - Rootless bool // ignore permission-related errors - Paths map[string]string + cgroups *configs.Cgroup + rootless bool // ignore permission-related errors + paths map[string]string } func NewManager(cg *configs.Cgroup, paths map[string]string, rootless bool) cgroups.Manager { - return &Manager{ - Cgroups: cg, - Paths: paths, - Rootless: rootless, + return &manager{ + cgroups: cg, + paths: paths, + rootless: rootless, } } @@ -132,25 +132,25 @@ func isIgnorableError(rootless bool, err error) bool { return false } -func (m *Manager) getSubsystems() subsystemSet { +func (m *manager) getSubsystems() subsystemSet { return subsystemsLegacy } -func (m *Manager) Apply(pid int) (err error) { - if m.Cgroups == nil { +func (m *manager) Apply(pid int) (err error) { + if m.cgroups == nil { return nil } m.mu.Lock() defer m.mu.Unlock() - var c = m.Cgroups + var c = m.cgroups - d, err := getCgroupData(m.Cgroups, pid) + d, err := getCgroupData(m.cgroups, pid) if err != nil { return err } - m.Paths = make(map[string]string) + m.paths = make(map[string]string) if c.Paths != nil { for name, path := range c.Paths { _, err := d.path(name) @@ -160,9 +160,9 @@ func (m *Manager) Apply(pid int) (err error) { } return err } - m.Paths[name] = path + m.paths[name] = path } - return cgroups.EnterPid(m.Paths, pid) + return cgroups.EnterPid(m.paths, pid) } for _, sys := range m.getSubsystems() { @@ -178,15 +178,15 @@ func (m *Manager) Apply(pid int) (err error) { } return err } - m.Paths[sys.Name()] = p + m.paths[sys.Name()] = p if err := sys.Apply(d); err != nil { // In the case of rootless (including euid=0 in userns), where an explicit cgroup path hasn't // been set, we don't bail on error in case of permission problems. // Cases where limits have been set (and we couldn't create our own // cgroup) are handled by Set. - if isIgnorableError(m.Rootless, err) && m.Cgroups.Path == "" { - delete(m.Paths, sys.Name()) + if isIgnorableError(m.rootless, err) && m.cgroups.Path == "" { + delete(m.paths, sys.Name()) continue } return err @@ -196,35 +196,35 @@ func (m *Manager) Apply(pid int) (err error) { return nil } -func (m *Manager) Destroy() error { - if m.Cgroups == nil || m.Cgroups.Paths != nil { +func (m *manager) Destroy() error { + if m.cgroups == nil || m.cgroups.Paths != nil { return nil } m.mu.Lock() defer m.mu.Unlock() - if err := cgroups.RemovePaths(m.Paths); err != nil { + if err := cgroups.RemovePaths(m.paths); err != nil { return err } - m.Paths = make(map[string]string) + m.paths = make(map[string]string) return nil } -func (m *Manager) GetPaths() map[string]string { +func (m *manager) GetPaths() map[string]string { m.mu.Lock() - paths := m.Paths + paths := m.paths m.mu.Unlock() return paths } -func (m *Manager) GetUnifiedPath() (string, error) { +func (m *manager) GetUnifiedPath() (string, error) { return "", errors.New("unified path is only supported when running in unified mode") } -func (m *Manager) GetStats() (*cgroups.Stats, error) { +func (m *manager) GetStats() (*cgroups.Stats, error) { m.mu.Lock() defer m.mu.Unlock() stats := cgroups.NewStats() - for name, path := range m.Paths { + for name, path := range m.paths { sys, err := m.getSubsystems().Get(name) if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) { continue @@ -236,14 +236,14 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) { return stats, nil } -func (m *Manager) Set(container *configs.Config) error { +func (m *manager) Set(container *configs.Config) error { if container.Cgroups == nil { return nil } // If Paths are set, then we are just joining cgroups paths // and there is no need to set any values. - if m.Cgroups != nil && m.Cgroups.Paths != nil { + if m.cgroups != nil && m.cgroups.Paths != nil { return nil } @@ -251,7 +251,7 @@ func (m *Manager) Set(container *configs.Config) error { for _, sys := range m.getSubsystems() { path := paths[sys.Name()] if err := sys.Set(path, container.Cgroups); err != nil { - if m.Rootless && sys.Name() == "devices" { + if m.rootless && sys.Name() == "devices" { continue } // When m.Rootless is true, errors from the device subsystem are ignored because it is really not expected to work. @@ -266,8 +266,8 @@ func (m *Manager) Set(container *configs.Config) error { } } - if m.Paths["cpu"] != "" { - if err := CheckCpushares(m.Paths["cpu"], container.Cgroups.Resources.CpuShares); err != nil { + if m.paths["cpu"] != "" { + if err := CheckCpushares(m.paths["cpu"], container.Cgroups.Resources.CpuShares); err != nil { return err } } @@ -276,33 +276,33 @@ func (m *Manager) Set(container *configs.Config) error { // Freeze toggles the container's freezer cgroup depending on the state // provided -func (m *Manager) Freeze(state configs.FreezerState) error { - if m.Cgroups == nil { +func (m *manager) Freeze(state configs.FreezerState) error { + if m.cgroups == nil { return errors.New("cannot toggle freezer: cgroups not configured for container") } paths := m.GetPaths() dir := paths["freezer"] - prevState := m.Cgroups.Resources.Freezer - m.Cgroups.Resources.Freezer = state + prevState := m.cgroups.Resources.Freezer + m.cgroups.Resources.Freezer = state freezer, err := m.getSubsystems().Get("freezer") if err != nil { return err } - err = freezer.Set(dir, m.Cgroups) + err = freezer.Set(dir, m.cgroups) if err != nil { - m.Cgroups.Resources.Freezer = prevState + m.cgroups.Resources.Freezer = prevState return err } return nil } -func (m *Manager) GetPids() ([]int, error) { +func (m *manager) GetPids() ([]int, error) { paths := m.GetPaths() return cgroups.GetPids(paths["devices"]) } -func (m *Manager) GetAllPids() ([]int, error) { +func (m *manager) GetAllPids() ([]int, error) { paths := m.GetPaths() return cgroups.GetAllPids(paths["devices"]) } @@ -410,6 +410,6 @@ func CheckCpushares(path string, c uint64) error { return nil } -func (m *Manager) GetCgroups() (*configs.Cgroup, error) { - return m.Cgroups, nil +func (m *manager) GetCgroups() (*configs.Cgroup, error) { + return m.cgroups, nil }