as early as possible, to avoid having to undo expensive work or allowing a window for limit exhaustion..
Signed-off-by: Fabian Grünbichler <f.gruenbich...@proxmox.com> --- PVE/API2/Qemu.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 497987ff..078a487e 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -229,6 +229,26 @@ my $check_storage_access_migrate = sub { if !$scfg->{content}->{images}; }; +my $check_pool_limits_create = sub { + my ($vmid, $conf, $running, $pool) = @_; + if ($pool) { + my $usage = PVE::QemuConfig->get_pool_usage($conf); + my $changes = { + cpu => $usage->{cpu}, + mem => $usage->{mem}, + absolute => 1, # in case this is an in-place restore + }; + PVE::GuestHelpers::check_guest_pool_limit($vmid, $changes, $pool); + if ($running) { + $changes->{running} = 1; + $changes->{cpu} = $conf->{vcpus} + if $conf->{vcpus} && $conf->{vcpus} < $changes->{cpu}; + PVE::GuestHelpers::check_guest_pool_limit($vmid, $changes, $pool); + } + } +}; + + my $import_from_volid = sub { my ($storecfg, $src_volid, $dest_info, $vollist) = @_; @@ -1041,6 +1061,7 @@ __PACKAGE__->register_method({ warn "Skipping early checks!\n"; } else { PVE::QemuServer::check_restore_permissions($rpcenv, $authuser, $merged); + $check_pool_limits_create->($vmid, $merged, $live_restore || $start_after_create, $pool); } } if ($archive->{type} eq 'file' || $archive->{type} eq 'pipe') { @@ -1085,6 +1106,7 @@ __PACKAGE__->register_method({ my $realcmd = sub { my $conf = $param; + $check_pool_limits_create->($vmid, $conf, $live_restore || $start_after_create, $pool); my $arch = PVE::QemuServer::get_vm_arch($conf); for my $opt (sort keys $param->%*) { @@ -3786,6 +3808,8 @@ __PACKAGE__->register_method({ my ($conffile, $newconf, $oldconf, $vollist, $drives, $fullclone) = $load_and_check->(); my $storecfg = PVE::Storage::config(); + $check_pool_limits_create->($newid, $newconf, 0, $pool); + # auto generate a new uuid my $smbios1 = PVE::QemuServer::parse_smbios1($newconf->{smbios1} || ''); $smbios1->{uuid} = PVE::QemuServer::generate_uuid(); -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel