]> git.proxmox.com Git - pve-container.git/commitdiff
move_volume: call deactivate volume for the old volid in any case
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 4 May 2022 08:15:02 +0000 (10:15 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 14 Jun 2022 09:42:19 +0000 (11:42 +0200)
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 <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/API2/LXC.pm

index 64724cb35406a9d9d72bc1cc06f2db09e456e3f7..e909cb08adf309a42aebadd9c7da72018dfbc28b 100644 (file)
@@ -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);