...

Source file src/github.com/opencontainers/runc/libcontainer/configs/blkio_device.go

Documentation: github.com/opencontainers/runc/libcontainer/configs

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

View as plain text