@@ -273,6 +273,25 @@ other options are ignored.
273273 if r .BlockIO .Weight != nil {
274274 config .Cgroups .Resources .BlkioWeight = * r .BlockIO .Weight
275275 }
276+ if r .BlockIO .LeafWeight != nil {
277+ config .Cgroups .Resources .BlkioLeafWeight = * r .BlockIO .LeafWeight
278+ }
279+ // For devices, we either update an existing one, or insert a new one.
280+ for _ , wd := range r .BlockIO .WeightDevice {
281+ config .Cgroups .Resources .BlkioWeightDevice = upsertWeightDevice (config .Cgroups .Resources .BlkioWeightDevice , wd )
282+ }
283+ for _ , td := range r .BlockIO .ThrottleReadBpsDevice {
284+ config .Cgroups .Resources .BlkioThrottleReadBpsDevice = upsertThrottleDevice (config .Cgroups .Resources .BlkioThrottleReadBpsDevice , td )
285+ }
286+ for _ , td := range r .BlockIO .ThrottleWriteBpsDevice {
287+ config .Cgroups .Resources .BlkioThrottleWriteBpsDevice = upsertThrottleDevice (config .Cgroups .Resources .BlkioThrottleWriteBpsDevice , td )
288+ }
289+ for _ , td := range r .BlockIO .ThrottleReadIOPSDevice {
290+ config .Cgroups .Resources .BlkioThrottleReadIOPSDevice = upsertThrottleDevice (config .Cgroups .Resources .BlkioThrottleReadIOPSDevice , td )
291+ }
292+ for _ , td := range r .BlockIO .ThrottleWriteIOPSDevice {
293+ config .Cgroups .Resources .BlkioThrottleWriteIOPSDevice = upsertThrottleDevice (config .Cgroups .Resources .BlkioThrottleWriteIOPSDevice , td )
294+ }
276295
277296 // Setting CPU quota and period independently does not make much sense,
278297 // but historically runc allowed it and this needs to be supported
@@ -381,3 +400,34 @@ other options are ignored.
381400 return container .Set (config )
382401 },
383402}
403+
404+ func upsertWeightDevice (slice []* cgroups.WeightDevice , wd specs.LinuxWeightDevice ) []* cgroups.WeightDevice {
405+ var weight , leafWeight uint16
406+ if wd .Weight != nil {
407+ weight = * wd .Weight
408+ }
409+ if wd .LeafWeight != nil {
410+ leafWeight = * wd .LeafWeight
411+ }
412+
413+ for i , dev := range slice {
414+ if dev .Major == wd .Major && dev .Minor == wd .Minor {
415+ slice [i ].Weight = weight
416+ slice [i ].LeafWeight = leafWeight
417+ return slice
418+ }
419+ }
420+
421+ return append (slice , cgroups .NewWeightDevice (wd .Major , wd .Minor , weight , leafWeight ))
422+ }
423+
424+ func upsertThrottleDevice (slice []* cgroups.ThrottleDevice , td specs.LinuxThrottleDevice ) []* cgroups.ThrottleDevice {
425+ for i , dev := range slice {
426+ if dev .Major == td .Major && dev .Minor == td .Minor {
427+ slice [i ].Rate = td .Rate
428+ return slice
429+ }
430+ }
431+
432+ return append (slice , cgroups .NewThrottleDevice (td .Major , td .Minor , td .Rate ))
433+ }
0 commit comments