]> git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/CGroup.pm
migrate: also set targetsid for unreferenced disks
[pve-container.git] / src / PVE / LXC / CGroup.pm
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 #
7 # Note that the long term plan is to have resource manage functions instead of
8 # dealing with cgroup files on the outside.
9
10 package PVE::LXC::CGroup;
11
12 use strict;
13 use warnings;
14
15 use PVE::LXC::Command;
16 use PVE::CGroup;
17 use base('PVE::CGroup');
18
19
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.
28 sub get_subdir {
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
56 1;