Mount cgroupfs if needed and return cgroup version cgcontrol: cgroup controllers to check ('cpu cpuacct cpuset') Returns: 'cgroup' | 'cgroup2'
( cgcontrol='cpu cpuacct cpuset' )
| 550 | # pylint: enable=broad-except |
| 551 | |
| 552 | def mountCgroups( cgcontrol='cpu cpuacct cpuset' ): |
| 553 | """Mount cgroupfs if needed and return cgroup version |
| 554 | cgcontrol: cgroup controllers to check ('cpu cpuacct cpuset') |
| 555 | Returns: 'cgroup' | 'cgroup2' """ |
| 556 | # Try to read the cgroup controllers in cgcontrol |
| 557 | cglist = cgcontrol.split() |
| 558 | paths = ' '.join( '-g ' + c for c in cglist ) |
| 559 | cmd = 'cgget -n %s /' % paths |
| 560 | result = errRun( cmd ) |
| 561 | # If it failed, mount cgroupfs and retry |
| 562 | if result.ret or result.err or any( |
| 563 | c not in result.out for c in cglist ): |
| 564 | errFail( 'cgroupfs-mount' ) |
| 565 | result = errRun( cmd ) |
| 566 | errFail( cmd ) |
| 567 | # cpu.cfs_period_us is used for cgroup but not cgroup2 |
| 568 | if 'cpu.cfs_period_us' in result.out: |
| 569 | return 'cgroup' |
| 570 | return 'cgroup2' |
| 571 | |
| 572 | def natural( text ): |
| 573 | "To sort sanely/alphabetically: sorted( l, key=natural )" |