]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/CGroup.pm
backup: log errors from rsync
[pve-container.git] / src / PVE / LXC / CGroup.pm
CommitLineData
80c7e72f
WB
1# cgroup handler
2#
3# This package should deal with figuring out the right cgroup path for a
4# container (via the command socket), reading and writing cgroup values, and
5# handling cgroup v1 & v2 differences.
6#
6973a214 7# Note that the long term plan is to have resource manage functions instead of
80c7e72f
WB
8# dealing with cgroup files on the outside.
9
10package PVE::LXC::CGroup;
11
12use strict;
13use warnings;
14
15use PVE::LXC::Command;
c48a2545
AD
16use PVE::CGroup;
17use base('PVE::CGroup');
80c7e72f 18
1f37e0d2 19
80c7e72f
WB
20# Get a subdirectory (without the cgroup mount point) for a controller.
21#
22# If `$controller` is `undef`, get the unified (cgroupv2) path.
23#
24# Note that in cgroup v2, lxc uses the activated controller names
25# (`cgroup.controllers` file) as list of controllers for the unified hierarchy,
26# so this returns a result when a `controller` is provided even when using
27# a pure cgroupv2 setup.
c48a2545 28sub get_subdir {
80c7e72f
WB
29 my ($self, $controller, $limiting) = @_;
30
31 my $entry_name = $controller || 'unified';
32 my $entry = ($self->{controllers}->{$entry_name} //= {});
33
34 my $kind = $limiting ? 'limit' : 'ns';
35 my $path = $entry->{$kind};
36
37 return $path if defined $path;
38
39 $path = PVE::LXC::Command::get_cgroup_path(
40 $self->{vmid},
41 $controller,
42 $limiting,
43 ) or return undef;
44
45 # untaint:
46 if ($path =~ /\.\./) {
47 die "lxc returned suspicious path: '$path'\n";
48 }
49 ($path) = ($path =~ /^(.*)$/s);
50
51 $entry->{$kind} = $path;
52
53 return $path;
54}
55
80c7e72f 561;