diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 69f57b909f..dbe202ceb3 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -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 { diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 0110ac26ee..d8ab1f8fd6 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -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 }