[pve-devel] [PATCH v2 qemu-server 1/6] config: add pool usage helper
Daniel Kral
d.kral at proxmox.com
Thu Dec 19 17:08:07 CET 2024
On 16/04/2024 14:20, Fabian Grünbichler wrote:
> determining the usage values for the current config. pending values are taken
> into account if they are higher than the current value only, else it would be
> possible to easily circumvent config limits by setting non-hotpluggable pending
> values.
>
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
> PVE/QemuConfig.pm | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
> index 8e8a7828..1410bf14 100644
> --- a/PVE/QemuConfig.pm
> +++ b/PVE/QemuConfig.pm
> @@ -573,4 +573,34 @@ sub has_cloudinit {
> return $found;
> }
>
> +# for determining pool usage vs limits
> +#
> +# this gives the higher of pending or currently configured
> +sub get_pool_usage {
similar comment as for the pve-container: would it make sense to rename
this sub to `get_configured_vm_usage`?
> + my ($class, $conf) = @_;
> +
> + my $usage = {};
> +
> + my $get_max = sub {
> + my $max = 0;
> +
> + for my $curr (@_) {
> + $max = $curr if defined($curr) && $curr > $max;
> + }
> +
> + return $max;
> + };
> +
> + $usage->{sockets} = $get_max->($conf->{pending}->{sockets}, $conf->{sockets}, 1);
> + $usage->{cores} = $get_max->($conf->{pending}->{cores}, $conf->{cores}, 1);
> + $usage->{cpu} = $usage->{sockets} * $usage->{cores};
nit: same as for pve-container, we could name this 'cpus' just for
consistency's sake (as 'cpu' holds the cpu usage % and 'cpus' the
amount of cores).
> + $usage->{mem} = $get_max->(
> + get_current_memory($conf->{pending}->{memory}),
> + get_current_memory($conf->{memory})
> + );
> + $usage->{mem} *= 1024*1024;
> +
> + return $usage;
> +}
> +
> 1;
> --
> 2.39.2
More information about the pve-devel
mailing list