to avoid repeating those calculations all over the place. Signed-off-by: Fabian Grünbichler <f.gruenbich...@proxmox.com> --- src/PVE/LXC/Config.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 1664a35..a6baccd 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -11,6 +11,7 @@ use PVE::DataCenterConfig; use PVE::GuestHelpers; use PVE::INotify; use PVE::JSONSchema qw(get_standard_option); +use PVE::ProcFSTools; use PVE::Tools; use PVE::LXC; @@ -1886,4 +1887,38 @@ sub foreach_passthrough_device { } } +my $cpuinfo = PVE::ProcFSTools::read_cpuinfo(); + +# for determining pool usage vs limits +# +# this gives the higher of pending or currently configured +sub get_pool_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->{cpu} = $get_max->( + $conf->{pending}->{cores}, + $conf->{cores}, + ); + $usage->{cpu} = $cpuinfo->{cpus} if !$usage->{cpu}; + + my $swap = $get_max->($conf->{pending}->{swap}, $conf->{swap}); + my $mem = $get_max->($conf->{pending}->{memory}, $conf->{memory}, 512); + $usage->{mem} = $mem+$swap; + $usage->{mem} *= 1024*1024; + + return $usage; +} + 1; -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel