]> git.proxmox.com Git - pve-container.git/commitdiff
update_lxc_config: cgroupv2 support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 3 Apr 2020 14:37:24 +0000 (16:37 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 4 Apr 2020 17:39:02 +0000 (19:39 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/LXC.pm

index df52afada999f9d01e10c52230f8bc699ecb74a7..b6327bc9138a9a0b18f94d63a746bd02add4e845 100644 (file)
@@ -737,28 +737,30 @@ sub update_lxc_config {
        $raw .= "lxc.net.$ind.mtu = $d->{mtu}\n" if defined($d->{mtu});
     }
 
-    if ($cgv1->{cpuset}) {
-       my $had_cpuset = 0;
-       if (my $lxcconf = $conf->{lxc}) {
-           foreach my $entry (@$lxcconf) {
-               my ($k, $v) = @$entry;
-               $had_cpuset = 1 if $k eq 'lxc.cgroup.cpuset.cpus';
-               $raw .= "$k = $v\n";
-           }
+    my $had_cpuset = 0;
+    if (my $lxcconf = $conf->{lxc}) {
+       foreach my $entry (@$lxcconf) {
+           my ($k, $v) = @$entry;
+           $had_cpuset = 1 if $k eq 'lxc.cgroup.cpuset.cpus';
+           $raw .= "$k = $v\n";
        }
+    }
 
-       my $cores = $conf->{cores};
-       if (!$had_cpuset && $cores) {
-           my $cpuset = eval { PVE::CpuSet->new_from_cgroup('lxc', 'effective_cpus') };
-           $cpuset = PVE::CpuSet->new_from_cgroup('', 'effective_cpus') if !$cpuset;
-           my @members = $cpuset->members();
-           while (scalar(@members) > $cores) {
-               my $randidx = int(rand(scalar(@members)));
-               $cpuset->delete($members[$randidx]);
-               splice(@members, $randidx, 1); # keep track of the changes
-           }
-           $raw .= "lxc.cgroup.cpuset.cpus = ".$cpuset->short_string()."\n";
+    my $cpuset;
+    my $cpuset_cgroup = eval { PVE::LXC::CGroup::cpuset_controller_path() };
+    if (defined($cpuset_cgroup)) {
+       $cpuset = eval { PVE::CpuSet->new_from_path("$cpuset_cgroup/lxc", 1) }
+           || PVE::CpuSet->new_from_path($cpuset_cgroup, 1);
+    }
+    my $cores = $conf->{cores};
+    if (!$had_cpuset && $cores && $cpuset) {
+       my @members = $cpuset->members();
+       while (scalar(@members) > $cores) {
+           my $randidx = int(rand(scalar(@members)));
+           $cpuset->delete($members[$randidx]);
+           splice(@members, $randidx, 1); # keep track of the changes
        }
+       $raw .= "lxc.cgroup.cpuset.cpus = ".$cpuset->short_string()."\n";
     }
 
     File::Path::mkpath("$dir/rootfs");