all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] move_volume: call deactivate volume for the old volid in any case
@ 2022-05-04  8:15 Dominik Csapak
  2022-06-14  9:43 ` [pve-devel] applied: " Wolfgang Bumiller
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2022-05-04  8:15 UTC (permalink / raw)
  To: pve-devel

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>
---
 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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-14  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04  8:15 [pve-devel] [PATCH container] move_volume: call deactivate volume for the old volid in any case Dominik Csapak
2022-06-14  9:43 ` [pve-devel] applied: " Wolfgang Bumiller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal