[pve-devel] [PATCH container 2/6] clone_vm: use destroy_config instead of manual unlink

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jun 18 14:51:19 CEST 2021


and wrap the calls in an eval to preserve original errors causing us to
remove the config in the first place..

also, remove disks before removing the locked config (reverse order of
creation).

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 src/PVE/API2/LXC.pm | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 9865a6b..807709a 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1387,7 +1387,6 @@ __PACKAGE__->register_method({
 
 	PVE::Cluster::check_cfs_quorum();
 
-	my $conffile;
 	my $newconf = {};
 	my $mountpoints = {};
 	my $fullclone = {};
@@ -1395,7 +1394,6 @@ __PACKAGE__->register_method({
 	my $running;
 
 	PVE::LXC::Config->create_and_lock_config($newid, 0);
-	$conffile = PVE::LXC::Config->config_file($newid);
 
 	PVE::LXC::Config->lock_config($vmid, sub {
 	    my $src_conf = PVE::LXC::Config->set_lock($vmid, 'disk');
@@ -1492,13 +1490,18 @@ __PACKAGE__->register_method({
 	    };
 	    if (my $err = $@) {
 		eval { PVE::LXC::Config->remove_lock($vmid, 'disk') };
-		PVE::LXC::Config->lock_config($newid, sub {
-		    my $conf = PVE::LXC::Config->load_config($newid);
-		    die "Lost 'create' config lock, aborting.\n"
-			if !PVE::LXC::Config->has_lock($conf, 'create');
-		    unlink($conffile);
-		});
-		warn $@ if $@;
+		warn "Failed to remove source CT config lock - $@\n" if $@;
+
+		eval {
+		    PVE::LXC::Config->lock_config($newid, sub {
+			my $conf = PVE::LXC::Config->load_config($newid);
+			die "Lost 'create' config lock, aborting.\n"
+			    if !PVE::LXC::Config->has_lock($conf, 'create');
+			PVE::LXC::Config->destroy_config($newid);
+		    });
+		};
+		warn "Failed to remove target CT config - $@\n" if $@;
+
 		die $err;
 	    }
 	});
@@ -1582,14 +1585,23 @@ __PACKAGE__->register_method({
 
 	    if ($err) {
 		# Now cleanup the config & disks:
-		unlink $conffile;
-
 		sleep 1; # some storages like rbd need to wait before release volume - really?
 
 		foreach my $volid (@$newvollist) {
 		    eval { PVE::Storage::vdisk_free($storecfg, $volid); };
 		    warn $@ if $@;
 		}
+
+		eval {
+		    PVE::LXC::Config->lock_config($newid, sub {
+			my $conf = PVE::LXC::Config->load_config($newid);
+			die "Lost 'create' config lock, aborting.\n"
+			    if !PVE::LXC::Config->has_lock($conf, 'create');
+			PVE::LXC::Config->destroy_config($newid);
+		    });
+		};
+		warn "Failed to remove target CT config - $@\n" if $@;
+
 		die "clone failed: $err";
 	    }
 
-- 
2.30.2






More information about the pve-devel mailing list