@@ -504,6 +504,144 @@ func (g *Generator) SetProcessOOMScoreAdj(adj int) {
504504 g .spec .Process .OOMScoreAdj = & adj
505505}
506506
507+ // SetLinuxResourcesBlockIOLeafWeight sets g.spec.Linux.Resources.BlockIO.LeafWeight.
508+ func (g * Generator ) SetLinuxResourcesBlockIOLeafWeight (weight uint16 ) {
509+ g .initSpecLinuxResourcesBlockIO ()
510+ g .spec .Linux .Resources .BlockIO .LeafWeight = & weight
511+ }
512+
513+ // AddLinuxResourcesBlockIOLeafWeightDevice adds or sets g.spec.Linux.Resources.BlockIO.WeightDevice.LeafWeight.
514+ func (g * Generator ) AddLinuxResourcesBlockIOLeafWeightDevice (major int64 , minor int64 , weight uint16 ) {
515+ g .initSpecLinuxResourcesBlockIO ()
516+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
517+ if weightDevice .Major == major && weightDevice .Minor == minor {
518+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ].LeafWeight = & weight
519+ return
520+ }
521+ }
522+ weightDevice := new (rspec.LinuxWeightDevice )
523+ weightDevice .Major = major
524+ weightDevice .Minor = minor
525+ weightDevice .LeafWeight = & weight
526+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice , * weightDevice )
527+ }
528+
529+ // DropLinuxResourcesBlockIOLeafWeightDevice drops a item form g.spec.Linux.Resources.BlockIO.WeightDevice.LeafWeight
530+ func (g * Generator ) DropLinuxResourcesBlockIOLeafWeightDevice (major int64 , minor int64 ) {
531+ g .initSpecLinuxResourcesBlockIO ()
532+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
533+ if weightDevice .Major == major && weightDevice .Minor == minor {
534+ if weightDevice .Weight != nil {
535+ newWeightDevice := new (rspec.LinuxWeightDevice )
536+ newWeightDevice .Major = major
537+ newWeightDevice .Minor = minor
538+ newWeightDevice .Weight = weightDevice .Weight
539+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ] = * newWeightDevice
540+ } else {
541+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice [:i ], g .spec .Linux .Resources .BlockIO .WeightDevice [i + 1 :]... )
542+ }
543+ return
544+ }
545+ }
546+ }
547+
548+ // SetLinuxResourcesBlockIOWeight sets g.spec.Linux.Resources.BlockIO.Weight.
549+ func (g * Generator ) SetLinuxResourcesBlockIOWeight (weight uint16 ) {
550+ g .initSpecLinuxResourcesBlockIO ()
551+ g .spec .Linux .Resources .BlockIO .Weight = & weight
552+ }
553+
554+ // AddLinuxResourcesBlockIOWeightDevice adds or sets g.spec.Linux.Resources.BlockIO.WeightDevice.Weight.
555+ func (g * Generator ) AddLinuxResourcesBlockIOWeightDevice (major int64 , minor int64 , weight uint16 ) {
556+ g .initSpecLinuxResourcesBlockIO ()
557+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
558+ if weightDevice .Major == major && weightDevice .Minor == minor {
559+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ].Weight = & weight
560+ return
561+ }
562+ }
563+ weightDevice := new (rspec.LinuxWeightDevice )
564+ weightDevice .Major = major
565+ weightDevice .Minor = minor
566+ weightDevice .Weight = & weight
567+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice , * weightDevice )
568+ }
569+
570+ // DropLinuxResourcesBlockIOWeightDevice drops a item form g.spec.Linux.Resources.BlockIO.WeightDevice.Weight
571+ func (g * Generator ) DropLinuxResourcesBlockIOWeightDevice (major int64 , minor int64 ) {
572+ g .initSpecLinuxResourcesBlockIO ()
573+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
574+ if weightDevice .Major == major && weightDevice .Minor == minor {
575+ if weightDevice .LeafWeight != nil {
576+ newWeightDevice := new (rspec.LinuxWeightDevice )
577+ newWeightDevice .Major = major
578+ newWeightDevice .Minor = minor
579+ newWeightDevice .LeafWeight = weightDevice .LeafWeight
580+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ] = * newWeightDevice
581+ } else {
582+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice [:i ], g .spec .Linux .Resources .BlockIO .WeightDevice [i + 1 :]... )
583+ }
584+ return
585+ }
586+ }
587+ }
588+
589+ // AddLinuxResourcesBlockIOThrottleReadBpsDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
590+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleReadBpsDevice (major int64 , minor int64 , rate uint64 ) {
591+ g .initSpecLinuxResourcesBlockIO ()
592+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice , major , minor , rate )
593+ g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice = throttleDevices
594+ }
595+
596+ // DropLinuxResourcesBlockIOThrottleReadBpsDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
597+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleReadBpsDevice (major int64 , minor int64 ) {
598+ g .initSpecLinuxResourcesBlockIO ()
599+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice , major , minor )
600+ g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice = throttleDevices
601+ }
602+
603+ // AddLinuxResourcesBlockIOThrottleReadIOPSDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
604+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleReadIOPSDevice (major int64 , minor int64 , rate uint64 ) {
605+ g .initSpecLinuxResourcesBlockIO ()
606+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice , major , minor , rate )
607+ g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice = throttleDevices
608+ }
609+
610+ // DropLinuxResourcesBlockIOThrottleReadIOPSDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
611+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleReadIOPSDevice (major int64 , minor int64 ) {
612+ g .initSpecLinuxResourcesBlockIO ()
613+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice , major , minor )
614+ g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice = throttleDevices
615+ }
616+
617+ // AddLinuxResourcesBlockIOThrottleWriteBpsDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
618+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleWriteBpsDevice (major int64 , minor int64 , rate uint64 ) {
619+ g .initSpecLinuxResourcesBlockIO ()
620+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice , major , minor , rate )
621+ g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice = throttleDevices
622+ }
623+
624+ // DropLinuxResourcesBlockIOThrottleWriteBpsDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
625+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleWriteBpsDevice (major int64 , minor int64 ) {
626+ g .initSpecLinuxResourcesBlockIO ()
627+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice , major , minor )
628+ g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice = throttleDevices
629+ }
630+
631+ // AddLinuxResourcesBlockIOThrottleWriteIOPSDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
632+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleWriteIOPSDevice (major int64 , minor int64 , rate uint64 ) {
633+ g .initSpecLinuxResourcesBlockIO ()
634+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice , major , minor , rate )
635+ g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice = throttleDevices
636+ }
637+
638+ // DropLinuxResourcesBlockIOThrottleWriteIOPSDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
639+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleWriteIOPSDevice (major int64 , minor int64 ) {
640+ g .initSpecLinuxResourcesBlockIO ()
641+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice , major , minor )
642+ g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice = throttleDevices
643+ }
644+
507645// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
508646func (g * Generator ) SetLinuxResourcesCPUShares (shares uint64 ) {
509647 g .initSpecLinuxResourcesCPU ()
@@ -1258,3 +1396,32 @@ func (g *Generator) AddLinuxReadonlyPaths(path string) {
12581396 g .initSpecLinux ()
12591397 g .spec .Linux .ReadonlyPaths = append (g .spec .Linux .ReadonlyPaths , path )
12601398}
1399+
1400+ func addOrReplaceBlockIOThrottleDevice (tmpList []rspec.LinuxThrottleDevice , major int64 , minor int64 , rate uint64 ) []rspec.LinuxThrottleDevice {
1401+ throttleDevices := tmpList
1402+ for i , throttleDevice := range throttleDevices {
1403+ if throttleDevice .Major == major && throttleDevice .Minor == minor {
1404+ throttleDevices [i ].Rate = rate
1405+ return throttleDevices
1406+ }
1407+ }
1408+ throttleDevice := new (rspec.LinuxThrottleDevice )
1409+ throttleDevice .Major = major
1410+ throttleDevice .Minor = minor
1411+ throttleDevice .Rate = rate
1412+ throttleDevices = append (throttleDevices , * throttleDevice )
1413+
1414+ return throttleDevices
1415+ }
1416+
1417+ func dropBlockIOThrottleDevice (tmpList []rspec.LinuxThrottleDevice , major int64 , minor int64 ) []rspec.LinuxThrottleDevice {
1418+ throttleDevices := tmpList
1419+ for i , throttleDevice := range throttleDevices {
1420+ if throttleDevice .Major == major && throttleDevice .Minor == minor {
1421+ throttleDevices = append (throttleDevices [:i ], throttleDevices [i + 1 :]... )
1422+ return throttleDevices
1423+ }
1424+ }
1425+
1426+ return throttleDevices
1427+ }
0 commit comments