blkio_device.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package configs
  2. import "fmt"
  3. // blockIODevice holds major:minor format supported in blkio cgroup
  4. type blockIODevice struct {
  5. // Major is the device's major number
  6. Major int64 `json:"major"`
  7. // Minor is the device's minor number
  8. Minor int64 `json:"minor"`
  9. }
  10. // WeightDevice struct holds a `major:minor weight`|`major:minor leaf_weight` pair
  11. type WeightDevice struct {
  12. blockIODevice
  13. // Weight is the bandwidth rate for the device, range is from 10 to 1000
  14. Weight uint16 `json:"weight"`
  15. // LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only
  16. LeafWeight uint16 `json:"leafWeight"`
  17. }
  18. // NewWeightDevice returns a configured WeightDevice pointer
  19. func NewWeightDevice(major, minor int64, weight, leafWeight uint16) *WeightDevice {
  20. wd := &WeightDevice{}
  21. wd.Major = major
  22. wd.Minor = minor
  23. wd.Weight = weight
  24. wd.LeafWeight = leafWeight
  25. return wd
  26. }
  27. // WeightString formats the struct to be writable to the cgroup specific file
  28. func (wd *WeightDevice) WeightString() string {
  29. return fmt.Sprintf("%d:%d %d", wd.Major, wd.Minor, wd.Weight)
  30. }
  31. // LeafWeightString formats the struct to be writable to the cgroup specific file
  32. func (wd *WeightDevice) LeafWeightString() string {
  33. return fmt.Sprintf("%d:%d %d", wd.Major, wd.Minor, wd.LeafWeight)
  34. }
  35. // ThrottleDevice struct holds a `major:minor rate_per_second` pair
  36. type ThrottleDevice struct {
  37. blockIODevice
  38. // Rate is the IO rate limit per cgroup per device
  39. Rate uint64 `json:"rate"`
  40. }
  41. // NewThrottleDevice returns a configured ThrottleDevice pointer
  42. func NewThrottleDevice(major, minor int64, rate uint64) *ThrottleDevice {
  43. td := &ThrottleDevice{}
  44. td.Major = major
  45. td.Minor = minor
  46. td.Rate = rate
  47. return td
  48. }
  49. // String formats the struct to be writable to the cgroup specific file
  50. func (td *ThrottleDevice) String() string {
  51. return fmt.Sprintf("%d:%d %d", td.Major, td.Minor, td.Rate)
  52. }