Make use of the newly introduced content type assertion helpers in the
preconditions check paths and the call to `vdisk_alloc` in the API
handlers for creating a VM or updating a VM with newly allocated VM,
EFI, TPM and/or cloudinit images.

Since the preconditions existed before, adding a content type safeguard
at `vdisk_alloc` does not break the API.

Signed-off-by: Daniel Kral <d.k...@proxmox.com>
---
changes since v1:
- squashed previous rfc patch #5 and #6 as they are very related to
  another and also made explicit notice of changes to `update_vm` api

 PVE/API2/Qemu.pm            | 14 +++++++++-----
 PVE/QemuServer.pm           |  4 +++-
 PVE/QemuServer/Cloudinit.pm |  1 +
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8ce266a3..ea164eea 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -150,9 +150,8 @@ my $check_storage_access = sub {
            $rpcenv->check($authuser, "/", ['Sys.Console']);
        } elsif (!$isCDROM && ($volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE 
|| $is_cloudinit)) {
            $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};
+           eval { PVE::Storage::assert_content_type_supported($storecfg, 
$storeid, 'images') };
+           raise_param_exc({ storage => "$@" }) if $@;
        } else {
            PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, 
$vmid, $volid);
            if ($storeid) {
@@ -416,6 +415,7 @@ my sub create_disks : prototype($$$$$$$$$$$) {
            my $ci_size = PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE;
            my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, 
$fmt, $ci_size/1024, {
                name => $name,
+               vtype => 'images',
            });
            $disk->{file} = $volid;
            $disk->{media} = 'cdrom';
@@ -554,9 +554,13 @@ 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', $size);
+                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, 
$vmid, 'raw', $size, {
+                       vtype => 'images',
+                   });
                } else {
-                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, 
$vmid, $fmt, $size);
+                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, 
$vmid, $fmt, $size, {
+                       vtype => 'images',
+                   });
                }
 
                # change created disk to a base volume in case the VM is a 
template
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0cc3285f..f3178655 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -8372,7 +8372,9 @@ 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, 
$vars_size);
+    my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, 
$vars_size, {
+       vtype => 'images',
+    });
     PVE::Storage::activate_volumes($storecfg, [$volid]);
 
     qemu_img_convert($ovmf_vars, $volid, $vars_size_b, undef, 0);
diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index 0dc99e05..a566e811 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -46,6 +46,7 @@ sub commit_cloudinit_disk {
        $size = 4 * 1024;
        PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $size, {
            name => $name,
+           vtype => 'images',
        });
        $size *= 1024; # vdisk alloc takes KB, qemu-img dd's osize takes byte
     }
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to