Merge pull request #388 from hqhq/hq_cgroup_cleanups

Some cgroup cleanups
This commit is contained in:
Alexander Morozov 2015-11-13 09:06:18 -08:00
commit bda4ca2f8f
23 changed files with 116 additions and 112 deletions

View File

@ -52,10 +52,10 @@ type subsystem interface {
Name() string Name() string
// Returns the stats, as 'stats', corresponding to the cgroup under 'path'. // Returns the stats, as 'stats', corresponding to the cgroup under 'path'.
GetStats(path string, stats *cgroups.Stats) error GetStats(path string, stats *cgroups.Stats) error
// Removes the cgroup represented by 'data'. // Removes the cgroup represented by 'cgroupData'.
Remove(*data) error Remove(*cgroupData) error
// Creates and joins the cgroup represented by data. // Creates and joins the cgroup represented by 'cgroupData'.
Apply(*data) error Apply(*cgroupData) error
// Set the cgroup represented by cgroup. // Set the cgroup represented by cgroup.
Set(path string, cgroup *configs.Cgroup) error Set(path string, cgroup *configs.Cgroup) error
} }
@ -92,10 +92,11 @@ func getCgroupRoot() (string, error) {
return cgroupRoot, nil return cgroupRoot, nil
} }
type data struct { type cgroupData struct {
root string root string
cgroup string parent string
c *configs.Cgroup name string
config *configs.Cgroup
pid int pid int
} }
@ -229,30 +230,31 @@ func (m *Manager) GetPids() ([]int, error) {
return cgroups.GetPids(dir) return cgroups.GetPids(dir)
} }
func getCgroupData(c *configs.Cgroup, pid int) (*data, error) { func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) {
root, err := getCgroupRoot() root, err := getCgroupRoot()
if err != nil { if err != nil {
return nil, err return nil, err
} }
cgroup := c.Name return &cgroupData{
if c.Parent != "" {
cgroup = filepath.Join(c.Parent, cgroup)
}
return &data{
root: root, root: root,
cgroup: cgroup, parent: c.Parent,
c: c, name: c.Name,
config: c,
pid: pid, pid: pid,
}, nil }, nil
} }
func (raw *data) parent(subsystem, mountpoint, root string) (string, error) { func (raw *cgroupData) parentPath(subsystem, mountpoint, root string) (string, error) {
// Use GetThisCgroupDir instead of GetInitCgroupDir, because the creating
// process could in container and shared pid namespace with host, and
// /proc/1/cgroup could point to whole other world of cgroups.
initPath, err := cgroups.GetThisCgroupDir(subsystem) initPath, err := cgroups.GetThisCgroupDir(subsystem)
if err != nil { if err != nil {
return "", err return "", err
} }
// This is needed for nested containers, because in /proc/self/cgroup we
// see pathes from host, which don't exist in container.
relDir, err := filepath.Rel(root, initPath) relDir, err := filepath.Rel(root, initPath)
if err != nil { if err != nil {
return "", err return "", err
@ -260,27 +262,29 @@ func (raw *data) parent(subsystem, mountpoint, root string) (string, error) {
return filepath.Join(mountpoint, relDir), nil return filepath.Join(mountpoint, relDir), nil
} }
func (raw *data) path(subsystem string) (string, error) { func (raw *cgroupData) path(subsystem string) (string, error) {
mnt, root, err := cgroups.FindCgroupMountpointAndRoot(subsystem) mnt, root, err := cgroups.FindCgroupMountpointAndRoot(subsystem)
// If we didn't mount the subsystem, there is no point we make the path. // If we didn't mount the subsystem, there is no point we make the path.
if err != nil { if err != nil {
return "", err return "", err
} }
cgPath := filepath.Join(raw.parent, raw.name)
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process. // If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
if filepath.IsAbs(raw.cgroup) { if filepath.IsAbs(cgPath) {
return filepath.Join(raw.root, filepath.Base(mnt), raw.cgroup), nil // Sometimes subsystems can be mounted togethger as 'cpu,cpuacct'.
return filepath.Join(raw.root, filepath.Base(mnt), cgPath), nil
} }
parent, err := raw.parent(subsystem, mnt, root) parentPath, err := raw.parentPath(subsystem, mnt, root)
if err != nil { if err != nil {
return "", err return "", err
} }
return filepath.Join(parent, raw.cgroup), nil return filepath.Join(parentPath, cgPath), nil
} }
func (raw *data) join(subsystem string) (string, error) { func (raw *cgroupData) join(subsystem string) (string, error) {
path, err := raw.path(subsystem) path, err := raw.path(subsystem)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -21,13 +21,13 @@ func (s *BlkioGroup) Name() string {
return "blkio" return "blkio"
} }
func (s *BlkioGroup) Apply(d *data) error { func (s *BlkioGroup) Apply(d *cgroupData) error {
dir, err := d.join("blkio") dir, err := d.join("blkio")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -78,7 +78,7 @@ func (s *BlkioGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *BlkioGroup) Remove(d *data) error { func (s *BlkioGroup) Remove(d *cgroupData) error {
return removePath(d.path("blkio")) return removePath(d.path("blkio"))
} }

View File

@ -89,9 +89,9 @@ func TestBlkioSetWeight(t *testing.T) {
"blkio.weight": strconv.Itoa(weightBefore), "blkio.weight": strconv.Itoa(weightBefore),
}) })
helper.CgroupData.c.BlkioWeight = weightAfter helper.CgroupData.config.BlkioWeight = weightAfter
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -120,9 +120,9 @@ func TestBlkioSetWeightDevice(t *testing.T) {
"blkio.weight_device": weightDeviceBefore, "blkio.weight_device": weightDeviceBefore,
}) })
helper.CgroupData.c.BlkioWeightDevice = []*configs.WeightDevice{wd} helper.CgroupData.config.BlkioWeightDevice = []*configs.WeightDevice{wd}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -157,9 +157,9 @@ func TestBlkioSetMultipleWeightDevice(t *testing.T) {
"blkio.weight_device": weightDeviceBefore, "blkio.weight_device": weightDeviceBefore,
}) })
helper.CgroupData.c.BlkioWeightDevice = []*configs.WeightDevice{wd1, wd2} helper.CgroupData.config.BlkioWeightDevice = []*configs.WeightDevice{wd1, wd2}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -529,9 +529,9 @@ func TestBlkioSetThrottleReadBpsDevice(t *testing.T) {
"blkio.throttle.read_bps_device": throttleBefore, "blkio.throttle.read_bps_device": throttleBefore,
}) })
helper.CgroupData.c.BlkioThrottleReadBpsDevice = []*configs.ThrottleDevice{td} helper.CgroupData.config.BlkioThrottleReadBpsDevice = []*configs.ThrottleDevice{td}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -559,9 +559,9 @@ func TestBlkioSetThrottleWriteBpsDevice(t *testing.T) {
"blkio.throttle.write_bps_device": throttleBefore, "blkio.throttle.write_bps_device": throttleBefore,
}) })
helper.CgroupData.c.BlkioThrottleWriteBpsDevice = []*configs.ThrottleDevice{td} helper.CgroupData.config.BlkioThrottleWriteBpsDevice = []*configs.ThrottleDevice{td}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -589,9 +589,9 @@ func TestBlkioSetThrottleReadIOpsDevice(t *testing.T) {
"blkio.throttle.read_iops_device": throttleBefore, "blkio.throttle.read_iops_device": throttleBefore,
}) })
helper.CgroupData.c.BlkioThrottleReadIOPSDevice = []*configs.ThrottleDevice{td} helper.CgroupData.config.BlkioThrottleReadIOPSDevice = []*configs.ThrottleDevice{td}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -619,9 +619,9 @@ func TestBlkioSetThrottleWriteIOpsDevice(t *testing.T) {
"blkio.throttle.write_iops_device": throttleBefore, "blkio.throttle.write_iops_device": throttleBefore,
}) })
helper.CgroupData.c.BlkioThrottleWriteIOPSDevice = []*configs.ThrottleDevice{td} helper.CgroupData.config.BlkioThrottleWriteIOPSDevice = []*configs.ThrottleDevice{td}
blkio := &BlkioGroup{} blkio := &BlkioGroup{}
if err := blkio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -19,7 +19,7 @@ func (s *CpuGroup) Name() string {
return "cpu" return "cpu"
} }
func (s *CpuGroup) Apply(d *data) error { func (s *CpuGroup) Apply(d *cgroupData) error {
// We always want to join the cpu group, to allow fair cpu scheduling // We always want to join the cpu group, to allow fair cpu scheduling
// on a container basis // on a container basis
dir, err := d.join("cpu") dir, err := d.join("cpu")
@ -27,7 +27,7 @@ func (s *CpuGroup) Apply(d *data) error {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -64,7 +64,7 @@ func (s *CpuGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *CpuGroup) Remove(d *data) error { func (s *CpuGroup) Remove(d *cgroupData) error {
return removePath(d.path("cpu")) return removePath(d.path("cpu"))
} }

View File

@ -23,9 +23,9 @@ func TestCpuSetShares(t *testing.T) {
"cpu.shares": strconv.Itoa(sharesBefore), "cpu.shares": strconv.Itoa(sharesBefore),
}) })
helper.CgroupData.c.CpuShares = sharesAfter helper.CgroupData.config.CpuShares = sharesAfter
cpu := &CpuGroup{} cpu := &CpuGroup{}
if err := cpu.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := cpu.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -61,12 +61,12 @@ func TestCpuSetBandWidth(t *testing.T) {
"cpu.rt_period_us": strconv.Itoa(rtPeriodBefore), "cpu.rt_period_us": strconv.Itoa(rtPeriodBefore),
}) })
helper.CgroupData.c.CpuQuota = quotaAfter helper.CgroupData.config.CpuQuota = quotaAfter
helper.CgroupData.c.CpuPeriod = periodAfter helper.CgroupData.config.CpuPeriod = periodAfter
helper.CgroupData.c.CpuRtRuntime = rtRuntimeAfter helper.CgroupData.config.CpuRtRuntime = rtRuntimeAfter
helper.CgroupData.c.CpuRtPeriod = rtPeriodAfter helper.CgroupData.config.CpuRtPeriod = rtPeriodAfter
cpu := &CpuGroup{} cpu := &CpuGroup{}
if err := cpu.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := cpu.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -28,7 +28,7 @@ func (s *CpuacctGroup) Name() string {
return "cpuacct" return "cpuacct"
} }
func (s *CpuacctGroup) Apply(d *data) error { func (s *CpuacctGroup) Apply(d *cgroupData) error {
// we just want to join this group even though we don't set anything // we just want to join this group even though we don't set anything
if _, err := d.join("cpuacct"); err != nil && !cgroups.IsNotFound(err) { if _, err := d.join("cpuacct"); err != nil && !cgroups.IsNotFound(err) {
return err return err
@ -41,7 +41,7 @@ func (s *CpuacctGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *CpuacctGroup) Remove(d *data) error { func (s *CpuacctGroup) Remove(d *cgroupData) error {
return removePath(d.path("cpuacct")) return removePath(d.path("cpuacct"))
} }

View File

@ -20,12 +20,12 @@ func (s *CpusetGroup) Name() string {
return "cpuset" return "cpuset"
} }
func (s *CpusetGroup) Apply(d *data) error { func (s *CpusetGroup) Apply(d *cgroupData) error {
dir, err := d.path("cpuset") dir, err := d.path("cpuset")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
return s.ApplyDir(dir, d.c, d.pid) return s.ApplyDir(dir, d.config, d.pid)
} }
func (s *CpusetGroup) Set(path string, cgroup *configs.Cgroup) error { func (s *CpusetGroup) Set(path string, cgroup *configs.Cgroup) error {
@ -42,7 +42,7 @@ func (s *CpusetGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *CpusetGroup) Remove(d *data) error { func (s *CpusetGroup) Remove(d *cgroupData) error {
return removePath(d.path("cpuset")) return removePath(d.path("cpuset"))
} }

View File

@ -19,9 +19,9 @@ func TestCpusetSetCpus(t *testing.T) {
"cpuset.cpus": cpusBefore, "cpuset.cpus": cpusBefore,
}) })
helper.CgroupData.c.CpusetCpus = cpusAfter helper.CgroupData.config.CpusetCpus = cpusAfter
cpuset := &CpusetGroup{} cpuset := &CpusetGroup{}
if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -48,9 +48,9 @@ func TestCpusetSetMems(t *testing.T) {
"cpuset.mems": memsBefore, "cpuset.mems": memsBefore,
}) })
helper.CgroupData.c.CpusetMems = memsAfter helper.CgroupData.config.CpusetMems = memsAfter
cpuset := &CpusetGroup{} cpuset := &CpusetGroup{}
if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -14,7 +14,7 @@ func (s *DevicesGroup) Name() string {
return "devices" return "devices"
} }
func (s *DevicesGroup) Apply(d *data) error { func (s *DevicesGroup) Apply(d *cgroupData) error {
dir, err := d.join("devices") dir, err := d.join("devices")
if err != nil { if err != nil {
// We will return error even it's `not found` error, devices // We will return error even it's `not found` error, devices
@ -22,7 +22,7 @@ func (s *DevicesGroup) Apply(d *data) error {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -56,7 +56,7 @@ func (s *DevicesGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *DevicesGroup) Remove(d *data) error { func (s *DevicesGroup) Remove(d *cgroupData) error {
return removePath(d.path("devices")) return removePath(d.path("devices"))
} }

View File

@ -41,10 +41,10 @@ func TestDevicesSetAllow(t *testing.T) {
"devices.deny": "a", "devices.deny": "a",
}) })
helper.CgroupData.c.AllowAllDevices = false helper.CgroupData.config.AllowAllDevices = false
helper.CgroupData.c.AllowedDevices = allowedDevices helper.CgroupData.config.AllowedDevices = allowedDevices
devices := &DevicesGroup{} devices := &DevicesGroup{}
if err := devices.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := devices.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -66,10 +66,10 @@ func TestDevicesSetDeny(t *testing.T) {
"devices.allow": "a", "devices.allow": "a",
}) })
helper.CgroupData.c.AllowAllDevices = true helper.CgroupData.config.AllowAllDevices = true
helper.CgroupData.c.DeniedDevices = deniedDevices helper.CgroupData.config.DeniedDevices = deniedDevices
devices := &DevicesGroup{} devices := &DevicesGroup{}
if err := devices.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := devices.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,13 +18,13 @@ func (s *FreezerGroup) Name() string {
return "freezer" return "freezer"
} }
func (s *FreezerGroup) Apply(d *data) error { func (s *FreezerGroup) Apply(d *cgroupData) error {
dir, err := d.join("freezer") dir, err := d.join("freezer")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -57,7 +57,7 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *FreezerGroup) Remove(d *data) error { func (s *FreezerGroup) Remove(d *cgroupData) error {
return removePath(d.path("freezer")) return removePath(d.path("freezer"))
} }

View File

@ -16,9 +16,9 @@ func TestFreezerSetState(t *testing.T) {
"freezer.state": string(configs.Frozen), "freezer.state": string(configs.Frozen),
}) })
helper.CgroupData.c.Freezer = configs.Thawed helper.CgroupData.config.Freezer = configs.Thawed
freezer := &FreezerGroup{} freezer := &FreezerGroup{}
if err := freezer.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := freezer.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -39,9 +39,9 @@ func TestFreezerSetInvalidState(t *testing.T) {
invalidArg configs.FreezerState = "Invalid" invalidArg configs.FreezerState = "Invalid"
) )
helper.CgroupData.c.Freezer = invalidArg helper.CgroupData.config.Freezer = invalidArg
freezer := &FreezerGroup{} freezer := &FreezerGroup{}
if err := freezer.Set(helper.CgroupPath, helper.CgroupData.c); err == nil { if err := freezer.Set(helper.CgroupPath, helper.CgroupData.config); err == nil {
t.Fatal("Failed to return invalid argument error") t.Fatal("Failed to return invalid argument error")
} }
} }

View File

@ -18,13 +18,13 @@ func (s *HugetlbGroup) Name() string {
return "hugetlb" return "hugetlb"
} }
func (s *HugetlbGroup) Apply(d *data) error { func (s *HugetlbGroup) Apply(d *cgroupData) error {
dir, err := d.join("hugetlb") dir, err := d.join("hugetlb")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -41,7 +41,7 @@ func (s *HugetlbGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *HugetlbGroup) Remove(d *data) error { func (s *HugetlbGroup) Remove(d *cgroupData) error {
return removePath(d.path("hugetlb")) return removePath(d.path("hugetlb"))
} }

View File

@ -40,14 +40,14 @@ func TestHugetlbSetHugetlb(t *testing.T) {
} }
for _, pageSize := range HugePageSizes { for _, pageSize := range HugePageSizes {
helper.CgroupData.c.HugetlbLimit = []*configs.HugepageLimit{ helper.CgroupData.config.HugetlbLimit = []*configs.HugepageLimit{
{ {
Pagesize: pageSize, Pagesize: pageSize,
Limit: hugetlbAfter, Limit: hugetlbAfter,
}, },
} }
hugetlb := &HugetlbGroup{} hugetlb := &HugetlbGroup{}
if err := hugetlb.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := hugetlb.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }

View File

@ -21,19 +21,19 @@ func (s *MemoryGroup) Name() string {
return "memory" return "memory"
} }
func (s *MemoryGroup) Apply(d *data) (err error) { func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
path, err := d.path("memory") path, err := d.path("memory")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if memoryAssigned(d.c) { if memoryAssigned(d.config) {
if path != "" { if path != "" {
if err := os.MkdirAll(path, 0755); err != nil { if err := os.MkdirAll(path, 0755); err != nil {
return err return err
} }
} }
if err := s.Set(path, d.c); err != nil { if err := s.Set(path, d.config); err != nil {
return err return err
} }
} }
@ -94,7 +94,7 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *MemoryGroup) Remove(d *data) error { func (s *MemoryGroup) Remove(d *cgroupData) error {
return removePath(d.path("memory")) return removePath(d.path("memory"))
} }

View File

@ -33,10 +33,10 @@ func TestMemorySetMemory(t *testing.T) {
"memory.soft_limit_in_bytes": strconv.Itoa(reservationBefore), "memory.soft_limit_in_bytes": strconv.Itoa(reservationBefore),
}) })
helper.CgroupData.c.Memory = memoryAfter helper.CgroupData.config.Memory = memoryAfter
helper.CgroupData.c.MemoryReservation = reservationAfter helper.CgroupData.config.MemoryReservation = reservationAfter
memory := &MemoryGroup{} memory := &MemoryGroup{}
if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := memory.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -70,9 +70,9 @@ func TestMemorySetMemoryswap(t *testing.T) {
"memory.memsw.limit_in_bytes": strconv.Itoa(memoryswapBefore), "memory.memsw.limit_in_bytes": strconv.Itoa(memoryswapBefore),
}) })
helper.CgroupData.c.MemorySwap = memoryswapAfter helper.CgroupData.config.MemorySwap = memoryswapAfter
memory := &MemoryGroup{} memory := &MemoryGroup{}
if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := memory.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -98,9 +98,9 @@ func TestMemorySetKernelMemory(t *testing.T) {
"memory.kmem.limit_in_bytes": strconv.Itoa(kernelMemoryBefore), "memory.kmem.limit_in_bytes": strconv.Itoa(kernelMemoryBefore),
}) })
helper.CgroupData.c.KernelMemory = kernelMemoryAfter helper.CgroupData.config.KernelMemory = kernelMemoryAfter
memory := &MemoryGroup{} memory := &MemoryGroup{}
if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := memory.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -126,9 +126,9 @@ func TestMemorySetMemorySwappinessDefault(t *testing.T) {
"memory.swappiness": strconv.Itoa(swappinessBefore), "memory.swappiness": strconv.Itoa(swappinessBefore),
}) })
helper.CgroupData.c.Memory = swappinessAfter helper.CgroupData.config.Memory = swappinessAfter
memory := &MemoryGroup{} memory := &MemoryGroup{}
if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := memory.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -279,7 +279,7 @@ func TestMemorySetOomControl(t *testing.T) {
}) })
memory := &MemoryGroup{} memory := &MemoryGroup{}
if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := memory.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -15,7 +15,7 @@ func (s *NameGroup) Name() string {
return s.GroupName return s.GroupName
} }
func (s *NameGroup) Apply(d *data) error { func (s *NameGroup) Apply(d *cgroupData) error {
return nil return nil
} }
@ -23,7 +23,7 @@ func (s *NameGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *NameGroup) Remove(d *data) error { func (s *NameGroup) Remove(d *cgroupData) error {
return nil return nil
} }

View File

@ -14,13 +14,13 @@ func (s *NetClsGroup) Name() string {
return "net_cls" return "net_cls"
} }
func (s *NetClsGroup) Apply(d *data) error { func (s *NetClsGroup) Apply(d *cgroupData) error {
dir, err := d.join("net_cls") dir, err := d.join("net_cls")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -37,7 +37,7 @@ func (s *NetClsGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *NetClsGroup) Remove(d *data) error { func (s *NetClsGroup) Remove(d *cgroupData) error {
return removePath(d.path("net_cls")) return removePath(d.path("net_cls"))
} }

View File

@ -19,9 +19,9 @@ func TestNetClsSetClassid(t *testing.T) {
"net_cls.classid": classidBefore, "net_cls.classid": classidBefore,
}) })
helper.CgroupData.c.NetClsClassid = classidAfter helper.CgroupData.config.NetClsClassid = classidAfter
netcls := &NetClsGroup{} netcls := &NetClsGroup{}
if err := netcls.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := netcls.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -14,13 +14,13 @@ func (s *NetPrioGroup) Name() string {
return "net_prio" return "net_prio"
} }
func (s *NetPrioGroup) Apply(d *data) error { func (s *NetPrioGroup) Apply(d *cgroupData) error {
dir, err := d.join("net_prio") dir, err := d.join("net_prio")
if err != nil && !cgroups.IsNotFound(err) { if err != nil && !cgroups.IsNotFound(err) {
return err return err
} }
if err := s.Set(dir, d.c); err != nil { if err := s.Set(dir, d.config); err != nil {
return err return err
} }
@ -37,7 +37,7 @@ func (s *NetPrioGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *NetPrioGroup) Remove(d *data) error { func (s *NetPrioGroup) Remove(d *cgroupData) error {
return removePath(d.path("net_prio")) return removePath(d.path("net_prio"))
} }

View File

@ -22,9 +22,9 @@ func TestNetPrioSetIfPrio(t *testing.T) {
helper := NewCgroupTestUtil("net_prio", t) helper := NewCgroupTestUtil("net_prio", t)
defer helper.cleanup() defer helper.cleanup()
helper.CgroupData.c.NetPrioIfpriomap = prioMap helper.CgroupData.config.NetPrioIfpriomap = prioMap
netPrio := &NetPrioGroup{} netPrio := &NetPrioGroup{}
if err := netPrio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { if err := netPrio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -14,7 +14,7 @@ func (s *PerfEventGroup) Name() string {
return "perf_event" return "perf_event"
} }
func (s *PerfEventGroup) Apply(d *data) error { func (s *PerfEventGroup) Apply(d *cgroupData) error {
// we just want to join this group even though we don't set anything // we just want to join this group even though we don't set anything
if _, err := d.join("perf_event"); err != nil && !cgroups.IsNotFound(err) { if _, err := d.join("perf_event"); err != nil && !cgroups.IsNotFound(err) {
return err return err
@ -26,7 +26,7 @@ func (s *PerfEventGroup) Set(path string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func (s *PerfEventGroup) Remove(d *data) error { func (s *PerfEventGroup) Remove(d *cgroupData) error {
return removePath(d.path("perf_event")) return removePath(d.path("perf_event"))
} }

View File

@ -17,8 +17,8 @@ import (
) )
type cgroupTestUtil struct { type cgroupTestUtil struct {
// data to use in tests. // cgroup data to use in tests.
CgroupData *data CgroupData *cgroupData
// Path to the mock cgroup directory. // Path to the mock cgroup directory.
CgroupPath string CgroupPath string
@ -30,8 +30,8 @@ type cgroupTestUtil struct {
// Creates a new test util for the specified subsystem // Creates a new test util for the specified subsystem
func NewCgroupTestUtil(subsystem string, t *testing.T) *cgroupTestUtil { func NewCgroupTestUtil(subsystem string, t *testing.T) *cgroupTestUtil {
d := &data{ d := &cgroupData{
c: &configs.Cgroup{}, config: &configs.Cgroup{},
} }
tempDir, err := ioutil.TempDir("", "cgroup_test") tempDir, err := ioutil.TempDir("", "cgroup_test")
if err != nil { if err != nil {