public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC qemu-server 5/9] api: create_vm: improve checks if storages for disks support vm images
Date: Mon, 16 Sep 2024 18:38:35 +0200	[thread overview]
Message-ID: <20240916163839.236908-6-d.kral@proxmox.com> (raw)
In-Reply-To: <20240916163839.236908-1-d.kral@proxmox.com>

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 <d.kral@proxmox.com>
---
 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


  parent reply	other threads:[~2024-09-16 16:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 16:38 [pve-devel] [RFC qemu-server 0/9] consistent checks for storage content types on volume disk allocation Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 1/9] test: cfg2cmd: expect error for invalid volume's storage content type Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 2/9] cfg2cmd: improve error message for invalid volume " Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 3/9] fix #5284: move_vm: add check if target storage supports vm images Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 4/9] api: clone_vm: add check if " Daniel Kral
2024-09-16 16:38 ` Daniel Kral [this message]
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 6/9] cloudinit: add check if storage for cloudinit disk " Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 7/9] api: migrate_vm: improve check if target storages support " Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 8/9] api: importdisk: improve check if storage supports " Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 9/9] restore_vm: improve checks " Daniel Kral

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240916163839.236908-6-d.kral@proxmox.com \
    --to=d.kral@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal