and set it as unused

Signed-off-by: Alexandre Derumier <[email protected]>
---
 PVE/API2/Qemu.pm |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 009f0a1..b3c91d1 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2406,8 +2406,19 @@ __PACKAGE__->register_method({
                 }
 
                if ($param->{delete}) {
-                   eval { PVE::Storage::vdisk_free($storecfg, $old_volid); };
-                   warn $@ if $@;
+                    my $used_paths = PVE::QemuServer::get_used_paths($vmid, 
$storecfg, $conf, 1, 1);
+                    my $path = PVE::Storage::path($storecfg, $old_volid);
+                   eval{ die "unable to delete '$old_volid' - volume is still 
in use (snapshot?)\n"
+                               if $used_paths->{$path}; };
+                   if ($@){
+                       warn $@;
+                       PVE::QemuServer::add_unused_volume($conf, $old_volid);
+                       PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+
+                   } else {
+                       eval { PVE::Storage::vdisk_free($storecfg, $old_volid); 
};
+                       warn $@ if $@;
+                   }
                }
            };
 
-- 
1.7.10.4

_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to