Browse code

Add support for blkio.weight_device

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>

Ma Shimiao authored on 2015/06/12 09:34:20
Showing 21 changed files
... ...
@@ -1355,6 +1355,7 @@ _docker_run() {
1355 1355
 		--add-host
1356 1356
 		--attach -a
1357 1357
 		--blkio-weight
1358
+		--blkio-weight-device
1358 1359
 		--cap-add
1359 1360
 		--cap-drop
1360 1361
 		--cgroup-parent
... ...
@@ -418,6 +418,7 @@ __docker_subcommand() {
418 418
         "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
419 419
         "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
420 420
         "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
421
+        "($help)--blkio-weight-device=-[Block IO (relative device weight)]:device:Block IO weight: "
421 422
         "($help)*--cap-add=[Add Linux capabilities]:capability: "
422 423
         "($help)*--cap-drop=[Drop Linux capabilities]:capability: "
423 424
         "($help)--cidfile=[Write the container ID to the file]:CID file:_files"
... ...
@@ -269,6 +269,11 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
269 269
 		}
270 270
 	}
271 271
 
272
+	weightDevices, err := getBlkioWeightDevices(c.hostConfig)
273
+	if err != nil {
274
+		return err
275
+	}
276
+
272 277
 	for _, limit := range ulimits {
273 278
 		rl, err := limit.GetRlimit()
274 279
 		if err != nil {
... ...
@@ -284,15 +289,16 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
284 284
 			CPUShares:         c.hostConfig.CPUShares,
285 285
 			BlkioWeight:       c.hostConfig.BlkioWeight,
286 286
 		},
287
-		MemorySwap:       c.hostConfig.MemorySwap,
288
-		KernelMemory:     c.hostConfig.KernelMemory,
289
-		CpusetCpus:       c.hostConfig.CpusetCpus,
290
-		CpusetMems:       c.hostConfig.CpusetMems,
291
-		CPUPeriod:        c.hostConfig.CPUPeriod,
292
-		CPUQuota:         c.hostConfig.CPUQuota,
293
-		Rlimits:          rlimits,
294
-		OomKillDisable:   c.hostConfig.OomKillDisable,
295
-		MemorySwappiness: -1,
287
+		MemorySwap:        c.hostConfig.MemorySwap,
288
+		KernelMemory:      c.hostConfig.KernelMemory,
289
+		CpusetCpus:        c.hostConfig.CpusetCpus,
290
+		CpusetMems:        c.hostConfig.CpusetMems,
291
+		CPUPeriod:         c.hostConfig.CPUPeriod,
292
+		CPUQuota:          c.hostConfig.CPUQuota,
293
+		Rlimits:           rlimits,
294
+		BlkioWeightDevice: weightDevices,
295
+		OomKillDisable:    c.hostConfig.OomKillDisable,
296
+		MemorySwappiness:  -1,
296 297
 	}
297 298
 
298 299
 	if c.hostConfig.MemorySwappiness != nil {
... ...
@@ -1202,6 +1202,7 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.
1202 1202
 
1203 1203
 	container.Lock()
1204 1204
 	defer container.Unlock()
1205
+
1205 1206
 	// Register any links from the host config before starting the container
1206 1207
 	if err := daemon.registerLinks(container, hostConfig); err != nil {
1207 1208
 		return err
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"github.com/docker/docker/daemon/graphdriver"
16 16
 	"github.com/docker/docker/dockerversion"
17 17
 	derr "github.com/docker/docker/errors"
18
+	pblkiodev "github.com/docker/docker/pkg/blkiodev"
18 19
 	"github.com/docker/docker/pkg/fileutils"
19 20
 	"github.com/docker/docker/pkg/idtools"
20 21
 	"github.com/docker/docker/pkg/parsers"
... ...
@@ -30,6 +31,7 @@ import (
30 30
 	"github.com/docker/libnetwork/netlabel"
31 31
 	"github.com/docker/libnetwork/options"
32 32
 	"github.com/docker/libnetwork/types"
33
+	blkiodev "github.com/opencontainers/runc/libcontainer/configs"
33 34
 	"github.com/opencontainers/runc/libcontainer/label"
34 35
 	"github.com/vishvananda/netlink"
35 36
 )
... ...
@@ -41,6 +43,21 @@ const (
41 41
 	platformSupported = true
42 42
 )
43 43
 
44
+func getBlkioWeightDevices(config *runconfig.HostConfig) ([]*blkiodev.WeightDevice, error) {
45
+	var stat syscall.Stat_t
46
+	var BlkioWeightDevices []*blkiodev.WeightDevice
47
+
48
+	for _, weightDevice := range config.BlkioWeightDevice {
49
+		if err := syscall.Stat(weightDevice.Path, &stat); err != nil {
50
+			return nil, err
51
+		}
52
+		WeightDevice := blkiodev.NewWeightDevice(int64(stat.Rdev/256), int64(stat.Rdev%256), weightDevice.Weight, 0)
53
+		BlkioWeightDevices = append(BlkioWeightDevices, WeightDevice)
54
+	}
55
+
56
+	return BlkioWeightDevices, nil
57
+}
58
+
44 59
 func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
45 60
 	var (
46 61
 		labelOpts []string
... ...
@@ -220,6 +237,11 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
220 220
 	if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
221 221
 		return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
222 222
 	}
223
+	if len(hostConfig.BlkioWeightDevice) > 0 && !sysInfo.BlkioWeightDevice {
224
+		warnings = append(warnings, "Your kernel does not support Block I/O weight_device.")
225
+		logrus.Warnf("Your kernel does not support Block I/O weight_device. Weight-device discarded.")
226
+		hostConfig.BlkioWeightDevice = []*pblkiodev.WeightDevice{}
227
+	}
223 228
 	if hostConfig.OomKillDisable && !sysInfo.OomKillDisable {
224 229
 		hostConfig.OomKillDisable = false
225 230
 		return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/docker/docker/pkg/system"
13 13
 	"github.com/docker/docker/runconfig"
14 14
 	"github.com/docker/libnetwork"
15
+	blkiodev "github.com/opencontainers/runc/libcontainer/configs"
15 16
 )
16 17
 
17 18
 const (
... ...
@@ -21,6 +22,10 @@ const (
21 21
 	windowsMaxCPUShares  = 9
22 22
 )
23 23
 
24
+func getBlkioWeightDevices(config *runconfig.HostConfig) ([]*blkiodev.WeightDevice, error) {
25
+	return nil, nil
26
+}
27
+
24 28
 func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
25 29
 	return nil
26 30
 }
... ...
@@ -18,6 +18,7 @@ import (
18 18
 	"github.com/opencontainers/runc/libcontainer"
19 19
 	"github.com/opencontainers/runc/libcontainer/cgroups/fs"
20 20
 	"github.com/opencontainers/runc/libcontainer/configs"
21
+	blkiodev "github.com/opencontainers/runc/libcontainer/configs"
21 22
 )
22 23
 
23 24
 // Mount contains information for a mount operation.
... ...
@@ -36,15 +37,16 @@ type Resources struct {
36 36
 
37 37
 	// Fields below here are platform specific
38 38
 
39
-	MemorySwap       int64            `json:"memory_swap"`
40
-	KernelMemory     int64            `json:"kernel_memory"`
41
-	CPUQuota         int64            `json:"cpu_quota"`
42
-	CpusetCpus       string           `json:"cpuset_cpus"`
43
-	CpusetMems       string           `json:"cpuset_mems"`
44
-	CPUPeriod        int64            `json:"cpu_period"`
45
-	Rlimits          []*ulimit.Rlimit `json:"rlimits"`
46
-	OomKillDisable   bool             `json:"oom_kill_disable"`
47
-	MemorySwappiness int64            `json:"memory_swappiness"`
39
+	BlkioWeightDevice []*blkiodev.WeightDevice `json:"blkio_weight_device"`
40
+	MemorySwap        int64                    `json:"memory_swap"`
41
+	KernelMemory      int64                    `json:"kernel_memory"`
42
+	CPUQuota          int64                    `json:"cpu_quota"`
43
+	CpusetCpus        string                   `json:"cpuset_cpus"`
44
+	CpusetMems        string                   `json:"cpuset_mems"`
45
+	CPUPeriod         int64                    `json:"cpu_period"`
46
+	Rlimits           []*ulimit.Rlimit         `json:"rlimits"`
47
+	OomKillDisable    bool                     `json:"oom_kill_disable"`
48
+	MemorySwappiness  int64                    `json:"memory_swappiness"`
48 49
 }
49 50
 
50 51
 // Ipc settings of the container
... ...
@@ -153,6 +155,7 @@ func SetupCgroups(container *configs.Config, c *Command) error {
153 153
 		container.Cgroups.CpuPeriod = c.Resources.CPUPeriod
154 154
 		container.Cgroups.CpuQuota = c.Resources.CPUQuota
155 155
 		container.Cgroups.BlkioWeight = c.Resources.BlkioWeight
156
+		container.Cgroups.BlkioWeightDevice = c.Resources.BlkioWeightDevice
156 157
 		container.Cgroups.OomKillDisable = c.Resources.OomKillDisable
157 158
 		container.Cgroups.MemorySwappiness = c.Resources.MemorySwappiness
158 159
 	}
... ...
@@ -187,6 +187,7 @@ Create a container
187 187
              "CpusetCpus": "0,1",
188 188
              "CpusetMems": "0,1",
189 189
              "BlkioWeight": 300,
190
+             "BlkioWeightDevice": [{}],
190 191
              "MemorySwappiness": 60,
191 192
              "OomKillDisable": false,
192 193
              "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] },
... ...
@@ -241,6 +242,7 @@ Json Parameters:
241 241
 -   **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use.
242 242
 -   **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
243 243
 -   **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000.
244
+ -   **BlkioWeightDevice** - Block IO weight (relative device weight) in the form of:        `"BlkioWeightDevice": [{"Path": "device_path", "Weight": weight}]`
244 245
 -   **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.
245 246
 -   **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not.
246 247
 -   **AttachStdin** - Boolean value, attaches to `stdin`.
... ...
@@ -391,6 +393,7 @@ Return low-level information on the container `id`
391 391
 		"HostConfig": {
392 392
 			"Binds": null,
393 393
 			"BlkioWeight": 0,
394
+			"BlkioWeightDevice": [{}],
394 395
 			"CapAdd": null,
395 396
 			"CapDrop": null,
396 397
 			"ContainerIDFile": "",
... ...
@@ -19,6 +19,7 @@ Creates a new container.
19 19
       -a, --attach=[]               Attach to STDIN, STDOUT or STDERR
20 20
       --add-host=[]                 Add a custom host-to-IP mapping (host:ip)
21 21
       --blkio-weight=0              Block IO weight (relative weight)
22
+      --blkio-weight-device=""      Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)
22 23
       --cpu-shares=0                CPU shares (relative weight)
23 24
       --cap-add=[]                  Add Linux capabilities
24 25
       --cap-drop=[]                 Drop Linux capabilities
... ...
@@ -17,6 +17,7 @@ parent = "smn_cli"
17 17
       -a, --attach=[]               Attach to STDIN, STDOUT or STDERR
18 18
       --add-host=[]                 Add a custom host-to-IP mapping (host:ip)
19 19
       --blkio-weight=0              Block IO weight (relative weight)
20
+      --blkio-weight-device=""      Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)
20 21
       --cpu-shares=0                CPU shares (relative weight)
21 22
       --cap-add=[]                  Add Linux capabilities
22 23
       --cap-drop=[]                 Drop Linux capabilities
... ...
@@ -623,6 +623,7 @@ container:
623 623
 | `--cpuset-mems=""`         | Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. |
624 624
 | `--cpu-quota=0`            | Limit the CPU CFS (Completely Fair Scheduler) quota                                         |
625 625
 | `--blkio-weight=0`         | Block IO weight (relative weight) accepts a weight value between 10 and 1000.               |
626
+| `--blkio-weight-device=""` | Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)                                                |
626 627
 | `--oom-kill-disable=false` | Whether to disable OOM Killer for the container or not.                                     |
627 628
 | `--memory-swappiness=""  ` | Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.        |
628 629
 
... ...
@@ -937,6 +938,9 @@ By default, all containers get the same proportion of block IO bandwidth
937 937
 container's blkio weight relative to the weighting of all other running
938 938
 containers using the `--blkio-weight` flag.
939 939
 
940
+> **Note:** The blkio weight setting is only available for direct IO. Buffered IO
941
+> is not currently supported.
942
+
940 943
 The `--blkio-weight` flag can set the weighting to a value between 10 to 1000.
941 944
 For example, the commands below create two containers with different blkio
942 945
 weight:
... ...
@@ -951,8 +955,24 @@ If you do block IO in the two containers at the same time, by, for example:
951 951
 You'll find that the proportion of time is the same as the proportion of blkio
952 952
 weights of the two containers.
953 953
 
954
-> **Note:** The blkio weight setting is only available for direct IO. Buffered IO
955
-> is not currently supported.
954
+The `--blkio-weight-device="DEVICE_NAME:WEIGHT"` flag sets a specific device weight.
955
+The `DEVICE_NAME:WEIGHT` is a string containing a colon-separated device name and weight.
956
+For example, to set `/dev/sda` device weight to `200`:
957
+
958
+$ docker run -it \
959
+    --blkio-weight-device "/dev/sda:200" \
960
+    ubuntu
961
+
962
+If you specify both the `--blkio-weight` and `--blkio-weight-device`, Docker
963
+uses the `--blkio-weight` as the default weight and uses `--blkio-weight-device` 
964
+to override this default with a new value on a specific device. 
965
+The following example uses a default weight of `300` and overrides this default 
966
+on `/dev/sda` setting that weight to `200`:
967
+
968
+$ docker run -it \
969
+    --blkio-weight 300 \
970
+    --blkio-weight-device "/dev/sda:200" \
971
+    ubuntu
956 972
 
957 973
 ## Additional groups
958 974
     --group-add: Add Linux capabilities
... ...
@@ -217,6 +217,12 @@ func (s *DockerSuite) TestRunWithBlkioInvalidWeight(c *check.C) {
217 217
 	c.Assert(out, checker.Contains, expected)
218 218
 }
219 219
 
220
+func (s *DockerSuite) TestRunWithBlkioInvalidWeightDevice(c *check.C) {
221
+	testRequires(c, blkioWeight)
222
+	out, _, err := dockerCmdWithError("run", "--blkio-weight-device", "/dev/sda:5", "busybox", "true")
223
+	c.Assert(err, check.NotNil, check.Commentf(out))
224
+}
225
+
220 226
 func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
221 227
 	testRequires(c, oomControl)
222 228
 	errChan := make(chan error)
... ...
@@ -9,6 +9,7 @@ docker-create - Create a new container
9 9
 [**-a**|**--attach**[=*[]*]]
10 10
 [**--add-host**[=*[]*]]
11 11
 [**--blkio-weight**[=*[BLKIO-WEIGHT]*]]
12
+[**--blkio-weight-device**[=*[]*]]
12 13
 [**--cpu-shares**[=*0*]]
13 14
 [**--cap-add**[=*[]*]]
14 15
 [**--cap-drop**[=*[]*]]
... ...
@@ -82,6 +83,9 @@ The initial status of the container created with **docker create** is 'created'.
82 82
 **--blkio-weight**=*0*
83 83
    Block IO weight (relative weight) accepts a weight value between 10 and 1000.
84 84
 
85
+**--blkio-weight-device**=[]
86
+   Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`).
87
+
85 88
 **--cpu-shares**=*0*
86 89
    CPU shares (relative weight)
87 90
 
... ...
@@ -9,6 +9,7 @@ docker-run - Run a command in a new container
9 9
 [**-a**|**--attach**[=*[]*]]
10 10
 [**--add-host**[=*[]*]]
11 11
 [**--blkio-weight**[=*[BLKIO-WEIGHT]*]]
12
+[**--blkio-weight-device**[=*[]*]]
12 13
 [**--cpu-shares**[=*0*]]
13 14
 [**--cap-add**[=*[]*]]
14 15
 [**--cap-drop**[=*[]*]]
... ...
@@ -99,6 +100,9 @@ option can be set multiple times.
99 99
 **--blkio-weight**=*0*
100 100
    Block IO weight (relative weight) accepts a weight value between 10 and 1000.
101 101
 
102
+**--blkio-weight-device**=[]
103
+   Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`).
104
+
102 105
 **--cpu-shares**=*0*
103 106
    CPU shares (relative weight)
104 107
 
... ...
@@ -755,6 +759,13 @@ Note:
755 755
 
756 756
 You would have to write policy defining a `svirt_apache_t` type.
757 757
 
758
+## Setting device weight
759
+
760
+If you want to set `/dev/sda` device weight to `200`, you can specify the device
761
+weight by `--blkio-weight-device` flag. Use the following command:
762
+
763
+   # docker run -it --blkio-weight-device "/dev/sda:200" ubuntu
764
+
758 765
 # HISTORY
759 766
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
760 767
 based on docker.com source material and internal work.
... ...
@@ -6,8 +6,10 @@ import (
6 6
 	"os"
7 7
 	"path"
8 8
 	"regexp"
9
+	"strconv"
9 10
 	"strings"
10 11
 
12
+	"github.com/docker/docker/pkg/blkiodev"
11 13
 	"github.com/docker/docker/pkg/parsers"
12 14
 )
13 15
 
... ...
@@ -168,6 +170,9 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
168 168
 // ValidatorFctType defines a validator function that returns a validated string and/or an error.
169 169
 type ValidatorFctType func(val string) (string, error)
170 170
 
171
+// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
172
+type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
173
+
171 174
 // ValidatorFctListType defines a validator function that returns a validated list of string and/or an error
172 175
 type ValidatorFctListType func(val string) ([]string, error)
173 176
 
... ...
@@ -182,6 +187,29 @@ func ValidateAttach(val string) (string, error) {
182 182
 	return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR")
183 183
 }
184 184
 
185
+// ValidateWeightDevice validates that the specified string has a valid device-weight format.
186
+func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
187
+	split := strings.SplitN(val, ":", 2)
188
+	if len(split) != 2 {
189
+		return nil, fmt.Errorf("bad format: %s", val)
190
+	}
191
+	if !strings.HasPrefix(split[0], "/dev/") {
192
+		return nil, fmt.Errorf("bad format for device path: %s", val)
193
+	}
194
+	weight, err := strconv.ParseUint(split[1], 10, 0)
195
+	if err != nil {
196
+		return nil, fmt.Errorf("invalid weight for device: %s", val)
197
+	}
198
+	if weight > 0 && (weight < 10 || weight > 1000) {
199
+		return nil, fmt.Errorf("invalid weight for device: %s", val)
200
+	}
201
+
202
+	return &blkiodev.WeightDevice{
203
+		Path:   split[0],
204
+		Weight: uint16(weight),
205
+	}, nil
206
+}
207
+
185 208
 // ValidateLink validates that the specified string has a valid link format (containerName:alias).
186 209
 func ValidateLink(val string) (string, error) {
187 210
 	if _, _, err := parsers.ParseLink(val); err != nil {
188 211
new file mode 100644
... ...
@@ -0,0 +1,56 @@
0
+package opts
1
+
2
+import (
3
+	"fmt"
4
+
5
+	"github.com/docker/docker/pkg/blkiodev"
6
+)
7
+
8
+// WeightdeviceOpt defines a map of WeightDevices
9
+type WeightdeviceOpt struct {
10
+	values    []*blkiodev.WeightDevice
11
+	validator ValidatorWeightFctType
12
+}
13
+
14
+// NewWeightdeviceOpt creates a new WeightdeviceOpt
15
+func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt {
16
+	values := []*blkiodev.WeightDevice{}
17
+	return WeightdeviceOpt{
18
+		values:    values,
19
+		validator: validator,
20
+	}
21
+}
22
+
23
+// Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt
24
+func (opt *WeightdeviceOpt) Set(val string) error {
25
+	var value *blkiodev.WeightDevice
26
+	if opt.validator != nil {
27
+		v, err := opt.validator(val)
28
+		if err != nil {
29
+			return err
30
+		}
31
+		value = v
32
+	}
33
+	(opt.values) = append((opt.values), value)
34
+	return nil
35
+}
36
+
37
+// String returns Ulimit values as a string.
38
+func (opt *WeightdeviceOpt) String() string {
39
+	var out []string
40
+	for _, v := range opt.values {
41
+		out = append(out, v.String())
42
+	}
43
+
44
+	return fmt.Sprintf("%v", out)
45
+}
46
+
47
+// GetList returns a slice of pointers to WeightDevices.
48
+func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice {
49
+	var weightdevice []*blkiodev.WeightDevice
50
+	for _, v := range opt.values {
51
+		weightdevice = append(weightdevice, v)
52
+	}
53
+
54
+	return weightdevice
55
+}
0 56
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package blkiodev
1
+
2
+import (
3
+	"fmt"
4
+)
5
+
6
+// WeightDevice is a structure that hold device:weight pair
7
+type WeightDevice struct {
8
+	Path   string
9
+	Weight uint16
10
+}
11
+
12
+func (w *WeightDevice) String() string {
13
+	return fmt.Sprintf("%s:%d", w.Path, w.Weight)
14
+}
... ...
@@ -60,6 +60,9 @@ type cgroupCPUInfo struct {
60 60
 type cgroupBlkioInfo struct {
61 61
 	// Whether Block IO weight is supported or not
62 62
 	BlkioWeight bool
63
+
64
+	// Whether Block IO weight_device is supported or not
65
+	BlkioWeightDevice bool
63 66
 }
64 67
 
65 68
 type cgroupCpusetInfo struct {
... ...
@@ -117,11 +117,19 @@ func checkCgroupBlkioInfo(quiet bool) cgroupBlkioInfo {
117 117
 		return cgroupBlkioInfo{}
118 118
 	}
119 119
 
120
-	w := cgroupEnabled(mountPoint, "blkio.weight")
121
-	if !quiet && !w {
120
+	weight := cgroupEnabled(mountPoint, "blkio.weight")
121
+	if !quiet && !weight {
122 122
 		logrus.Warn("Your kernel does not support cgroup blkio weight")
123 123
 	}
124
-	return cgroupBlkioInfo{BlkioWeight: w}
124
+
125
+	weightDevice := cgroupEnabled(mountPoint, "blkio.weight_device")
126
+	if !quiet && !weightDevice {
127
+		logrus.Warn("Your kernel does not support cgroup blkio weight_device")
128
+	}
129
+	return cgroupBlkioInfo{
130
+		BlkioWeight:       weight,
131
+		BlkioWeightDevice: weightDevice,
132
+	}
125 133
 }
126 134
 
127 135
 // checkCgroupCpusetInfo reads the cpuset information from the cpuset cgroup mount point.
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"io"
6 6
 	"strings"
7 7
 
8
+	"github.com/docker/docker/pkg/blkiodev"
8 9
 	"github.com/docker/docker/pkg/nat"
9 10
 	"github.com/docker/docker/pkg/stringutils"
10 11
 	"github.com/docker/docker/pkg/ulimit"
... ...
@@ -180,7 +181,8 @@ type HostConfig struct {
180 180
 	VolumesFrom     []string      // List of volumes to take from other container
181 181
 
182 182
 	// Applicable to UNIX platforms
183
-	BlkioWeight       uint16                // Block IO weight (relative weight vs. other containers)
183
+	BlkioWeight       uint16 // Block IO weight (relative weight vs. other containers)
184
+	BlkioWeightDevice []*blkiodev.WeightDevice
184 185
 	CapAdd            *stringutils.StrSlice // List of kernel capabilities to add to the container
185 186
 	CapDrop           *stringutils.StrSlice // List of kernel capabilities to remove from the container
186 187
 	CgroupParent      string                // Parent cgroup.
... ...
@@ -48,12 +48,13 @@ var (
48 48
 func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSet, error) {
49 49
 	var (
50 50
 		// FIXME: use utils.ListOpts for attach and volumes?
51
-		flAttach  = opts.NewListOpts(opts.ValidateAttach)
52
-		flVolumes = opts.NewListOpts(nil)
53
-		flLinks   = opts.NewListOpts(opts.ValidateLink)
54
-		flEnv     = opts.NewListOpts(opts.ValidateEnv)
55
-		flLabels  = opts.NewListOpts(opts.ValidateEnv)
56
-		flDevices = opts.NewListOpts(opts.ValidateDevice)
51
+		flAttach            = opts.NewListOpts(opts.ValidateAttach)
52
+		flVolumes           = opts.NewListOpts(nil)
53
+		flBlkioWeightDevice = opts.NewWeightdeviceOpt(opts.ValidateWeightDevice)
54
+		flLinks             = opts.NewListOpts(opts.ValidateLink)
55
+		flEnv               = opts.NewListOpts(opts.ValidateEnv)
56
+		flLabels            = opts.NewListOpts(opts.ValidateEnv)
57
+		flDevices           = opts.NewListOpts(opts.ValidateDevice)
57 58
 
58 59
 		flUlimits = opts.NewUlimitOpt(nil)
59 60
 
... ...
@@ -108,6 +109,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
108 108
 	)
109 109
 
110 110
 	cmd.Var(&flAttach, []string{"a", "-attach"}, "Attach to STDIN, STDOUT or STDERR")
111
+	cmd.Var(&flBlkioWeightDevice, []string{"-blkio-weight-device"}, "Block IO weight (relative device weight)")
111 112
 	cmd.Var(&flVolumes, []string{"v", "-volume"}, "Bind mount a volume")
112 113
 	cmd.Var(&flLinks, []string{"#link", "-link"}, "Add link to another container")
113 114
 	cmd.Var(&flDevices, []string{"-device"}, "Add a host device to the container")
... ...
@@ -344,6 +346,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
344 344
 		CpusetMems:        *flCpusetMems,
345 345
 		CPUQuota:          *flCPUQuota,
346 346
 		BlkioWeight:       *flBlkioWeight,
347
+		BlkioWeightDevice: flBlkioWeightDevice.GetList(),
347 348
 		OomKillDisable:    *flOomKillDisable,
348 349
 		MemorySwappiness:  flSwappiness,
349 350
 		Privileged:        *flPrivileged,