Asserts whether the target storage supports storing VM images before
cloning a VM and its volumes to the target storage.

Without the check in place, a VMs volumes can be cloned to a storage,
which does not support VM images, but won't be able to start since any
attached volume must be stored on a supported storage.

Signed-off-by: Daniel Kral <d.k...@proxmox.com>
---
changes since v1:
- new! (was fixed without special notice in rfc)

 PVE/API2/Qemu.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 52234afd..370036b8 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -3851,13 +3851,15 @@ __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 on local node and supports vm 
images
+               my $scfg = PVE::Storage::storage_check_enabled($storecfg, 
$storage);
+               raise_param_exc({ storage => "storage '$storage' does not 
support vm images" })
+                   if !$scfg->{content}->{images};
+
                if ($target) {
                    # check if storage is available on target node
                    PVE::Storage::storage_check_enabled($storecfg, $storage, 
$target);
                    # clone only works if target storage is shared
-                   my $scfg = PVE::Storage::storage_config($storecfg, 
$storage);
                    die "can't clone to non-shared storage '$storage'\n"
                        if !$scfg->{shared};
                }
-- 
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