瀏覽代碼

Windows: Refactor resources structure

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 9 年之前
父節點
當前提交
b1220a763c

+ 15 - 13
daemon/container_unix.go

@@ -279,19 +279,21 @@ func populateCommand(c *Container, env []string) error {
 	}
 	}
 
 
 	resources := &execdriver.Resources{
 	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 {
 	if c.hostConfig.MemorySwappiness != nil {

+ 3 - 1
daemon/container_windows.go

@@ -86,7 +86,9 @@ func populateCommand(c *Container, env []string) error {
 
 
 	// TODO Windows. More resource controls to be implemented later.
 	// TODO Windows. More resource controls to be implemented later.
 	resources := &execdriver.Resources{
 	resources := &execdriver.Resources{
-		CPUShares: c.hostConfig.CPUShares,
+		CommonResources: execdriver.CommonResources{
+			CPUShares: c.hostConfig.CPUShares,
+		},
 	}
 	}
 
 
 	// TODO Windows. Further refactoring required (privileged/user)
 	// TODO Windows. Further refactoring required (privileged/user)

+ 7 - 19
daemon/execdriver/driver.go

@@ -7,8 +7,6 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/docker/docker/pkg/idtools"
 	"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"
 	"github.com/opencontainers/runc/libcontainer/configs"
 	"github.com/opencontainers/runc/libcontainer/configs"
 )
 )
@@ -138,23 +136,13 @@ type UTS struct {
 	HostUTS bool `json:"host_uts"`
 	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.
 // ResourceStats contains information about resource usage by a container.

+ 19 - 0
daemon/execdriver/driver_unix.go

@@ -13,6 +13,7 @@ import (
 
 
 	"github.com/docker/docker/daemon/execdriver/native/template"
 	"github.com/docker/docker/daemon/execdriver/native/template"
 	"github.com/docker/docker/pkg/mount"
 	"github.com/docker/docker/pkg/mount"
+	"github.com/docker/docker/pkg/ulimit"
 	"github.com/opencontainers/runc/libcontainer"
 	"github.com/opencontainers/runc/libcontainer"
 	"github.com/opencontainers/runc/libcontainer/cgroups/fs"
 	"github.com/opencontainers/runc/libcontainer/cgroups/fs"
 	"github.com/opencontainers/runc/libcontainer/configs"
 	"github.com/opencontainers/runc/libcontainer/configs"
@@ -27,6 +28,24 @@ type Mount struct {
 	Slave       bool   `json:"slave"`
 	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
 // Network settings of the container
 type Network struct {
 type Network struct {
 	Mtu            int    `json:"mtu"`
 	Mtu            int    `json:"mtu"`

+ 8 - 0
daemon/execdriver/driver_windows.go

@@ -9,6 +9,14 @@ type Mount struct {
 	Writable    bool   `json:"writable"`
 	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
 // Network settings of the container
 type Network struct {
 type Network struct {
 	Interface   *NetworkInterface `json:"interface"`
 	Interface   *NetworkInterface `json:"interface"`

+ 4 - 2
daemon/execdriver/lxc/lxc_template_unit_test.go

@@ -47,9 +47,11 @@ func TestLXCConfig(t *testing.T) {
 	command := &execdriver.Command{
 	command := &execdriver.Command{
 		ID: "1",
 		ID: "1",
 		Resources: &execdriver.Resources{
 		Resources: &execdriver.Resources{
-			Memory:     int64(mem),
 			MemorySwap: int64(swap),
 			MemorySwap: int64(swap),
-			CPUShares:  int64(cpu),
+			CommonResources: execdriver.CommonResources{
+				Memory:    int64(mem),
+				CPUShares: int64(cpu),
+			},
 		},
 		},
 		Network: &execdriver.Network{
 		Network: &execdriver.Network{
 			Mtu: 1500,
 			Mtu: 1500,

+ 0 - 5
daemon/execdriver/windows/checkoptions.go

@@ -24,11 +24,6 @@ func checkSupportedOptions(c *execdriver.Command) error {
 		return errors.New("Windows does not support lxc options")
 		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
 	// TODO Windows: Validate other fields which Windows doesn't support, factor
 	// out where applicable per platform.
 	// out where applicable per platform.