From b1220a763c5046efe8caa3e245c84633a29c3684 Mon Sep 17 00:00:00 2001 From: John Howard Date: Mon, 5 Oct 2015 10:11:10 -0700 Subject: [PATCH] Windows: Refactor resources structure Signed-off-by: John Howard --- daemon/container_unix.go | 28 ++++++++++--------- daemon/container_windows.go | 4 ++- daemon/execdriver/driver.go | 26 +++++------------ daemon/execdriver/driver_unix.go | 19 +++++++++++++ daemon/execdriver/driver_windows.go | 8 ++++++ .../execdriver/lxc/lxc_template_unit_test.go | 6 ++-- daemon/execdriver/windows/checkoptions.go | 5 ---- 7 files changed, 56 insertions(+), 40 deletions(-) diff --git a/daemon/container_unix.go b/daemon/container_unix.go index 89dbcfad4c..3b22081e50 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -279,19 +279,21 @@ func populateCommand(c *Container, env []string) error { } resources := &execdriver.Resources{ - Memory: c.hostConfig.Memory, - MemorySwap: c.hostConfig.MemorySwap, - MemoryReservation: c.hostConfig.MemoryReservation, - KernelMemory: c.hostConfig.KernelMemory, - CPUShares: c.hostConfig.CPUShares, - CpusetCpus: c.hostConfig.CpusetCpus, - CpusetMems: c.hostConfig.CpusetMems, - CPUPeriod: c.hostConfig.CPUPeriod, - CPUQuota: c.hostConfig.CPUQuota, - BlkioWeight: c.hostConfig.BlkioWeight, - Rlimits: rlimits, - OomKillDisable: c.hostConfig.OomKillDisable, - MemorySwappiness: -1, + CommonResources: execdriver.CommonResources{ + Memory: c.hostConfig.Memory, + MemoryReservation: c.hostConfig.MemoryReservation, + CPUShares: c.hostConfig.CPUShares, + BlkioWeight: c.hostConfig.BlkioWeight, + }, + MemorySwap: c.hostConfig.MemorySwap, + KernelMemory: c.hostConfig.KernelMemory, + CpusetCpus: c.hostConfig.CpusetCpus, + CpusetMems: c.hostConfig.CpusetMems, + CPUPeriod: c.hostConfig.CPUPeriod, + CPUQuota: c.hostConfig.CPUQuota, + Rlimits: rlimits, + OomKillDisable: c.hostConfig.OomKillDisable, + MemorySwappiness: -1, } if c.hostConfig.MemorySwappiness != nil { diff --git a/daemon/container_windows.go b/daemon/container_windows.go index 178521087a..5d62a96d68 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -86,7 +86,9 @@ func populateCommand(c *Container, env []string) error { // TODO Windows. More resource controls to be implemented later. resources := &execdriver.Resources{ - CPUShares: c.hostConfig.CPUShares, + CommonResources: execdriver.CommonResources{ + CPUShares: c.hostConfig.CPUShares, + }, } // TODO Windows. Further refactoring required (privileged/user) diff --git a/daemon/execdriver/driver.go b/daemon/execdriver/driver.go index 462666b392..75d266fcf1 100644 --- a/daemon/execdriver/driver.go +++ b/daemon/execdriver/driver.go @@ -7,8 +7,6 @@ import ( "time" "github.com/docker/docker/pkg/idtools" - // TODO Windows: Factor out ulimit - "github.com/docker/docker/pkg/ulimit" "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/configs" ) @@ -138,23 +136,13 @@ type UTS struct { HostUTS bool `json:"host_uts"` } -// Resources contains all resource configs for a driver. -// Currently these are all for cgroup configs. -// TODO Windows: Factor out ulimit.Rlimit -type Resources struct { - Memory int64 `json:"memory"` - MemorySwap int64 `json:"memory_swap"` - MemoryReservation int64 `json:"memory_reservation"` - KernelMemory int64 `json:"kernel_memory"` - CPUShares int64 `json:"cpu_shares"` - CpusetCpus string `json:"cpuset_cpus"` - CpusetMems string `json:"cpuset_mems"` - CPUPeriod int64 `json:"cpu_period"` - CPUQuota int64 `json:"cpu_quota"` - BlkioWeight uint16 `json:"blkio_weight"` - Rlimits []*ulimit.Rlimit `json:"rlimits"` - OomKillDisable bool `json:"oom_kill_disable"` - MemorySwappiness int64 `json:"memory_swappiness"` +// CommonResources contains the resource configs for a driver that are +// common across platforms. +type CommonResources struct { + Memory int64 `json:"memory"` + MemoryReservation int64 `json:"memory_reservation"` + CPUShares int64 `json:"cpu_shares"` + BlkioWeight uint16 `json:"blkio_weight"` } // ResourceStats contains information about resource usage by a container. diff --git a/daemon/execdriver/driver_unix.go b/daemon/execdriver/driver_unix.go index 2ebf95fc84..dfca4a710c 100644 --- a/daemon/execdriver/driver_unix.go +++ b/daemon/execdriver/driver_unix.go @@ -13,6 +13,7 @@ import ( "github.com/docker/docker/daemon/execdriver/native/template" "github.com/docker/docker/pkg/mount" + "github.com/docker/docker/pkg/ulimit" "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/cgroups/fs" "github.com/opencontainers/runc/libcontainer/configs" @@ -27,6 +28,24 @@ type Mount struct { Slave bool `json:"slave"` } +// Resources contains all resource configs for a driver. +// Currently these are all for cgroup configs. +type Resources struct { + CommonResources + + // Fields below here are platform specific + + MemorySwap int64 `json:"memory_swap"` + KernelMemory int64 `json:"kernel_memory"` + CPUQuota int64 `json:"cpu_quota"` + CpusetCpus string `json:"cpuset_cpus"` + CpusetMems string `json:"cpuset_mems"` + CPUPeriod int64 `json:"cpu_period"` + Rlimits []*ulimit.Rlimit `json:"rlimits"` + OomKillDisable bool `json:"oom_kill_disable"` + MemorySwappiness int64 `json:"memory_swappiness"` +} + // Network settings of the container type Network struct { Mtu int `json:"mtu"` diff --git a/daemon/execdriver/driver_windows.go b/daemon/execdriver/driver_windows.go index b422bcd79a..fee843fa39 100644 --- a/daemon/execdriver/driver_windows.go +++ b/daemon/execdriver/driver_windows.go @@ -9,6 +9,14 @@ type Mount struct { Writable bool `json:"writable"` } +// Resources contains all resource configs for a driver. +// Currently these are all for cgroup configs. +type Resources struct { + CommonResources + + // Fields below here are platform specific +} + // Network settings of the container type Network struct { Interface *NetworkInterface `json:"interface"` diff --git a/daemon/execdriver/lxc/lxc_template_unit_test.go b/daemon/execdriver/lxc/lxc_template_unit_test.go index 01bc3eaef3..ad706010e7 100644 --- a/daemon/execdriver/lxc/lxc_template_unit_test.go +++ b/daemon/execdriver/lxc/lxc_template_unit_test.go @@ -47,9 +47,11 @@ func TestLXCConfig(t *testing.T) { command := &execdriver.Command{ ID: "1", Resources: &execdriver.Resources{ - Memory: int64(mem), MemorySwap: int64(swap), - CPUShares: int64(cpu), + CommonResources: execdriver.CommonResources{ + Memory: int64(mem), + CPUShares: int64(cpu), + }, }, Network: &execdriver.Network{ Mtu: 1500, diff --git a/daemon/execdriver/windows/checkoptions.go b/daemon/execdriver/windows/checkoptions.go index cb67e8a259..1cfc48893f 100644 --- a/daemon/execdriver/windows/checkoptions.go +++ b/daemon/execdriver/windows/checkoptions.go @@ -24,11 +24,6 @@ func checkSupportedOptions(c *execdriver.Command) error { return errors.New("Windows does not support lxc options") } - // Windows doesn't support ulimit - if c.Resources.Rlimits != nil { - return errors.New("Windows does not support ulimit options") - } - // TODO Windows: Validate other fields which Windows doesn't support, factor // out where applicable per platform.