[pve-devel] [PATCH v2 container 7/7] update: handle pool limits
Daniel Kral
d.kral at proxmox.com
Thu Dec 19 17:04:23 CET 2024
On 16/04/2024 14:20, Fabian Grünbichler wrote:
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
>
> Notes:
> v2:
> - don't multiply mem+swap, but add them up (thanks Dominik)
>
> src/PVE/API2/LXC/Config.pm | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
> index e6c0980..15fab61 100644
> --- a/src/PVE/API2/LXC/Config.pm
> +++ b/src/PVE/API2/LXC/Config.pm
> @@ -208,6 +208,27 @@ __PACKAGE__->register_method({
>
> my $running = PVE::LXC::check_running($vmid);
>
> + my $usage = PVE::LXC::Config->get_pool_usage($conf);
> + if (defined($param->{memory}) || defined($param->{swap})) {
> + my $old = $usage->{mem};
> + my $new = $param->{memory} || $usage->{memory};
> + $new += ($param->{swap} || $usage->{swap});
> +
> + if ($new > $old) {
> + my $change = { mem => ($new - $old) * 1024 * 1024 };
I haven't tested this exactly, but aren't $new and $old in different
magnitudes, i.e. bytes and MiB?
> + PVE::GuestHelpers::check_guest_pool_limit($vmid, $change);
> + }
> + }
> + if (defined($param->{cores})) {
> + my $old = $usage->{cpu};
> + my $new = $param->{cores};
> +
> + if ($new > $old) {
> + my $change = { cpu => ($new - $old) };
> + PVE::GuestHelpers::check_guest_pool_limit($vmid, $change);
> + }
> + }
> +
> my $errors = PVE::LXC::Config->update_pct_config($vmid, $conf, $running, $param, \@delete, \@revert);
> PVE::LXC::Config->write_config($vmid, $conf);
> $conf = PVE::LXC::Config->load_config($vmid);
> --
> 2.39.2
More information about the pve-devel
mailing list