mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-08-09 22:05:17 +00:00
rebalance_lxc_containers: fix hotplug
factor out code to modify cpusets into $modify_cpuset->()
This commit is contained in:
parent
193146f8b0
commit
0b959507c1
@ -234,6 +234,29 @@ sub rebalance_lxc_containers {
|
|||||||
my @cpu_ctcount = (0) x $max_cpuid;
|
my @cpu_ctcount = (0) x $max_cpuid;
|
||||||
my @balanced_cts;
|
my @balanced_cts;
|
||||||
|
|
||||||
|
my $modify_cpuset = sub {
|
||||||
|
my ($vmid, $cpuset, $newset) = @_;
|
||||||
|
|
||||||
|
syslog('info', "modified cpu set for lxc/$vmid: " .
|
||||||
|
$newset->short_string());
|
||||||
|
eval {
|
||||||
|
# allow all, so that we can set new cpuset in /ns
|
||||||
|
$all_cpus->write_to_cgroup("lxc/$vmid");
|
||||||
|
eval {
|
||||||
|
$newset->write_to_cgroup("lxc/$vmid/ns");
|
||||||
|
};
|
||||||
|
if (my $err = $@) {
|
||||||
|
warn $err;
|
||||||
|
# restore original
|
||||||
|
$cpuset->write_to_cgroup("lxc/$vmid");
|
||||||
|
} else {
|
||||||
|
# also apply to container root cgroup
|
||||||
|
$newset->write_to_cgroup("lxc/$vmid");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
warn $@ if $@;
|
||||||
|
};
|
||||||
|
|
||||||
my $ctlist = PVE::LXC::config_list();
|
my $ctlist = PVE::LXC::config_list();
|
||||||
|
|
||||||
foreach my $vmid (sort keys %$ctlist) {
|
foreach my $vmid (sort keys %$ctlist) {
|
||||||
@ -278,9 +301,7 @@ sub rebalance_lxc_containers {
|
|||||||
# Apply hot-plugged changes if any:
|
# Apply hot-plugged changes if any:
|
||||||
if (!$newset->is_equal($cpuset)) {
|
if (!$newset->is_equal($cpuset)) {
|
||||||
@cpuset_members = $newset->members();
|
@cpuset_members = $newset->members();
|
||||||
syslog('info', "detected changed cpu set for lxc/$vmid: " .
|
$modify_cpuset->($vmid, $cpuset, $newset);
|
||||||
$newset->short_string());
|
|
||||||
$newset->write_to_cgroup("lxc/$vmid");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Note: no need to rebalance if we already use all cores
|
# Note: no need to rebalance if we already use all cores
|
||||||
@ -332,24 +353,7 @@ sub rebalance_lxc_containers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$newset->is_equal($cpuset)) {
|
if (!$newset->is_equal($cpuset)) {
|
||||||
syslog('info', "modified cpu set for lxc/$vmid: " .
|
$modify_cpuset->($vmid, $cpuset, $newset);
|
||||||
$newset->short_string());
|
|
||||||
eval {
|
|
||||||
# allow all, so that we can set new cpuset in /ns
|
|
||||||
$all_cpus->write_to_cgroup("lxc/$vmid");
|
|
||||||
eval {
|
|
||||||
$newset->write_to_cgroup("lxc/$vmid/ns");
|
|
||||||
};
|
|
||||||
if (my $err = $@) {
|
|
||||||
warn $err;
|
|
||||||
# restore original
|
|
||||||
$cpuset->write_to_cgroup("lxc/$vmid");
|
|
||||||
} else {
|
|
||||||
# also apply to container root cgroup
|
|
||||||
$newset->write_to_cgroup("lxc/$vmid");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
warn $@ if $@;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user