зеркало из https://github.com/microsoft/docker.git
Simplify blkio resources setup in spec
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Родитель
aa537a367c
Коммит
668f0a2a4c
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/docker/docker/runconfig"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/engine-api/types"
|
||||
"github.com/docker/engine-api/types/blkiodev"
|
||||
pblkiodev "github.com/docker/engine-api/types/blkiodev"
|
||||
containertypes "github.com/docker/engine-api/types/container"
|
||||
"github.com/docker/libnetwork"
|
||||
|
@ -176,76 +177,22 @@ func parseSecurityOpt(container *container.Container, config *containertypes.Hos
|
|||
return err
|
||||
}
|
||||
|
||||
func getBlkioReadIOpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) {
|
||||
var blkioReadIOpsDevice []specs.ThrottleDevice
|
||||
func getBlkioThrottleDevices(devs []*blkiodev.ThrottleDevice) ([]specs.ThrottleDevice, error) {
|
||||
var throttleDevices []specs.ThrottleDevice
|
||||
var stat syscall.Stat_t
|
||||
|
||||
for _, iopsDevice := range config.BlkioDeviceReadIOps {
|
||||
if err := syscall.Stat(iopsDevice.Path, &stat); err != nil {
|
||||
for _, d := range devs {
|
||||
if err := syscall.Stat(d.Path, &stat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rate := iopsDevice.Rate
|
||||
rate := d.Rate
|
||||
d := specs.ThrottleDevice{Rate: &rate}
|
||||
d.Major = int64(stat.Rdev / 256)
|
||||
d.Minor = int64(stat.Rdev % 256)
|
||||
blkioReadIOpsDevice = append(blkioReadIOpsDevice, d)
|
||||
throttleDevices = append(throttleDevices, d)
|
||||
}
|
||||
|
||||
return blkioReadIOpsDevice, nil
|
||||
}
|
||||
|
||||
func getBlkioWriteIOpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) {
|
||||
var blkioWriteIOpsDevice []specs.ThrottleDevice
|
||||
var stat syscall.Stat_t
|
||||
|
||||
for _, iopsDevice := range config.BlkioDeviceWriteIOps {
|
||||
if err := syscall.Stat(iopsDevice.Path, &stat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rate := iopsDevice.Rate
|
||||
d := specs.ThrottleDevice{Rate: &rate}
|
||||
d.Major = int64(stat.Rdev / 256)
|
||||
d.Minor = int64(stat.Rdev % 256)
|
||||
blkioWriteIOpsDevice = append(blkioWriteIOpsDevice, d)
|
||||
}
|
||||
|
||||
return blkioWriteIOpsDevice, nil
|
||||
}
|
||||
|
||||
func getBlkioReadBpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) {
|
||||
var blkioReadBpsDevice []specs.ThrottleDevice
|
||||
var stat syscall.Stat_t
|
||||
|
||||
for _, bpsDevice := range config.BlkioDeviceReadBps {
|
||||
if err := syscall.Stat(bpsDevice.Path, &stat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rate := bpsDevice.Rate
|
||||
d := specs.ThrottleDevice{Rate: &rate}
|
||||
d.Major = int64(stat.Rdev / 256)
|
||||
d.Minor = int64(stat.Rdev % 256)
|
||||
blkioReadBpsDevice = append(blkioReadBpsDevice, d)
|
||||
}
|
||||
|
||||
return blkioReadBpsDevice, nil
|
||||
}
|
||||
|
||||
func getBlkioWriteBpsDevices(config containertypes.Resources) ([]specs.ThrottleDevice, error) {
|
||||
var blkioWriteBpsDevice []specs.ThrottleDevice
|
||||
var stat syscall.Stat_t
|
||||
|
||||
for _, bpsDevice := range config.BlkioDeviceWriteBps {
|
||||
if err := syscall.Stat(bpsDevice.Path, &stat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rate := bpsDevice.Rate
|
||||
d := specs.ThrottleDevice{Rate: &rate}
|
||||
d.Major = int64(stat.Rdev / 256)
|
||||
d.Minor = int64(stat.Rdev % 256)
|
||||
blkioWriteBpsDevice = append(blkioWriteBpsDevice, d)
|
||||
}
|
||||
|
||||
return blkioWriteBpsDevice, nil
|
||||
return throttleDevices, nil
|
||||
}
|
||||
|
||||
func checkKernelVersion(k, major, minor int) bool {
|
||||
|
|
|
@ -31,19 +31,19 @@ func setResources(s *specs.Spec, r containertypes.Resources) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
readBpsDevice, err := getBlkioReadBpsDevices(r)
|
||||
readBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadBps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeBpsDevice, err := getBlkioWriteBpsDevices(r)
|
||||
writeBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteBps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
readIOpsDevice, err := getBlkioReadIOpsDevices(r)
|
||||
readIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadIOps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeIOpsDevice, err := getBlkioWriteIOpsDevices(r)
|
||||
writeIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteIOps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче