From 5b0bd20dd50e30029cd5490305380149a35b22b7 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Mon, 14 Apr 2014 13:52:23 +0200 Subject: [PATCH] move_disk : don't delete disk if used in a previous snasphot v2 and set it as unused Signed-off-by: Alexandre Derumier --- PVE/API2/Qemu.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 009f0a13..696887f0 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -2406,8 +2406,16 @@ __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); + if ($used_paths->{$path}){ + warn "volume $old_volid have snapshots. Can't delete it"; + 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 $@; + } } };