not only when we want to remove it. Otherwise, if the old volume is mapped (e.g. ceph krbd), we don't unmap it when we're finished.
We have to save if we deactivated successfully before attempting to remove it. If it was not removed (either because we could not deactivate, or the remove failed), we add it back as unused. Signed-off-by: Dominik Csapak <[email protected]> --- src/PVE/API2/LXC.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 64724cb..e909cb0 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -2043,13 +2043,23 @@ __PACKAGE__->register_method({ die $err; } + my $deactivated = 0; + eval { + PVE::Storage::deactivate_volumes($storage_cfg, [ $old_volid ]); + $deactivated = 1; + }; + warn $@ if $@; + if ($param->{delete}) { - eval { - PVE::Storage::deactivate_volumes($storage_cfg, [ $old_volid ]); - PVE::Storage::vdisk_free($storage_cfg, $old_volid); - }; - if (my $err = $@) { - warn $err; + my $removed = 0; + if ($deactivated) { + eval { + PVE::Storage::vdisk_free($storage_cfg, $old_volid); + $removed = 1; + }; + warn $@ if $@; + } + if (!$removed) { PVE::LXC::Config->lock_config($vmid, sub { my $conf = PVE::LXC::Config->load_config($vmid); PVE::LXC::Config->add_unused_volume($conf, $old_volid); -- 2.30.2 _______________________________________________ pve-devel mailing list [email protected] https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
