[pve-devel] [PATCH v3 container 5/5] move_volume: if deleting old volume fails, add it as unused

Fabian Ebner f.ebner at proxmox.com
Mon Mar 23 12:18:54 CET 2020


Especially useful when there are linked clones using the volume
that is being moved, but shouldn't hurt otherwise either.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/LXC.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 307fd90..e028963 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1858,7 +1858,14 @@ __PACKAGE__->register_method({
 			PVE::Storage::deactivate_volumes($storage_cfg, [ $old_volid ]);
 			PVE::Storage::vdisk_free($storage_cfg, $old_volid);
 		    };
-		    warn $@ if $@;
+		    if (my $err = $@) {
+			warn $err;
+			PVE::LXC::Config->lock_config($vmid, sub {
+			    my $conf = PVE::LXC::Config->load_config($vmid);
+			    PVE::LXC::Config->add_unused_volume($conf, $old_volid);
+			    PVE::LXC::Config->write_config($vmid, $conf);
+			});
+		    }
 		}
 	    };
 	    my $err = $@;
-- 
2.20.1





More information about the pve-devel mailing list