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 148B31FF16B for ; Mon, 16 Sep 2024 18:38:49 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DDCFAB6FD; Mon, 16 Sep 2024 18:38:46 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Mon, 16 Sep 2024 18:38:33 +0200 Message-Id: <20240916163839.236908-4-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.005 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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 3/9] fix #5284: move_vm: add check if target 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 if the target storage when moving a VM disk images between two different storages supports the content type 'images'. Without the check in place, it will move the volume image to the target storage even though vm images are not supported there. This will result in the VM failing to start for any non-unused disk volumes. Signed-off-by: Daniel Kral --- PVE/API2/Qemu.pm | 8 ++++--- PVE/QemuServer/Helpers.pm | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index d25a79fe..0cb4af89 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; +use PVE::QemuServer::Helpers qw(check_storage_alloc check_volume_alloc); use PVE::QemuServer::ImportDisk; use PVE::QemuServer::Monitor qw(mon_cmd); use PVE::QemuServer::Machine; @@ -4115,6 +4115,10 @@ __PACKAGE__->register_method({ die "you can't move to the same storage with same format\n" if $oldstoreid eq $storeid && (!$format || !$oldfmt || $oldfmt eq $format); + check_storage_alloc($rpcenv, $authuser, $storeid); + eval { check_volume_alloc($storecfg, $storeid) }; + raise_param_exc({ storage => "$@" }) if $@; + # this only checks snapshots because $disk is passed! my $snapshotted = PVE::QemuServer::Drive::is_volume_in_use( $storecfg, @@ -4408,8 +4412,6 @@ __PACKAGE__->register_method({ $disk_reassignfn ); } elsif ($storeid) { - $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']); - $load_and_check_move->(); # early checks before forking/locking my $realcmd = sub { diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm index 9d0f24aa..a5f6b328 100644 --- a/PVE/QemuServer/Helpers.pm +++ b/PVE/QemuServer/Helpers.pm @@ -11,6 +11,8 @@ use PVE::ProcFSTools; use base 'Exporter'; our @EXPORT_OK = qw( +check_storage_alloc +check_volume_alloc min_version config_aware_timeout parse_number_sets @@ -151,6 +153,50 @@ sub check_volume_content_type : prototype($$) { return check_storage_content_type($storecfg, $storeid, $vtype); } +=head3 check_storage_alloc($rpcenv, $user, $storeid) + +Checks whether the C<$user> has the permissions in the C<$rpcenv> to allocate space in the storage +with the identifier C<$storeid>. + + +If the check fails, the subroutine will C with a permission exception inside the subroutine +L. + +Returns C<1> if the check is successful. + +=cut + +sub check_storage_alloc : prototype($$$) { + my ($rpcenv, $user, $storeid) = @_; + + if (defined($rpcenv) && defined($user)) { + $rpcenv->check($user, "/storage/$storeid", ['Datastore.AllocateSpace']) + if $user ne 'root@pam'; + } + + return 1; +} + +=head3 check_volume_alloc($storecfg, $storeid, $node) + +Checks whether the volume with the identifier C<$volid>, that is defined in C<$storecfg> (which +is typically retrieved with L), is enabled an supports volume images. + +If the check fails, it will C with an error message. + +Returns C<1> if the check is successful. + +=cut + +sub check_volume_alloc : prototype($$;$) { + my ($storecfg, $storeid, $node) = @_; + + PVE::Storage::storage_check_enabled($storecfg, $storeid, $node); + check_storage_content_type($storecfg, $storeid); + + return 1; +} + 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