Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi authored on 2016/04/30 05:39:04... | ... |
@@ -27,6 +27,7 @@ import ( |
27 | 27 |
"github.com/docker/docker/runconfig" |
28 | 28 |
runconfigopts "github.com/docker/docker/runconfig/opts" |
29 | 29 |
"github.com/docker/engine-api/types" |
30 |
+ "github.com/docker/engine-api/types/blkiodev" |
|
30 | 31 |
pblkiodev "github.com/docker/engine-api/types/blkiodev" |
31 | 32 |
containertypes "github.com/docker/engine-api/types/container" |
32 | 33 |
"github.com/docker/libnetwork" |
... | ... |
@@ -176,76 +177,22 @@ func parseSecurityOpt(container *container.Container, config *containertypes.Hos |
176 | 176 |
return err |
177 | 177 |
} |
178 | 178 |
|
179 |
-func getBlkioReadIOpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) { |
|
180 |
- var blkioReadIOpsDevice []specs.ThrottleDevice |
|
179 |
+func getBlkioThrottleDevices(devs []*blkiodev.ThrottleDevice) ([]specs.ThrottleDevice, error) { |
|
180 |
+ var throttleDevices []specs.ThrottleDevice |
|
181 | 181 |
var stat syscall.Stat_t |
182 | 182 |
|
183 |
- for _, iopsDevice := range config.BlkioDeviceReadIOps { |
|
184 |
- if err := syscall.Stat(iopsDevice.Path, &stat); err != nil { |
|
183 |
+ for _, d := range devs { |
|
184 |
+ if err := syscall.Stat(d.Path, &stat); err != nil { |
|
185 | 185 |
return nil, err |
186 | 186 |
} |
187 |
- rate := iopsDevice.Rate |
|
187 |
+ rate := d.Rate |
|
188 | 188 |
d := specs.ThrottleDevice{Rate: &rate} |
189 | 189 |
d.Major = int64(stat.Rdev / 256) |
190 | 190 |
d.Minor = int64(stat.Rdev % 256) |
191 |
- blkioReadIOpsDevice = append(blkioReadIOpsDevice, d) |
|
191 |
+ throttleDevices = append(throttleDevices, d) |
|
192 | 192 |
} |
193 | 193 |
|
194 |
- return blkioReadIOpsDevice, nil |
|
195 |
-} |
|
196 |
- |
|
197 |
-func getBlkioWriteIOpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) { |
|
198 |
- var blkioWriteIOpsDevice []specs.ThrottleDevice |
|
199 |
- var stat syscall.Stat_t |
|
200 |
- |
|
201 |
- for _, iopsDevice := range config.BlkioDeviceWriteIOps { |
|
202 |
- if err := syscall.Stat(iopsDevice.Path, &stat); err != nil { |
|
203 |
- return nil, err |
|
204 |
- } |
|
205 |
- rate := iopsDevice.Rate |
|
206 |
- d := specs.ThrottleDevice{Rate: &rate} |
|
207 |
- d.Major = int64(stat.Rdev / 256) |
|
208 |
- d.Minor = int64(stat.Rdev % 256) |
|
209 |
- blkioWriteIOpsDevice = append(blkioWriteIOpsDevice, d) |
|
210 |
- } |
|
211 |
- |
|
212 |
- return blkioWriteIOpsDevice, nil |
|
213 |
-} |
|
214 |
- |
|
215 |
-func getBlkioReadBpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) { |
|
216 |
- var blkioReadBpsDevice []specs.ThrottleDevice |
|
217 |
- var stat syscall.Stat_t |
|
218 |
- |
|
219 |
- for _, bpsDevice := range config.BlkioDeviceReadBps { |
|
220 |
- if err := syscall.Stat(bpsDevice.Path, &stat); err != nil { |
|
221 |
- return nil, err |
|
222 |
- } |
|
223 |
- rate := bpsDevice.Rate |
|
224 |
- d := specs.ThrottleDevice{Rate: &rate} |
|
225 |
- d.Major = int64(stat.Rdev / 256) |
|
226 |
- d.Minor = int64(stat.Rdev % 256) |
|
227 |
- blkioReadBpsDevice = append(blkioReadBpsDevice, d) |
|
228 |
- } |
|
229 |
- |
|
230 |
- return blkioReadBpsDevice, nil |
|
231 |
-} |
|
232 |
- |
|
233 |
-func getBlkioWriteBpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) { |
|
234 |
- var blkioWriteBpsDevice []specs.ThrottleDevice |
|
235 |
- var stat syscall.Stat_t |
|
236 |
- |
|
237 |
- for _, bpsDevice := range config.BlkioDeviceWriteBps { |
|
238 |
- if err := syscall.Stat(bpsDevice.Path, &stat); err != nil { |
|
239 |
- return nil, err |
|
240 |
- } |
|
241 |
- rate := bpsDevice.Rate |
|
242 |
- d := specs.ThrottleDevice{Rate: &rate} |
|
243 |
- d.Major = int64(stat.Rdev / 256) |
|
244 |
- d.Minor = int64(stat.Rdev % 256) |
|
245 |
- blkioWriteBpsDevice = append(blkioWriteBpsDevice, d) |
|
246 |
- } |
|
247 |
- |
|
248 |
- return blkioWriteBpsDevice, nil |
|
194 |
+ return throttleDevices, nil |
|
249 | 195 |
} |
250 | 196 |
|
251 | 197 |
func checkKernelVersion(k, major, minor int) bool { |
... | ... |
@@ -31,19 +31,19 @@ func setResources(s *specs.Spec, r containertypes.Resources) error { |
31 | 31 |
if err != nil { |
32 | 32 |
return err |
33 | 33 |
} |
34 |
- readBpsDevice, err := getBlkioReadBpsDevices(r) |
|
34 |
+ readBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadBps) |
|
35 | 35 |
if err != nil { |
36 | 36 |
return err |
37 | 37 |
} |
38 |
- writeBpsDevice, err := getBlkioWriteBpsDevices(r) |
|
38 |
+ writeBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteBps) |
|
39 | 39 |
if err != nil { |
40 | 40 |
return err |
41 | 41 |
} |
42 |
- readIOpsDevice, err := getBlkioReadIOpsDevices(r) |
|
42 |
+ readIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadIOps) |
|
43 | 43 |
if err != nil { |
44 | 44 |
return err |
45 | 45 |
} |
46 |
- writeIOpsDevice, err := getBlkioWriteIOpsDevices(r) |
|
46 |
+ writeIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteIOps) |
|
47 | 47 |
if err != nil { |
48 | 48 |
return err |
49 | 49 |
} |