diff --git a/daemon/execdriver/driver_unix.go b/daemon/execdriver/driver_unix.go index 168b818cc8..eedd8ac820 100644 --- a/daemon/execdriver/driver_unix.go +++ b/daemon/execdriver/driver_unix.go @@ -139,7 +139,7 @@ func InitContainer(c *Command) *configs.Config { container.Hostname = getEnv("HOSTNAME", c.ProcessConfig.Env) container.Cgroups.Name = c.ID - container.Cgroups.AllowedDevices = c.AllowedDevices + container.Cgroups.Resources.AllowedDevices = c.AllowedDevices container.Devices = c.AutoCreatedDevices container.Rootfs = c.Rootfs container.Readonlyfs = c.ReadonlyRootfs @@ -170,23 +170,23 @@ func getEnv(key string, env []string) string { // SetupCgroups setups cgroup resources for a container. func SetupCgroups(container *configs.Config, c *Command) error { if c.Resources != nil { - container.Cgroups.CpuShares = c.Resources.CPUShares - container.Cgroups.Memory = c.Resources.Memory - container.Cgroups.MemoryReservation = c.Resources.MemoryReservation - container.Cgroups.MemorySwap = c.Resources.MemorySwap - container.Cgroups.KernelMemory = c.Resources.KernelMemory - container.Cgroups.CpusetCpus = c.Resources.CpusetCpus - container.Cgroups.CpusetMems = c.Resources.CpusetMems - container.Cgroups.CpuPeriod = c.Resources.CPUPeriod - container.Cgroups.CpuQuota = c.Resources.CPUQuota - container.Cgroups.BlkioWeight = c.Resources.BlkioWeight - container.Cgroups.BlkioWeightDevice = c.Resources.BlkioWeightDevice - container.Cgroups.BlkioThrottleReadBpsDevice = c.Resources.BlkioThrottleReadBpsDevice - container.Cgroups.BlkioThrottleWriteBpsDevice = c.Resources.BlkioThrottleWriteBpsDevice - container.Cgroups.BlkioThrottleReadIOPSDevice = c.Resources.BlkioThrottleReadIOpsDevice - container.Cgroups.BlkioThrottleWriteIOPSDevice = c.Resources.BlkioThrottleWriteIOpsDevice - container.Cgroups.OomKillDisable = c.Resources.OomKillDisable - container.Cgroups.MemorySwappiness = c.Resources.MemorySwappiness + container.Cgroups.Resources.CpuShares = c.Resources.CPUShares + container.Cgroups.Resources.Memory = c.Resources.Memory + container.Cgroups.Resources.MemoryReservation = c.Resources.MemoryReservation + container.Cgroups.Resources.MemorySwap = c.Resources.MemorySwap + container.Cgroups.Resources.KernelMemory = c.Resources.KernelMemory + container.Cgroups.Resources.CpusetCpus = c.Resources.CpusetCpus + container.Cgroups.Resources.CpusetMems = c.Resources.CpusetMems + container.Cgroups.Resources.CpuPeriod = c.Resources.CPUPeriod + container.Cgroups.Resources.CpuQuota = c.Resources.CPUQuota + container.Cgroups.Resources.BlkioWeight = c.Resources.BlkioWeight + container.Cgroups.Resources.BlkioWeightDevice = c.Resources.BlkioWeightDevice + container.Cgroups.Resources.BlkioThrottleReadBpsDevice = c.Resources.BlkioThrottleReadBpsDevice + container.Cgroups.Resources.BlkioThrottleWriteBpsDevice = c.Resources.BlkioThrottleWriteBpsDevice + container.Cgroups.Resources.BlkioThrottleReadIOPSDevice = c.Resources.BlkioThrottleReadIOpsDevice + container.Cgroups.Resources.BlkioThrottleWriteIOPSDevice = c.Resources.BlkioThrottleWriteIOpsDevice + container.Cgroups.Resources.OomKillDisable = c.Resources.OomKillDisable + container.Cgroups.Resources.MemorySwappiness = c.Resources.MemorySwappiness } return nil diff --git a/daemon/execdriver/native/create.go b/daemon/execdriver/native/create.go index 16ad4508d7..4f97ed93f8 100644 --- a/daemon/execdriver/native/create.go +++ b/daemon/execdriver/native/create.go @@ -251,7 +251,7 @@ func (d *Driver) setupRemappedRoot(container *configs.Config, c *execdriver.Comm func (d *Driver) setPrivileged(container *configs.Config) (err error) { container.Capabilities = execdriver.GetAllCapabilities() - container.Cgroups.AllowAllDevices = true + container.Cgroups.Resources.AllowAllDevices = true hostDevices, err := devices.HostDevices() if err != nil { diff --git a/daemon/execdriver/native/driver.go b/daemon/execdriver/native/driver.go index e85c4179cf..c011bba861 100644 --- a/daemon/execdriver/native/driver.go +++ b/daemon/execdriver/native/driver.go @@ -385,7 +385,7 @@ func (d *Driver) Stats(id string) (*execdriver.ResourceStats, error) { if err != nil { return nil, err } - memoryLimit := c.Config().Cgroups.Memory + memoryLimit := c.Config().Cgroups.Resources.Memory // if the container does not have any memory limit specified set the // limit to the machines memory if memoryLimit == 0 { diff --git a/daemon/execdriver/native/template/default_template_linux.go b/daemon/execdriver/native/template/default_template_linux.go index d59e3181d8..8caf34fa4e 100644 --- a/daemon/execdriver/native/template/default_template_linux.go +++ b/daemon/execdriver/native/template/default_template_linux.go @@ -40,9 +40,11 @@ func New() *configs.Config { {Type: "NEWUSER"}, }), Cgroups: &configs.Cgroup{ - Parent: "/docker", - AllowAllDevices: false, - MemorySwappiness: -1, + Parent: "/docker", + Resources: &configs.Resources{ + AllowAllDevices: false, + MemorySwappiness: -1, + }, }, Mounts: []*configs.Mount{ { diff --git a/hack/vendor.sh b/hack/vendor.sh index d99f9a4a48..9a4a612cdf 100755 --- a/hack/vendor.sh +++ b/hack/vendor.sh @@ -51,7 +51,7 @@ clone git github.com/miekg/pkcs11 80f102b5cac759de406949c47f0928b99bd64cdf clone git github.com/jfrazelle/go v1.5.1-1 clone git github.com/agl/ed25519 d2b94fd789ea21d12fac1a4443dd3a3f79cda72c -clone git github.com/opencontainers/runc ba1568de399395774ad84c2ace65937814c542ed # libcontainer +clone git github.com/opencontainers/runc d97d5e8b007e4657316eed76ea30bc0f690230cf # libcontainer clone git github.com/opencontainers/specs 46d949ea81080c5f60dfb72ee91468b1e9fb2998 # specs clone git github.com/seccomp/libseccomp-golang 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1 # libcontainer deps (see src/github.com/opencontainers/runc/Godeps/Godeps.json) diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go index 68ebcfefbf..0c4d207ee7 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go @@ -137,7 +137,7 @@ func (m *Manager) Apply(pid int) (err error) { m.Paths = paths if paths["cpu"] != "" { - if err := CheckCpushares(paths["cpu"], c.CpuShares); err != nil { + if err := CheckCpushares(paths["cpu"], c.Resources.CpuShares); err != nil { return err } } @@ -202,15 +202,15 @@ func (m *Manager) Freeze(state configs.FreezerState) error { if err != nil { return err } - prevState := m.Cgroups.Freezer - m.Cgroups.Freezer = state + prevState := m.Cgroups.Resources.Freezer + m.Cgroups.Resources.Freezer = state freezer, err := subsystems.Get("freezer") if err != nil { return err } err = freezer.Set(dir, m.Cgroups) if err != nil { - m.Cgroups.Freezer = prevState + m.Cgroups.Resources.Freezer = prevState return err } return nil diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/blkio.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/blkio.go index eddba0bf8b..518cb63f63 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/blkio.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/blkio.go @@ -35,18 +35,18 @@ func (s *BlkioGroup) Apply(d *cgroupData) error { } func (s *BlkioGroup) Set(path string, cgroup *configs.Cgroup) error { - if cgroup.BlkioWeight != 0 { - if err := writeFile(path, "blkio.weight", strconv.FormatUint(uint64(cgroup.BlkioWeight), 10)); err != nil { + if cgroup.Resources.BlkioWeight != 0 { + if err := writeFile(path, "blkio.weight", strconv.FormatUint(uint64(cgroup.Resources.BlkioWeight), 10)); err != nil { return err } } - if cgroup.BlkioLeafWeight != 0 { - if err := writeFile(path, "blkio.leaf_weight", strconv.FormatUint(uint64(cgroup.BlkioLeafWeight), 10)); err != nil { + if cgroup.Resources.BlkioLeafWeight != 0 { + if err := writeFile(path, "blkio.leaf_weight", strconv.FormatUint(uint64(cgroup.Resources.BlkioLeafWeight), 10)); err != nil { return err } } - for _, wd := range cgroup.BlkioWeightDevice { + for _, wd := range cgroup.Resources.BlkioWeightDevice { if err := writeFile(path, "blkio.weight_device", wd.WeightString()); err != nil { return err } @@ -54,22 +54,22 @@ func (s *BlkioGroup) Set(path string, cgroup *configs.Cgroup) error { return err } } - for _, td := range cgroup.BlkioThrottleReadBpsDevice { + for _, td := range cgroup.Resources.BlkioThrottleReadBpsDevice { if err := writeFile(path, "blkio.throttle.read_bps_device", td.String()); err != nil { return err } } - for _, td := range cgroup.BlkioThrottleWriteBpsDevice { + for _, td := range cgroup.Resources.BlkioThrottleWriteBpsDevice { if err := writeFile(path, "blkio.throttle.write_bps_device", td.String()); err != nil { return err } } - for _, td := range cgroup.BlkioThrottleReadIOPSDevice { + for _, td := range cgroup.Resources.BlkioThrottleReadIOPSDevice { if err := writeFile(path, "blkio.throttle.read_iops_device", td.String()); err != nil { return err } } - for _, td := range cgroup.BlkioThrottleWriteIOPSDevice { + for _, td := range cgroup.Resources.BlkioThrottleWriteIOPSDevice { if err := writeFile(path, "blkio.throttle.write_iops_device", td.String()); err != nil { return err } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go index 762a68fe80..ad5f427ec2 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go @@ -35,28 +35,28 @@ func (s *CpuGroup) Apply(d *cgroupData) error { } func (s *CpuGroup) Set(path string, cgroup *configs.Cgroup) error { - if cgroup.CpuShares != 0 { - if err := writeFile(path, "cpu.shares", strconv.FormatInt(cgroup.CpuShares, 10)); err != nil { + if cgroup.Resources.CpuShares != 0 { + if err := writeFile(path, "cpu.shares", strconv.FormatInt(cgroup.Resources.CpuShares, 10)); err != nil { return err } } - if cgroup.CpuPeriod != 0 { - if err := writeFile(path, "cpu.cfs_period_us", strconv.FormatInt(cgroup.CpuPeriod, 10)); err != nil { + if cgroup.Resources.CpuPeriod != 0 { + if err := writeFile(path, "cpu.cfs_period_us", strconv.FormatInt(cgroup.Resources.CpuPeriod, 10)); err != nil { return err } } - if cgroup.CpuQuota != 0 { - if err := writeFile(path, "cpu.cfs_quota_us", strconv.FormatInt(cgroup.CpuQuota, 10)); err != nil { + if cgroup.Resources.CpuQuota != 0 { + if err := writeFile(path, "cpu.cfs_quota_us", strconv.FormatInt(cgroup.Resources.CpuQuota, 10)); err != nil { return err } } - if cgroup.CpuRtPeriod != 0 { - if err := writeFile(path, "cpu.rt_period_us", strconv.FormatInt(cgroup.CpuRtPeriod, 10)); err != nil { + if cgroup.Resources.CpuRtPeriod != 0 { + if err := writeFile(path, "cpu.rt_period_us", strconv.FormatInt(cgroup.Resources.CpuRtPeriod, 10)); err != nil { return err } } - if cgroup.CpuRtRuntime != 0 { - if err := writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(cgroup.CpuRtRuntime, 10)); err != nil { + if cgroup.Resources.CpuRtRuntime != 0 { + if err := writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(cgroup.Resources.CpuRtRuntime, 10)); err != nil { return err } } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpuset.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpuset.go index 088a665b97..b7632108f8 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpuset.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpuset.go @@ -29,13 +29,13 @@ func (s *CpusetGroup) Apply(d *cgroupData) error { } func (s *CpusetGroup) Set(path string, cgroup *configs.Cgroup) error { - if cgroup.CpusetCpus != "" { - if err := writeFile(path, "cpuset.cpus", cgroup.CpusetCpus); err != nil { + if cgroup.Resources.CpusetCpus != "" { + if err := writeFile(path, "cpuset.cpus", cgroup.Resources.CpusetCpus); err != nil { return err } } - if cgroup.CpusetMems != "" { - if err := writeFile(path, "cpuset.mems", cgroup.CpusetMems); err != nil { + if cgroup.Resources.CpusetMems != "" { + if err := writeFile(path, "cpuset.mems", cgroup.Resources.CpusetMems); err != nil { return err } } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/devices.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/devices.go index 1e39618a46..a9883eb4bb 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/devices.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/devices.go @@ -30,12 +30,12 @@ func (s *DevicesGroup) Apply(d *cgroupData) error { } func (s *DevicesGroup) Set(path string, cgroup *configs.Cgroup) error { - if !cgroup.AllowAllDevices { + if !cgroup.Resources.AllowAllDevices { if err := writeFile(path, "devices.deny", "a"); err != nil { return err } - for _, dev := range cgroup.AllowedDevices { + for _, dev := range cgroup.Resources.AllowedDevices { if err := writeFile(path, "devices.allow", dev.CgroupString()); err != nil { return err } @@ -47,7 +47,7 @@ func (s *DevicesGroup) Set(path string, cgroup *configs.Cgroup) error { return err } - for _, dev := range cgroup.DeniedDevices { + for _, dev := range cgroup.Resources.DeniedDevices { if err := writeFile(path, "devices.deny", dev.CgroupString()); err != nil { return err } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/freezer.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/freezer.go index 8960ec789c..6aaad4e009 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/freezer.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/freezer.go @@ -32,9 +32,9 @@ func (s *FreezerGroup) Apply(d *cgroupData) error { } func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error { - switch cgroup.Freezer { + switch cgroup.Resources.Freezer { case configs.Frozen, configs.Thawed: - if err := writeFile(path, "freezer.state", string(cgroup.Freezer)); err != nil { + if err := writeFile(path, "freezer.state", string(cgroup.Resources.Freezer)); err != nil { return err } @@ -43,7 +43,7 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error { if err != nil { return err } - if strings.TrimSpace(state) == string(cgroup.Freezer) { + if strings.TrimSpace(state) == string(cgroup.Resources.Freezer) { break } time.Sleep(1 * time.Millisecond) @@ -51,7 +51,7 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error { case configs.Undefined: return nil default: - return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Freezer)) + return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Resources.Freezer)) } return nil diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/hugetlb.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/hugetlb.go index b11365370f..ca106da44d 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/hugetlb.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/hugetlb.go @@ -32,7 +32,7 @@ func (s *HugetlbGroup) Apply(d *cgroupData) error { } func (s *HugetlbGroup) Set(path string, cgroup *configs.Cgroup) error { - for _, hugetlb := range cgroup.HugetlbLimit { + for _, hugetlb := range cgroup.Resources.HugetlbLimit { if err := writeFile(path, strings.Join([]string{"hugetlb", hugetlb.Pagesize, "limit_in_bytes"}, "."), strconv.FormatUint(hugetlb.Limit, 10)); err != nil { return err } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/memory.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/memory.go index e5ffde4b6d..6b9687ca2f 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/memory.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/memory.go @@ -55,40 +55,40 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) { } func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error { - if cgroup.Memory != 0 { - if err := writeFile(path, "memory.limit_in_bytes", strconv.FormatInt(cgroup.Memory, 10)); err != nil { + if cgroup.Resources.Memory != 0 { + if err := writeFile(path, "memory.limit_in_bytes", strconv.FormatInt(cgroup.Resources.Memory, 10)); err != nil { return err } } - if cgroup.MemoryReservation != 0 { - if err := writeFile(path, "memory.soft_limit_in_bytes", strconv.FormatInt(cgroup.MemoryReservation, 10)); err != nil { + if cgroup.Resources.MemoryReservation != 0 { + if err := writeFile(path, "memory.soft_limit_in_bytes", strconv.FormatInt(cgroup.Resources.MemoryReservation, 10)); err != nil { return err } } - if cgroup.MemorySwap > 0 { - if err := writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(cgroup.MemorySwap, 10)); err != nil { + if cgroup.Resources.MemorySwap > 0 { + if err := writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(cgroup.Resources.MemorySwap, 10)); err != nil { return err } } - if cgroup.KernelMemory > 0 { - if err := writeFile(path, "memory.kmem.limit_in_bytes", strconv.FormatInt(cgroup.KernelMemory, 10)); err != nil { + if cgroup.Resources.KernelMemory > 0 { + if err := writeFile(path, "memory.kmem.limit_in_bytes", strconv.FormatInt(cgroup.Resources.KernelMemory, 10)); err != nil { return err } } - if cgroup.OomKillDisable { + if cgroup.Resources.OomKillDisable { if err := writeFile(path, "memory.oom_control", "1"); err != nil { return err } } - if cgroup.MemorySwappiness >= 0 && cgroup.MemorySwappiness <= 100 { - if err := writeFile(path, "memory.swappiness", strconv.FormatInt(cgroup.MemorySwappiness, 10)); err != nil { + if cgroup.Resources.MemorySwappiness >= 0 && cgroup.Resources.MemorySwappiness <= 100 { + if err := writeFile(path, "memory.swappiness", strconv.FormatInt(cgroup.Resources.MemorySwappiness, 10)); err != nil { return err } - } else if cgroup.MemorySwappiness == -1 { + } else if cgroup.Resources.MemorySwappiness == -1 { return nil } else { - return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", cgroup.MemorySwappiness) + return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", cgroup.Resources.MemorySwappiness) } return nil @@ -139,12 +139,12 @@ func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error { } func memoryAssigned(cgroup *configs.Cgroup) bool { - return cgroup.Memory != 0 || - cgroup.MemoryReservation != 0 || - cgroup.MemorySwap > 0 || - cgroup.KernelMemory > 0 || - cgroup.OomKillDisable || - cgroup.MemorySwappiness != -1 + return cgroup.Resources.Memory != 0 || + cgroup.Resources.MemoryReservation != 0 || + cgroup.Resources.MemorySwap > 0 || + cgroup.Resources.KernelMemory > 0 || + cgroup.Resources.OomKillDisable || + cgroup.Resources.MemorySwappiness != -1 } func getMemoryData(path, name string) (cgroups.MemoryData, error) { diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_cls.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_cls.go index b09a1760e4..6382373127 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_cls.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_cls.go @@ -28,8 +28,8 @@ func (s *NetClsGroup) Apply(d *cgroupData) error { } func (s *NetClsGroup) Set(path string, cgroup *configs.Cgroup) error { - if cgroup.NetClsClassid != "" { - if err := writeFile(path, "net_cls.classid", cgroup.NetClsClassid); err != nil { + if cgroup.Resources.NetClsClassid != "" { + if err := writeFile(path, "net_cls.classid", cgroup.Resources.NetClsClassid); err != nil { return err } } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_prio.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_prio.go index 59117cad91..0dabaae729 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_prio.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/fs/net_prio.go @@ -28,7 +28,7 @@ func (s *NetPrioGroup) Apply(d *cgroupData) error { } func (s *NetPrioGroup) Set(path string, cgroup *configs.Cgroup) error { - for _, prioMap := range cgroup.NetPrioIfpriomap { + for _, prioMap := range cgroup.Resources.NetPrioIfpriomap { if err := writeFile(path, "net_prio.ifpriomap", prioMap.CgroupString()); err != nil { return err } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/apply_systemd.go b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/apply_systemd.go index 41b6fbcd8a..93300cda38 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/apply_systemd.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/apply_systemd.go @@ -189,26 +189,26 @@ func (m *Manager) Apply(pid int) error { newProp("DefaultDependencies", false)) } - if c.Memory != 0 { + if c.Resources.Memory != 0 { properties = append(properties, - newProp("MemoryLimit", uint64(c.Memory))) + newProp("MemoryLimit", uint64(c.Resources.Memory))) } - if c.CpuShares != 0 { + if c.Resources.CpuShares != 0 { properties = append(properties, - newProp("CPUShares", uint64(c.CpuShares))) + newProp("CPUShares", uint64(c.Resources.CpuShares))) } - if c.BlkioWeight != 0 { + if c.Resources.BlkioWeight != 0 { properties = append(properties, - newProp("BlockIOWeight", uint64(c.BlkioWeight))) + newProp("BlockIOWeight", uint64(c.Resources.BlkioWeight))) } // We need to set kernel memory before processes join cgroup because // kmem.limit_in_bytes can only be set when the cgroup is empty. // And swap memory limit needs to be set after memory limit, only // memory limit is handled by systemd, so it's kind of ugly here. - if c.KernelMemory > 0 { + if c.Resources.KernelMemory > 0 { if err := setKernelMemory(c); err != nil { return err } @@ -279,7 +279,7 @@ func (m *Manager) Apply(pid int) error { m.Paths = paths if paths["cpu"] != "" { - if err := fs.CheckCpushares(paths["cpu"], c.CpuShares); err != nil { + if err := fs.CheckCpushares(paths["cpu"], c.Resources.CpuShares); err != nil { return err } } @@ -334,23 +334,23 @@ func joinCpu(c *configs.Cgroup, pid int) error { if err != nil && !cgroups.IsNotFound(err) { return err } - if c.CpuQuota != 0 { - if err = writeFile(path, "cpu.cfs_quota_us", strconv.FormatInt(c.CpuQuota, 10)); err != nil { + if c.Resources.CpuQuota != 0 { + if err = writeFile(path, "cpu.cfs_quota_us", strconv.FormatInt(c.Resources.CpuQuota, 10)); err != nil { return err } } - if c.CpuPeriod != 0 { - if err = writeFile(path, "cpu.cfs_period_us", strconv.FormatInt(c.CpuPeriod, 10)); err != nil { + if c.Resources.CpuPeriod != 0 { + if err = writeFile(path, "cpu.cfs_period_us", strconv.FormatInt(c.Resources.CpuPeriod, 10)); err != nil { return err } } - if c.CpuRtPeriod != 0 { - if err = writeFile(path, "cpu.rt_period_us", strconv.FormatInt(c.CpuRtPeriod, 10)); err != nil { + if c.Resources.CpuRtPeriod != 0 { + if err = writeFile(path, "cpu.rt_period_us", strconv.FormatInt(c.Resources.CpuRtPeriod, 10)); err != nil { return err } } - if c.CpuRtRuntime != 0 { - if err = writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(c.CpuRtRuntime, 10)); err != nil { + if c.Resources.CpuRtRuntime != 0 { + if err = writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(c.Resources.CpuRtRuntime, 10)); err != nil { return err } } @@ -418,15 +418,15 @@ func (m *Manager) Freeze(state configs.FreezerState) error { if err != nil { return err } - prevState := m.Cgroups.Freezer - m.Cgroups.Freezer = state + prevState := m.Cgroups.Resources.Freezer + m.Cgroups.Resources.Freezer = state freezer, err := subsystems.Get("freezer") if err != nil { return err } err = freezer.Set(path, m.Cgroups) if err != nil { - m.Cgroups.Freezer = prevState + m.Cgroups.Resources.Freezer = prevState return err } return nil @@ -510,8 +510,8 @@ func setKernelMemory(c *configs.Cgroup) error { return err } - if c.KernelMemory > 0 { - err = writeFile(path, "memory.kmem.limit_in_bytes", strconv.FormatInt(c.KernelMemory, 10)) + if c.Resources.KernelMemory > 0 { + err = writeFile(path, "memory.kmem.limit_in_bytes", strconv.FormatInt(c.Resources.KernelMemory, 10)) if err != nil { return err } @@ -527,33 +527,33 @@ func joinMemory(c *configs.Cgroup, pid int) error { } // -1 disables memoryswap - if c.MemorySwap > 0 { - err = writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(c.MemorySwap, 10)) + if c.Resources.MemorySwap > 0 { + err = writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(c.Resources.MemorySwap, 10)) if err != nil { return err } } - if c.MemoryReservation > 0 { - err = writeFile(path, "memory.soft_limit_in_bytes", strconv.FormatInt(c.MemoryReservation, 10)) + if c.Resources.MemoryReservation > 0 { + err = writeFile(path, "memory.soft_limit_in_bytes", strconv.FormatInt(c.Resources.MemoryReservation, 10)) if err != nil { return err } } - if c.OomKillDisable { + if c.Resources.OomKillDisable { if err := writeFile(path, "memory.oom_control", "1"); err != nil { return err } } - if c.MemorySwappiness >= 0 && c.MemorySwappiness <= 100 { - err = writeFile(path, "memory.swappiness", strconv.FormatInt(c.MemorySwappiness, 10)) + if c.Resources.MemorySwappiness >= 0 && c.Resources.MemorySwappiness <= 100 { + err = writeFile(path, "memory.swappiness", strconv.FormatInt(c.Resources.MemorySwappiness, 10)) if err != nil { return err } - } else if c.MemorySwappiness == -1 { + } else if c.Resources.MemorySwappiness == -1 { return nil } else { - return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", c.MemorySwappiness) + return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", c.Resources.MemorySwappiness) } return nil @@ -582,12 +582,12 @@ func joinBlkio(c *configs.Cgroup, pid int) error { return err } // systemd doesn't directly support this in the dbus properties - if c.BlkioLeafWeight != 0 { - if err := writeFile(path, "blkio.leaf_weight", strconv.FormatUint(uint64(c.BlkioLeafWeight), 10)); err != nil { + if c.Resources.BlkioLeafWeight != 0 { + if err := writeFile(path, "blkio.leaf_weight", strconv.FormatUint(uint64(c.Resources.BlkioLeafWeight), 10)); err != nil { return err } } - for _, wd := range c.BlkioWeightDevice { + for _, wd := range c.Resources.BlkioWeightDevice { if err := writeFile(path, "blkio.weight_device", wd.WeightString()); err != nil { return err } @@ -595,22 +595,22 @@ func joinBlkio(c *configs.Cgroup, pid int) error { return err } } - for _, td := range c.BlkioThrottleReadBpsDevice { + for _, td := range c.Resources.BlkioThrottleReadBpsDevice { if err := writeFile(path, "blkio.throttle.read_bps_device", td.String()); err != nil { return err } } - for _, td := range c.BlkioThrottleWriteBpsDevice { + for _, td := range c.Resources.BlkioThrottleWriteBpsDevice { if err := writeFile(path, "blkio.throttle.write_bps_device", td.String()); err != nil { return err } } - for _, td := range c.BlkioThrottleReadIOPSDevice { + for _, td := range c.Resources.BlkioThrottleReadIOPSDevice { if err := writeFile(path, "blkio.throttle.read_iops_device", td.String()); err != nil { return err } } - for _, td := range c.BlkioThrottleWriteIOPSDevice { + for _, td := range c.Resources.BlkioThrottleWriteIOPSDevice { if err := writeFile(path, "blkio.throttle.write_iops_device", td.String()); err != nil { return err } diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/configs/cgroup_unix.go b/vendor/src/github.com/opencontainers/runc/libcontainer/configs/cgroup_unix.go index f256fa2471..ef781324fb 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/configs/cgroup_unix.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/configs/cgroup_unix.go @@ -16,6 +16,14 @@ type Cgroup struct { // name of parent cgroup or slice Parent string `json:"parent"` + // ScopePrefix decribes prefix for the scope name + ScopePrefix string `json:"scope_prefix"` + + // Resources contains various cgroups settings to apply + Resources *Resources `json:"resources"` +} + +type Resources struct { // If this is true allow access to any kind of device within the container. If false, allow access only to devices explicitly listed in the allowed_devices list. AllowAllDevices bool `json:"allow_all_devices"` @@ -83,9 +91,6 @@ type Cgroup struct { // Hugetlb limit (in bytes) HugetlbLimit []*HugepageLimit `json:"hugetlb_limit"` - // ScopePrefix decribes prefix for the scope name - ScopePrefix string `json:"scope_prefix"` - // Whether to disable OOM Killer OomKillDisable bool `json:"oom_kill_disable"` diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/container_linux.go b/vendor/src/github.com/opencontainers/runc/libcontainer/container_linux.go index 82476ed99a..de98e97ca2 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/container_linux.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/container_linux.go @@ -985,7 +985,7 @@ func (c *linuxContainer) currentStatus() (Status, error) { } return 0, newSystemError(err) } - if c.config.Cgroups != nil && c.config.Cgroups.Freezer == configs.Frozen { + if c.config.Cgroups != nil && c.config.Cgroups.Resources != nil && c.config.Cgroups.Resources.Freezer == configs.Frozen { return Paused, nil } return Running, nil diff --git a/vendor/src/github.com/opencontainers/runc/libcontainer/message_linux.go b/vendor/src/github.com/opencontainers/runc/libcontainer/message_linux.go index 0e95e3b0ad..0c3301f2bb 100644 --- a/vendor/src/github.com/opencontainers/runc/libcontainer/message_linux.go +++ b/vendor/src/github.com/opencontainers/runc/libcontainer/message_linux.go @@ -14,6 +14,8 @@ const ( InitMsg uint16 = 62000 PidAttr uint16 = 27281 ConsolePathAttr uint16 = 27282 + // When syscall.NLA_HDRLEN is in gccgo, take this out. + syscall_NLA_HDRLEN = (syscall.SizeofNlAttr + syscall.NLA_ALIGNTO - 1) & ^(syscall.NLA_ALIGNTO - 1) ) type Int32msg struct { @@ -34,7 +36,7 @@ func (msg *Int32msg) Serialize() []byte { } func (msg *Int32msg) Len() int { - return syscall.NLA_HDRLEN + 4 + return syscall_NLA_HDRLEN + 4 } // bytemsg has the following representation @@ -56,5 +58,5 @@ func (msg *Bytemsg) Serialize() []byte { } func (msg *Bytemsg) Len() int { - return syscall.NLA_HDRLEN + len(msg.Value) + 1 // null-terminated + return syscall_NLA_HDRLEN + len(msg.Value) + 1 // null-terminated }