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 CEA2F1FF16B for ; Mon, 16 Sep 2024 18:39:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 08A95BA3D; Mon, 16 Sep 2024 18:39:18 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Mon, 16 Sep 2024 18:38:38 +0200 Message-Id: <20240916163839.236908-9-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 8/9] api: importdisk: improve check if storage supports 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 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 --- 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