Skip to content

Commit

Permalink
libct/cgroups/fs: privatize Manager and its fields
Browse files Browse the repository at this point in the history
This was generated entirely by gorename -- nothing to review here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed May 8, 2020
1 parent 5935bf8 commit fc620fd
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -236,22 +236,22 @@ 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
}

paths := m.GetPaths()
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.
Expand All @@ -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
}
}
Expand All @@ -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"])
}
Expand Down Expand Up @@ -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
}

0 comments on commit fc620fd

Please sign in to comment.