@@ -30,12 +30,22 @@ func getDeviceID(id string) (int64, int64, error) {
3030}
3131
3232// GetBlockIOData gets cgroup blockio data
33- func (cg * CgroupV1 ) GetBlockIOData (cgPath string ) (* rspec.LinuxBlockIO , error ) {
33+ func (cg * CgroupV1 ) GetBlockIOData (pid int , cgPath string ) (* rspec.LinuxBlockIO , error ) {
3434 lb := & rspec.LinuxBlockIO {}
3535 names := []string {"weight" , "leaf_weight" , "weight_device" , "leaf_weight_device" , "throttle.read_bps_device" , "throttle.write_bps_device" , "throttle.read_iops_device" , "throttle.write_iops_device" }
3636 for i , name := range names {
3737 fileName := strings .Join ([]string {"blkio" , name }, "." )
3838 filePath := filepath .Join (cg .MountPath , "blkio" , cgPath , fileName )
39+ if ! filepath .IsAbs (cgPath ) {
40+ subPath , err := GetSubsystemPath (pid , "blkio" )
41+ if err != nil {
42+ return nil , err
43+ }
44+ if ! strings .Contains (subPath , RelCgroupPath ) {
45+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "blkio" )
46+ }
47+ filePath = filepath .Join (cg .MountPath , "blkio" , subPath , fileName )
48+ }
3949 contents , err := ioutil .ReadFile (filePath )
4050 if err != nil {
4151 return nil , err
@@ -182,12 +192,22 @@ func (cg *CgroupV1) GetBlockIOData(cgPath string) (*rspec.LinuxBlockIO, error) {
182192}
183193
184194// GetCPUData gets cgroup cpus data
185- func (cg * CgroupV1 ) GetCPUData (cgPath string ) (* rspec.LinuxCPU , error ) {
195+ func (cg * CgroupV1 ) GetCPUData (pid int , cgPath string ) (* rspec.LinuxCPU , error ) {
186196 lc := & rspec.LinuxCPU {}
187197 names := []string {"shares" , "cfs_quota_us" , "cfs_period_us" }
188198 for i , name := range names {
189199 fileName := strings .Join ([]string {"cpu" , name }, "." )
190200 filePath := filepath .Join (cg .MountPath , "cpu" , cgPath , fileName )
201+ if ! filepath .IsAbs (cgPath ) {
202+ subPath , err := GetSubsystemPath (pid , "cpu" )
203+ if err != nil {
204+ return nil , err
205+ }
206+ if ! strings .Contains (subPath , RelCgroupPath ) {
207+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "cpu" )
208+ }
209+ filePath = filepath .Join (cg .MountPath , "cpu" , subPath , fileName )
210+ }
191211 contents , err := ioutil .ReadFile (filePath )
192212 if err != nil {
193213 return nil , err
@@ -241,6 +261,16 @@ func (cg *CgroupV1) GetCPUData(cgPath string) (*rspec.LinuxCPU, error) {
241261 for i , name := range names {
242262 fileName := strings .Join ([]string {"cpuset" , name }, "." )
243263 filePath := filepath .Join (cg .MountPath , "cpuset" , cgPath , fileName )
264+ if ! filepath .IsAbs (cgPath ) {
265+ subPath , err := GetSubsystemPath (pid , "cpuset" )
266+ if err != nil {
267+ return nil , err
268+ }
269+ if ! strings .Contains (subPath , RelCgroupPath ) {
270+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "cpuset" )
271+ }
272+ filePath = filepath .Join (cg .MountPath , "cpuset" , subPath , fileName )
273+ }
244274 contents , err := ioutil .ReadFile (filePath )
245275 if err != nil {
246276 return nil , err
@@ -257,7 +287,7 @@ func (cg *CgroupV1) GetCPUData(cgPath string) (*rspec.LinuxCPU, error) {
257287}
258288
259289// GetDevicesData gets cgroup devices data
260- func (cg * CgroupV1 ) GetDevicesData (cgPath string ) ([]rspec.LinuxDeviceCgroup , error ) {
290+ func (cg * CgroupV1 ) GetDevicesData (pid int , cgPath string ) ([]rspec.LinuxDeviceCgroup , error ) {
261291 ld := []rspec.LinuxDeviceCgroup {}
262292
263293 return ld , nil
@@ -318,7 +348,7 @@ func getHugePageSize() ([]string, error) {
318348}
319349
320350// GetHugepageLimitData gets cgroup hugetlb data
321- func (cg * CgroupV1 ) GetHugepageLimitData (cgPath string ) ([]rspec.LinuxHugepageLimit , error ) {
351+ func (cg * CgroupV1 ) GetHugepageLimitData (pid int , cgPath string ) ([]rspec.LinuxHugepageLimit , error ) {
322352 lh := []rspec.LinuxHugepageLimit {}
323353 pageSizes , err := getHugePageSize ()
324354 if err != nil {
@@ -327,6 +357,16 @@ func (cg *CgroupV1) GetHugepageLimitData(cgPath string) ([]rspec.LinuxHugepageLi
327357 for _ , pageSize := range pageSizes {
328358 maxUsage := strings .Join ([]string {"hugetlb" , pageSize , "limit_in_bytes" }, "." )
329359 filePath := filepath .Join (cg .MountPath , "hugetlb" , cgPath , maxUsage )
360+ if ! filepath .IsAbs (cgPath ) {
361+ subPath , err := GetSubsystemPath (pid , "hugetlb" )
362+ if err != nil {
363+ return lh , err
364+ }
365+ if ! strings .Contains (subPath , RelCgroupPath ) {
366+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "hugetlb" )
367+ }
368+ filePath = filepath .Join (cg .MountPath , "hugetlb" , subPath , maxUsage )
369+ }
330370 contents , err := ioutil .ReadFile (filePath )
331371 if err != nil {
332372 return lh , err
@@ -345,12 +385,22 @@ func (cg *CgroupV1) GetHugepageLimitData(cgPath string) ([]rspec.LinuxHugepageLi
345385}
346386
347387// GetMemoryData gets cgroup memory data
348- func (cg * CgroupV1 ) GetMemoryData (cgPath string ) (* rspec.LinuxMemory , error ) {
388+ func (cg * CgroupV1 ) GetMemoryData (pid int , cgPath string ) (* rspec.LinuxMemory , error ) {
349389 lm := & rspec.LinuxMemory {}
350390 names := []string {"limit_in_bytes" , "soft_limit_in_bytes" , "memsw.limit_in_bytes" , "kmem.limit_in_bytes" , "kmem.tcp.limit_in_bytes" , "swappiness" , "oom_control" }
351391 for i , name := range names {
352392 fileName := strings .Join ([]string {"memory" , name }, "." )
353393 filePath := filepath .Join (cg .MountPath , "memory" , cgPath , fileName )
394+ if ! filepath .IsAbs (cgPath ) {
395+ subPath , err := GetSubsystemPath (pid , "memory" )
396+ if err != nil {
397+ return nil , err
398+ }
399+ if ! strings .Contains (subPath , RelCgroupPath ) {
400+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "memory" )
401+ }
402+ filePath = filepath .Join (cg .MountPath , "memory" , subPath , fileName )
403+ }
354404 contents , err := ioutil .ReadFile (filePath )
355405 if err != nil {
356406 return nil , err
@@ -417,10 +467,20 @@ func (cg *CgroupV1) GetMemoryData(cgPath string) (*rspec.LinuxMemory, error) {
417467}
418468
419469// GetNetworkData gets cgroup network data
420- func (cg * CgroupV1 ) GetNetworkData (cgPath string ) (* rspec.LinuxNetwork , error ) {
470+ func (cg * CgroupV1 ) GetNetworkData (pid int , cgPath string ) (* rspec.LinuxNetwork , error ) {
421471 ln := & rspec.LinuxNetwork {}
422472 fileName := strings .Join ([]string {"net_cls" , "classid" }, "." )
423473 filePath := filepath .Join (cg .MountPath , "net_cls" , cgPath , fileName )
474+ if ! filepath .IsAbs (cgPath ) {
475+ subPath , err := GetSubsystemPath (pid , "net_cls" )
476+ if err != nil {
477+ return nil , err
478+ }
479+ if ! strings .Contains (subPath , RelCgroupPath ) {
480+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "net_cls" )
481+ }
482+ filePath = filepath .Join (cg .MountPath , "net_cls" , subPath , fileName )
483+ }
424484 contents , err := ioutil .ReadFile (filePath )
425485 if err != nil {
426486 return nil , err
@@ -434,6 +494,16 @@ func (cg *CgroupV1) GetNetworkData(cgPath string) (*rspec.LinuxNetwork, error) {
434494
435495 fileName = strings .Join ([]string {"net_prio" , "ifpriomap" }, "." )
436496 filePath = filepath .Join (cg .MountPath , "net_prio" , cgPath , fileName )
497+ if ! filepath .IsAbs (cgPath ) {
498+ subPath , err := GetSubsystemPath (pid , "net_prio" )
499+ if err != nil {
500+ return nil , err
501+ }
502+ if ! strings .Contains (subPath , RelCgroupPath ) {
503+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "net_prio" )
504+ }
505+ filePath = filepath .Join (cg .MountPath , "net_prio" , subPath , fileName )
506+ }
437507 contents , err = ioutil .ReadFile (filePath )
438508 if err != nil {
439509 return nil , err
@@ -455,10 +525,20 @@ func (cg *CgroupV1) GetNetworkData(cgPath string) (*rspec.LinuxNetwork, error) {
455525}
456526
457527// GetPidsData gets cgroup pids data
458- func (cg * CgroupV1 ) GetPidsData (cgPath string ) (* rspec.LinuxPids , error ) {
528+ func (cg * CgroupV1 ) GetPidsData (pid int , cgPath string ) (* rspec.LinuxPids , error ) {
459529 lp := & rspec.LinuxPids {}
460530 fileName := strings .Join ([]string {"pids" , "max" }, "." )
461531 filePath := filepath .Join (cg .MountPath , "pids" , cgPath , fileName )
532+ if ! filepath .IsAbs (cgPath ) {
533+ subPath , err := GetSubsystemPath (pid , "pids" )
534+ if err != nil {
535+ return nil , err
536+ }
537+ if ! strings .Contains (subPath , RelCgroupPath ) {
538+ return nil , fmt .Errorf ("cgroup subsystem %s is not mounted as expected" , "pids" )
539+ }
540+ filePath = filepath .Join (cg .MountPath , "pids" , subPath , fileName )
541+ }
462542 contents , err := ioutil .ReadFile (filePath )
463543 if err != nil {
464544 return nil , err
0 commit comments