@@ -32,18 +32,11 @@ func systemdCreate(resources *cgroups.Resources, path string, c *systemdDbus.Con
3232 systemdDbus .PropDescription ("cgroup " + name ),
3333 systemdDbus .PropWants (slice ),
3434 }
35- var ioString string
36- v2 , _ := IsCgroup2UnifiedMode ()
37- if v2 {
38- ioString = "IOAccounting"
39- } else {
40- ioString = "BlockIOAccounting"
41- }
4235 pMap := map [string ]bool {
4336 "DefaultDependencies" : false ,
4437 "MemoryAccounting" : true ,
4538 "CPUAccounting" : true ,
46- ioString : true ,
39+ "IOAccounting" : true ,
4740 }
4841 if i == 0 {
4942 pMap ["Delegate" ] = true
@@ -57,7 +50,7 @@ func systemdCreate(resources *cgroups.Resources, path string, c *systemdDbus.Con
5750 properties = append (properties , p )
5851 }
5952
60- uMap , sMap , bMap , iMap , structMap , err := resourcesToProps (resources , v2 )
53+ uMap , sMap , bMap , iMap , structMap , err := resourcesToProps (resources )
6154 if err != nil {
6255 lastError = err
6356 continue
@@ -150,7 +143,7 @@ func systemdDestroyConn(path string, c *systemdDbus.Conn) error {
150143 return nil
151144}
152145
153- func resourcesToProps (res * cgroups.Resources , v2 bool ) (map [string ]uint64 , map [string ]string , map [string ][]byte , map [string ]int64 , map [string ][]BlkioDev , error ) {
146+ func resourcesToProps (res * cgroups.Resources ) (map [string ]uint64 , map [string ]string , map [string ][]byte , map [string ]int64 , map [string ][]BlkioDev , error ) {
154147 bMap := make (map [string ][]byte )
155148 // this array is not used but will be once more resource limits are added
156149 sMap := make (map [string ]string )
@@ -176,13 +169,8 @@ func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[s
176169
177170 if res .CpuShares != 0 {
178171 // convert from shares to weight. weight only supports 1-10000
179- v2 , _ := IsCgroup2UnifiedMode ()
180- if v2 {
181- wt := (1 + ((res .CpuShares - 2 )* 9999 )/ 262142 )
182- uMap ["CPUWeight" ] = wt
183- } else {
184- uMap ["CPUShares" ] = res .CpuShares
185- }
172+ wt := (1 + ((res .CpuShares - 2 )* 9999 )/ 262142 )
173+ uMap ["CPUWeight" ] = wt
186174 }
187175
188176 // CPUSet
@@ -212,21 +200,15 @@ func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[s
212200 case res .Memory == - 1 || res .MemorySwap == - 1 :
213201 swap := - 1
214202 uMap ["MemorySwapMax" ] = uint64 (swap )
215- case v2 :
203+ default :
216204 // swap max = swap (limit + swap limit) - limit
217205 uMap ["MemorySwapMax" ] = uint64 (res .MemorySwap - res .Memory )
218- default :
219- uMap ["MemorySwapMax" ] = uint64 (res .MemorySwap )
220206 }
221207 }
222208
223209 // Blkio
224210 if res .BlkioWeight > 0 {
225- if v2 {
226- uMap ["IOWeight" ] = uint64 (res .BlkioWeight )
227- } else {
228- uMap ["BlockIOWeight" ] = uint64 (res .BlkioWeight )
229- }
211+ uMap ["IOWeight" ] = uint64 (res .BlkioWeight )
230212 }
231213
232214 // systemd requires the paths to be in the form /dev/{block, char}/major:minor
@@ -238,11 +220,7 @@ func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[s
238220 Device : fmt .Sprintf ("/dev/block/%d:%d" , entry .Major , entry .Minor ),
239221 Bytes : entry .Rate ,
240222 }
241- if v2 {
242- structMap ["IOReadBandwidthMax" ] = append (structMap ["IOReadBandwidthMax" ], newThrottle )
243- } else {
244- structMap ["BlockIOReadBandwidth" ] = append (structMap ["BlockIOReadBandwidth" ], newThrottle )
245- }
223+ structMap ["IOReadBandwidthMax" ] = append (structMap ["IOReadBandwidthMax" ], newThrottle )
246224 }
247225 }
248226
@@ -252,11 +230,7 @@ func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[s
252230 Device : fmt .Sprintf ("/dev/block/%d:%d" , entry .Major , entry .Minor ),
253231 Bytes : entry .Rate ,
254232 }
255- if v2 {
256- structMap ["IOWriteBandwidthMax" ] = append (structMap ["IOWriteBandwidthMax" ], newThrottle )
257- } else {
258- structMap ["BlockIOWriteBandwidth" ] = append (structMap ["BlockIOWriteBandwidth" ], newThrottle )
259- }
233+ structMap ["IOWriteBandwidthMax" ] = append (structMap ["IOWriteBandwidthMax" ], newThrottle )
260234 }
261235 }
262236
@@ -266,11 +240,7 @@ func resourcesToProps(res *cgroups.Resources, v2 bool) (map[string]uint64, map[s
266240 Device : fmt .Sprintf ("/dev/block/%d:%d" , entry .Major , entry .Minor ),
267241 Bytes : uint64 (entry .Weight ),
268242 }
269- if v2 {
270- structMap ["IODeviceWeight" ] = append (structMap ["IODeviceWeight" ], newWeight )
271- } else {
272- structMap ["BlockIODeviceWeight" ] = append (structMap ["BlockIODeviceWeight" ], newWeight )
273- }
243+ structMap ["IODeviceWeight" ] = append (structMap ["IODeviceWeight" ], newWeight )
274244 }
275245 }
276246
0 commit comments