]> git.proxmox.com Git - pve-container.git/commitdiff
fix: cloning a locked container creates an empty config
authorDaniel Tschlatscher <d.tschlatscher@proxmox.com>
Fri, 17 Jun 2022 10:40:01 +0000 (12:40 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2022 07:03:57 +0000 (09:03 +0200)
When an attempt was made to clone a locked container the API would
correctly present the error 'CT is locked (disk)' but create the
config files for the new container anyway.

There was also a potential problem when the config of the new ct would
already be present and the creation of the container failed. In this
case the config of the new CT would be incorrectly removed.
The config locks for the new and the old configs should now be
correctly released depending on from which call a problem originates.

Futhermore, I moved some related function calls into the eval block to
avoid similar problems with leftover config files in the future.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
src/PVE/API2/LXC.pm

index e909cb08adf309a42aebadd9c7da72018dfbc28b..589f96f6090d3503390c3c29810770a6831d269a 100644 (file)
@@ -1461,9 +1461,6 @@ __PACKAGE__->register_method({
        my $vollist = [];
        my $running;
 
-       PVE::LXC::Config->create_and_lock_config($newid, 0);
-       PVE::Firewall::clone_vmfw_conf($vmid, $newid);
-
        my $lock_and_reload = sub {
            my ($vmid, $code) = @_;
            return PVE::LXC::Config->lock_config($vmid, sub {
@@ -1477,14 +1474,26 @@ __PACKAGE__->register_method({
 
        my $src_conf = PVE::LXC::Config->set_lock($vmid, 'disk');
 
-       $running = PVE::LXC::check_running($vmid) || 0;
+       eval {
+           PVE::LXC::Config->create_and_lock_config($newid, 0);
+       };
+       if (my $err = $@) {
+           eval { PVE::LXC::Config->remove_lock($vmid, 'disk') };
+           warn "Failed to remove source CT config lock - $@\n" if $@;
 
-       my $full = extract_param($param, 'full');
-       if (!defined($full)) {
-           $full = !PVE::LXC::Config->is_template($src_conf);
+           die $err;
        }
 
        eval {
+           $running = PVE::LXC::check_running($vmid) || 0;
+
+           my $full = extract_param($param, 'full');
+           if (!defined($full)) {
+               $full = !PVE::LXC::Config->is_template($src_conf);
+           }
+
+           PVE::Firewall::clone_vmfw_conf($vmid, $newid);
+
            die "parameter 'storage' not allowed for linked clones\n"
                if defined($storage) && !$full;