From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 942151FF16B for ; Mon, 16 Sep 2024 18:38:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 804E8B834; Mon, 16 Sep 2024 18:38:47 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Mon, 16 Sep 2024 18:38:35 +0200 Message-Id: <20240916163839.236908-6-d.kral@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916163839.236908-1-d.kral@proxmox.com> References: <20240916163839.236908-1-d.kral@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC qemu-server 5/9] api: create_vm: improve checks if storages for disks support vm images X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Adds checks when creating regular volume disks, the EFI disk and the TPM state disk if the underlying storage for these disks support the content type 'images'. This adds parameter context to the error message and checks right before allocating the disk with `alloc_volume_disk`. This affects the behavior when creating disks through the create vm api (`create_disks`) and inadvertently when updating the VM configuration (`update_vm_api`). Signed-off-by: Daniel Kral --- PVE/API2/Qemu.pm | 18 +++++++++--------- PVE/QemuServer.pm | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index a7931d98..b6bfd68e 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -29,7 +29,7 @@ use PVE::QemuServer; use PVE::QemuServer::Cloudinit; use PVE::QemuServer::CPUConfig; use PVE::QemuServer::Drive; -use PVE::QemuServer::Helpers qw(check_storage_alloc check_volume_alloc); +use PVE::QemuServer::Helpers qw(check_storage_alloc check_volume_alloc alloc_volume_disk); use PVE::QemuServer::ImportDisk; use PVE::QemuServer::Monitor qw(mon_cmd); use PVE::QemuServer::Machine; @@ -147,10 +147,10 @@ my $check_storage_access = sub { } elsif (!$isCDROM && ($volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE)) { my ($storeid, $size) = ($2 || $default_storage, $3); die "no storage ID specified (and no default storage)\n" if !$storeid; - $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']); - my $scfg = PVE::Storage::storage_config($storecfg, $storeid); - raise_param_exc({ storage => "storage '$storeid' does not support vm images"}) - if !$scfg->{content}->{images}; + + check_storage_alloc($rpcenv, $authuser, $storeid); + eval { check_volume_alloc($storecfg, $storeid) }; + raise_param_exc({ storage => "$@" }) if $@; } else { PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $volid); if ($storeid) { @@ -402,7 +402,7 @@ my sub create_disks : prototype($$$$$$$$$$) { my ($storeid, $size) = ($2 || $default_storage, $3); die "no storage ID specified (and no default storage)\n" if !$storeid; - $size = PVE::Tools::convert_size($size, 'gb' => 'kb'); # vdisk_alloc uses kb + $size = PVE::Tools::convert_size($size, 'gb' => 'kb'); # alloc_volume_disk uses kb my $live_import = $is_live_import && $ds ne 'efidisk0'; my $needs_creation = 1; @@ -465,7 +465,7 @@ my sub create_disks : prototype($$$$$$$$$$) { } if ($needs_creation) { - $size = PVE::Tools::convert_size($size, 'b' => 'kb'); # vdisk_alloc uses kb + $size = PVE::Tools::convert_size($size, 'b' => 'kb'); # alloc_volume_disk uses kb } else { $disk->{file} = $dst_volid; $disk->{size} = $size; @@ -486,9 +486,9 @@ my sub create_disks : prototype($$$$$$$$$$) { } elsif ($ds eq 'tpmstate0') { # swtpm can only use raw volumes, and uses a fixed size $size = PVE::Tools::convert_size(PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE, 'b' => 'kb'); - $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, "raw", undef, $size); + $volid = alloc_volume_disk($storecfg, $storeid, $vmid, "raw", undef, $size); } else { - $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size); + $volid = alloc_volume_disk($storecfg, $storeid, $vmid, $fmt, undef, $size); } push @$vollist, $volid; $disk->{file} = $volid; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 507932d3..b40f6f6e 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -8449,7 +8449,7 @@ sub create_efidisk($$$$$$$) { my $vars_size_b = -s $ovmf_vars; my $vars_size = PVE::Tools::convert_size($vars_size_b, 'b' => 'kb'); - my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size); + my $volid = alloc_volume_disk($storecfg, $storeid, $vmid, $fmt, undef, $vars_size); PVE::Storage::activate_volumes($storecfg, [$volid]); qemu_img_convert($ovmf_vars, $volid, $vars_size_b, undef, 0); -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel