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 8/9] api: importdisk: improve check if storage supports vm images
Date: Mon, 16 Sep 2024 18:38:38 +0200	[thread overview]
Message-ID: <20240916163839.236908-9-d.kral@proxmox.com> (raw)
In-Reply-To: <20240916163839.236908-1-d.kral@proxmox.com>

Adds a check in the API call `importovf` and improves the check in
`importdisk` if the target storage for the disk import supports the
content type 'images'. This will add parameter context when the check
fails and also adds a check right before allocating the disk that is
being imported.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 PVE/CLI/qm.pm                | 12 ++++++------
 PVE/QemuServer/ImportDisk.pm |  4 +++-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index d3dbf7b4..0f62cece 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -30,7 +30,7 @@ use PVE::API2::Qemu::Agent;
 use PVE::API2::Qemu;
 use PVE::QemuConfig;
 use PVE::QemuServer::Drive;
-use PVE::QemuServer::Helpers;
+use PVE::QemuServer::Helpers qw(check_storage_alloc check_volume_alloc);
 use PVE::QemuServer::Agent qw(agent_available);
 use PVE::QemuServer::ImportDisk;
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -595,11 +595,9 @@ __PACKAGE__->register_method ({
 	die "$source: non-existent or non-regular file\n" if (! -f $source);
 
 	my $storecfg = PVE::Storage::config();
-	PVE::Storage::storage_check_enabled($storecfg, $storeid);
 
-	my $target_storage_config =  PVE::Storage::storage_config($storecfg, $storeid);
-	die "storage $storeid does not support vm images\n"
-	    if !$target_storage_config->{content}->{images};
+	eval { check_volume_alloc($storecfg, $storeid) };
+	raise_param_exc({ storage => "$@" }) if $@;
 
 	print "importing disk '$source' to VM $vmid ...\n";
 	my ($drive_id, $volid) = PVE::QemuServer::ImportDisk::do_import($source, $vmid, $storeid, { format => $format });
@@ -727,7 +725,9 @@ __PACKAGE__->register_method ({
 
 	die "$ovf_file: non-existent or non-regular file\n" if (! -f $ovf_file);
 	my $storecfg = PVE::Storage::config();
-	PVE::Storage::storage_check_enabled($storecfg, $storeid);
+
+	eval { check_volume_alloc($storecfg, $storeid) };
+	raise_param_exc({ storage => "$@" }) if $@;
 
 	my $parsed = PVE::QemuServer::OVF::parse_ovf($ovf_file);
 
diff --git a/PVE/QemuServer/ImportDisk.pm b/PVE/QemuServer/ImportDisk.pm
index 132932ae..e32b7155 100755
--- a/PVE/QemuServer/ImportDisk.pm
+++ b/PVE/QemuServer/ImportDisk.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use PVE::Storage;
 use PVE::QemuServer;
+use PVE::QemuServer::Helpers qw(alloc_volume_disk);
 use PVE::Tools qw(run_command extract_param);
 
 # imports an external disk image to an existing VM
@@ -31,7 +32,8 @@ sub do_import {
     warn "format '$format' is not supported by the target storage - using '$dst_format' instead\n"
 	if $format && $format ne $dst_format;
 
-    my $dst_volid = PVE::Storage::vdisk_alloc($storecfg, $storage_id, $vmid, $dst_format, undef, $src_size / 1024);
+    my $dst_volid = alloc_volume_disk(
+	$storecfg, $storage_id, $vmid, $dst_format, undef, $src_size/1024);
 
     my $zeroinit = PVE::Storage::volume_has_feature($storecfg, 'sparseinit', $dst_volid);
 
-- 
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:39 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 ` [pve-devel] [RFC qemu-server 5/9] api: create_vm: improve checks if storages for disks support " Daniel Kral
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 6/9] cloudinit: add check if storage for cloudinit disk supports " 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 ` Daniel Kral [this message]
2024-09-16 16:38 ` [pve-devel] [RFC qemu-server 9/9] restore_vm: improve checks if storage supports " 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-9-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