libct/cgroups/systemd/v1: privatize v1 manager

This patch was generated entirely by gorename -- nothing to review here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-05-07 19:37:53 -07:00
parent d827e323b0
commit 51e1a0842d
1 changed files with 38 additions and 38 deletions

View File

@ -17,16 +17,16 @@ import (
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
) )
type LegacyManager struct { type legacyManager struct {
mu sync.Mutex mu sync.Mutex
Cgroups *configs.Cgroup cgroups *configs.Cgroup
Paths map[string]string paths map[string]string
} }
func NewLegacyManager(cg *configs.Cgroup, paths map[string]string) cgroups.Manager { func NewLegacyManager(cg *configs.Cgroup, paths map[string]string) cgroups.Manager {
return &LegacyManager{ return &legacyManager{
Cgroups: cg, cgroups: cg,
Paths: paths, paths: paths,
} }
} }
@ -121,9 +121,9 @@ func genV1ResourcesProperties(c *configs.Cgroup) ([]systemdDbus.Property, error)
return properties, nil return properties, nil
} }
func (m *LegacyManager) Apply(pid int) error { func (m *legacyManager) Apply(pid int) error {
var ( var (
c = m.Cgroups c = m.cgroups
unitName = getUnitName(c) unitName = getUnitName(c)
slice = "system.slice" slice = "system.slice"
properties []systemdDbus.Property properties []systemdDbus.Property
@ -132,7 +132,7 @@ func (m *LegacyManager) Apply(pid int) error {
if c.Paths != nil { if c.Paths != nil {
paths := make(map[string]string) paths := make(map[string]string)
for name, path := range c.Paths { for name, path := range c.Paths {
_, err := getSubsystemPath(m.Cgroups, name) _, err := getSubsystemPath(m.cgroups, name)
if err != nil { if err != nil {
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem // Don't fail if a cgroup hierarchy was not found, just skip this subsystem
if cgroups.IsNotFound(err) { if cgroups.IsNotFound(err) {
@ -142,8 +142,8 @@ func (m *LegacyManager) Apply(pid int) error {
} }
paths[name] = path paths[name] = path
} }
m.Paths = paths m.paths = paths
return cgroups.EnterPid(m.Paths, pid) return cgroups.EnterPid(m.paths, pid)
} }
if c.Parent != "" { if c.Parent != "" {
@ -203,7 +203,7 @@ func (m *LegacyManager) Apply(pid int) error {
paths := make(map[string]string) paths := make(map[string]string)
for _, s := range legacySubsystems { for _, s := range legacySubsystems {
subsystemPath, err := getSubsystemPath(m.Cgroups, s.Name()) subsystemPath, err := getSubsystemPath(m.cgroups, s.Name())
if err != nil { if err != nil {
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem // Don't fail if a cgroup hierarchy was not found, just skip this subsystem
if cgroups.IsNotFound(err) { if cgroups.IsNotFound(err) {
@ -213,12 +213,12 @@ func (m *LegacyManager) Apply(pid int) error {
} }
paths[s.Name()] = subsystemPath paths[s.Name()] = subsystemPath
} }
m.Paths = paths m.paths = paths
return nil return nil
} }
func (m *LegacyManager) Destroy() error { func (m *legacyManager) Destroy() error {
if m.Cgroups.Paths != nil { if m.cgroups.Paths != nil {
return nil return nil
} }
m.mu.Lock() m.mu.Lock()
@ -228,22 +228,22 @@ func (m *LegacyManager) Destroy() error {
if err != nil { if err != nil {
return err return err
} }
unitName := getUnitName(m.Cgroups) unitName := getUnitName(m.cgroups)
if err := stopUnit(dbusConnection, unitName); err != nil { if err := stopUnit(dbusConnection, unitName); err != nil {
return err return err
} }
m.Paths = make(map[string]string) m.paths = make(map[string]string)
return nil return nil
} }
func (m *LegacyManager) GetPaths() map[string]string { func (m *legacyManager) GetPaths() map[string]string {
m.mu.Lock() m.mu.Lock()
paths := m.Paths paths := m.paths
m.mu.Unlock() m.mu.Unlock()
return paths return paths
} }
func (m *LegacyManager) GetUnifiedPath() (string, error) { func (m *legacyManager) GetUnifiedPath() (string, error) {
return "", errors.New("unified path is only supported when running in unified mode") return "", errors.New("unified path is only supported when running in unified mode")
} }
@ -324,46 +324,46 @@ func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
} }
func (m *LegacyManager) Freeze(state configs.FreezerState) error { func (m *legacyManager) Freeze(state configs.FreezerState) error {
path, err := getSubsystemPath(m.Cgroups, "freezer") path, err := getSubsystemPath(m.cgroups, "freezer")
if err != nil { if err != nil {
return err return err
} }
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, err := legacySubsystems.Get("freezer")
if err != nil { if err != nil {
return err 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
return err return err
} }
return nil return nil
} }
func (m *LegacyManager) GetPids() ([]int, error) { func (m *legacyManager) GetPids() ([]int, error) {
path, err := getSubsystemPath(m.Cgroups, "devices") path, err := getSubsystemPath(m.cgroups, "devices")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return cgroups.GetPids(path) return cgroups.GetPids(path)
} }
func (m *LegacyManager) GetAllPids() ([]int, error) { func (m *legacyManager) GetAllPids() ([]int, error) {
path, err := getSubsystemPath(m.Cgroups, "devices") path, err := getSubsystemPath(m.cgroups, "devices")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return cgroups.GetAllPids(path) return cgroups.GetAllPids(path)
} }
func (m *LegacyManager) GetStats() (*cgroups.Stats, error) { func (m *legacyManager) GetStats() (*cgroups.Stats, error) {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
stats := cgroups.NewStats() stats := cgroups.NewStats()
for name, path := range m.Paths { for name, path := range m.paths {
sys, err := legacySubsystems.Get(name) sys, err := legacySubsystems.Get(name)
if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) { if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
continue continue
@ -376,10 +376,10 @@ func (m *LegacyManager) GetStats() (*cgroups.Stats, error) {
return stats, nil return stats, nil
} }
func (m *LegacyManager) Set(container *configs.Config) error { func (m *legacyManager) Set(container *configs.Config) error {
// If Paths are set, then we are just joining cgroups paths // If Paths are set, then we are just joining cgroups paths
// and there is no need to set any values. // and there is no need to set any values.
if m.Cgroups.Paths != nil { if m.cgroups.Paths != nil {
return nil return nil
} }
properties, err := genV1ResourcesProperties(container.Cgroups) properties, err := genV1ResourcesProperties(container.Cgroups)
@ -406,8 +406,8 @@ func (m *LegacyManager) Set(container *configs.Config) error {
} }
} }
if m.Paths["cpu"] != "" { if m.paths["cpu"] != "" {
if err := fs.CheckCpushares(m.Paths["cpu"], container.Cgroups.Resources.CpuShares); err != nil { if err := fs.CheckCpushares(m.paths["cpu"], container.Cgroups.Resources.CpuShares); err != nil {
return err return err
} }
} }
@ -434,6 +434,6 @@ func setKernelMemory(c *configs.Cgroup) error {
} }
return fs.EnableKernelMemoryAccounting(path) return fs.EnableKernelMemoryAccounting(path)
} }
func (m *LegacyManager) GetCgroups() (*configs.Cgroup, error) { func (m *legacyManager) GetCgroups() (*configs.Cgroup, error) {
return m.Cgroups, nil return m.cgroups, nil
} }