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 289861FF16B for ; Mon, 16 Sep 2024 18:39:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0ED49B948; Mon, 16 Sep 2024 18:39:17 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Mon, 16 Sep 2024 18:38:34 +0200 Message-Id: <20240916163839.236908-5-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 4/9] api: clone_vm: add 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 when cloning a disk if the underlying storage, where the disk should be cloned to, supports the content type 'images'. This happens first when using the clone vm api and right before doing the disk allocation. Without this check, a vm could be cloned to an arbitrary storage and then failed to start if the storage does not support vm images. This will restrict the allocation of disk images when moving between storages (api call `move_vm_disk`), cloning a vm (api call `clone_vm`) and importint EFI disks and/or non-live disk imports (`create_disks`). Signed-off-by: Daniel Kral --- PVE/API2/Qemu.pm | 5 +++-- PVE/QemuServer.pm | 6 ++---- PVE/QemuServer/Helpers.pm | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 0cb4af89..a7931d98 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -3737,8 +3737,9 @@ __PACKAGE__->register_method({ my $storecfg = PVE::Storage::config(); if ($storage) { - # check if storage is enabled on local node - PVE::Storage::storage_check_enabled($storecfg, $storage); + # check if storage is enabled and supports vm images on local node + check_volume_alloc($storecfg, $storage); + if ($target) { # check if storage is available on target node PVE::Storage::storage_check_enabled($storecfg, $storage, $target); diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index e24c741c..507932d3 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -50,7 +50,7 @@ use PVE::Tools qw(run_command file_read_firstline file_get_contents dir_glob_for use PVE::QMPClient; use PVE::QemuConfig; -use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version); +use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version alloc_volume_disk); use PVE::QemuServer::Cloudinit; use PVE::QemuServer::CGroup; use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options get_cpu_bitness is_native_arch); @@ -8326,9 +8326,7 @@ sub clone_disk { $size = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 10); } - $newvolid = PVE::Storage::vdisk_alloc( - $storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024) - ); + $newvolid = alloc_volume_disk($storecfg, $storeid, $newvmid, $dst_format, $name, $size/1024); push @$newvollist, $newvolid; PVE::Storage::activate_volumes($storecfg, [$newvolid]); diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm index a5f6b328..937e32bf 100644 --- a/PVE/QemuServer/Helpers.pm +++ b/PVE/QemuServer/Helpers.pm @@ -13,6 +13,7 @@ use base 'Exporter'; our @EXPORT_OK = qw( check_storage_alloc check_volume_alloc +alloc_volume_disk min_version config_aware_timeout parse_number_sets @@ -197,6 +198,25 @@ sub check_volume_alloc : prototype($$;$) { return 1; } +=head3 alloc_volume_disk($storecfg, $storeid, $vmid, $format, $name, $size_kb) + +Allocates a volume disk image on C<$storeid>, that is defined in C<$storecfg> (which is typically +retrieved with L), with the VM id C<$vmid>, the format C<$format> (e.g. +C<"raw">), the name C<$name> and the image size in kilobytes C<$size_kb>. + +This subroutine will check whether the storage, where the volume disk image should be allocated, +supports the allocation beforehand with L. + +=cut + +sub alloc_volume_disk : prototype($$$$$$) { + my ($storecfg, $storeid, $vmid, $format, $name, $size_kb) = @_; + + check_volume_alloc($storecfg, $storeid); + + return PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, $size_kb); +} + sub min_version { my ($verstr, $major, $minor, $pve) = @_; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel