* [pve-devel] [PATCH container 1/6] clone_vm: use move_config_to_node
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 2/6] clone_vm: use destroy_config instead of manual unlink Fabian Grünbichler
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/PVE/API2/LXC.pm | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 4dd692d..9865a6b 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1571,9 +1571,7 @@ __PACKAGE__->register_method({
PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
PVE::Storage::deactivate_volumes($storecfg, $newvollist);
- my $newconffile = PVE::LXC::Config->config_file($newid, $target);
- die "Failed to move config to node '$target' - rename failed: $!\n"
- if !rename($conffile, $newconffile);
+ PVE::LXC::Config->move_config_to_node($newid, $target);
}
});
};
--
2.30.2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [pve-devel] [PATCH container 2/6] clone_vm: use destroy_config instead of manual unlink
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 1/6] clone_vm: use move_config_to_node Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 3/6] clone_vm: reduce source flock scope Fabian Grünbichler
` (3 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
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@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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [pve-devel] [PATCH container 3/6] clone_vm: reduce source flock scope
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 1/6] clone_vm: use move_config_to_node Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 2/6] clone_vm: use destroy_config instead of manual unlink Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 4/6] clone_vm: move linked clone check in eval Fabian Grünbichler
` (2 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
set_lock already obtains the flock (since it does a read-modify-write
cycle), and the rest of this code does not touch the config file in any
fashion so no need to hold the flock either..
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
best viewed with -w ;)
src/PVE/API2/LXC.pm | 163 ++++++++++++++++++++++----------------------
1 file changed, 81 insertions(+), 82 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 807709a..1554ef2 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1395,116 +1395,115 @@ __PACKAGE__->register_method({
PVE::LXC::Config->create_and_lock_config($newid, 0);
- PVE::LXC::Config->lock_config($vmid, sub {
- my $src_conf = PVE::LXC::Config->set_lock($vmid, 'disk');
-
- $running = PVE::LXC::check_running($vmid) || 0;
- my $full = extract_param($param, 'full');
- if (!defined($full)) {
- $full = !PVE::LXC::Config->is_template($src_conf);
- }
- die "parameter 'storage' not allowed for linked clones\n" if defined($storage) && !$full;
+ my $src_conf = PVE::LXC::Config->set_lock($vmid, 'disk');
- eval {
- die "snapshot '$snapname' does not exist\n"
- if $snapname && !defined($src_conf->{snapshots}->{$snapname});
+ $running = PVE::LXC::check_running($vmid) || 0;
- my $src_conf = $snapname ? $src_conf->{snapshots}->{$snapname} : $src_conf;
+ my $full = extract_param($param, 'full');
+ if (!defined($full)) {
+ $full = !PVE::LXC::Config->is_template($src_conf);
+ }
+ die "parameter 'storage' not allowed for linked clones\n" if defined($storage) && !$full;
- my $sharedvm = 1;
- for my $opt (sort keys %$src_conf) {
- next if $opt =~ m/^unused\d+$/;
+ eval {
+ die "snapshot '$snapname' does not exist\n"
+ if $snapname && !defined($src_conf->{snapshots}->{$snapname});
- my $value = $src_conf->{$opt};
+ my $src_conf = $snapname ? $src_conf->{snapshots}->{$snapname} : $src_conf;
- if (($opt eq 'rootfs') || ($opt =~ m/^mp\d+$/)) {
- my $mp = PVE::LXC::Config->parse_volume($opt, $value);
+ my $sharedvm = 1;
+ for my $opt (sort keys %$src_conf) {
+ next if $opt =~ m/^unused\d+$/;
- if ($mp->{type} eq 'volume') {
- my $volid = $mp->{volume};
+ my $value = $src_conf->{$opt};
- my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
- $sid = $storage if defined($storage);
- my $scfg = PVE::Storage::storage_config($storecfg, $sid);
- if (!$scfg->{shared}) {
- $sharedvm = 0;
- warn "found non-shared volume: $volid\n" if $target;
- }
+ if (($opt eq 'rootfs') || ($opt =~ m/^mp\d+$/)) {
+ my $mp = PVE::LXC::Config->parse_volume($opt, $value);
- $rpcenv->check($authuser, "/storage/$sid", ['Datastore.AllocateSpace']);
+ if ($mp->{type} eq 'volume') {
+ my $volid = $mp->{volume};
- if ($full) {
- die "Cannot do full clones on a running container without snapshots\n"
- if $running && !defined($snapname);
- $fullclone->{$opt} = 1;
- } else {
- # not full means clone instead of copy
- die "Linked clone feature for '$volid' is not available\n"
- if !PVE::Storage::volume_has_feature($storecfg, 'clone', $volid, $snapname, $running, {'valid_target_formats' => ['raw', 'subvol']});
- }
+ my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
+ $sid = $storage if defined($storage);
+ my $scfg = PVE::Storage::storage_config($storecfg, $sid);
+ if (!$scfg->{shared}) {
+ $sharedvm = 0;
+ warn "found non-shared volume: $volid\n" if $target;
+ }
- $mountpoints->{$opt} = $mp;
- push @$vollist, $volid;
+ $rpcenv->check($authuser, "/storage/$sid", ['Datastore.AllocateSpace']);
+ if ($full) {
+ die "Cannot do full clones on a running container without snapshots\n"
+ if $running && !defined($snapname);
+ $fullclone->{$opt} = 1;
} else {
- # TODO: allow bind mounts?
- die "unable to clone mountpoint '$opt' (type $mp->{type})\n";
+ # not full means clone instead of copy
+ die "Linked clone feature for '$volid' is not available\n"
+ if !PVE::Storage::volume_has_feature($storecfg, 'clone', $volid, $snapname, $running, {'valid_target_formats' => ['raw', 'subvol']});
}
- } elsif ($opt =~ m/^net(\d+)$/) {
- # always change MAC! address
- my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
- my $net = PVE::LXC::Config->parse_lxc_network($value);
- $net->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
- $newconf->{$opt} = PVE::LXC::Config->print_lxc_network($net);
+
+ $mountpoints->{$opt} = $mp;
+ push @$vollist, $volid;
+
} else {
- # copy everything else
- $newconf->{$opt} = $value;
+ # TODO: allow bind mounts?
+ die "unable to clone mountpoint '$opt' (type $mp->{type})\n";
}
+ } elsif ($opt =~ m/^net(\d+)$/) {
+ # always change MAC! address
+ my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ my $net = PVE::LXC::Config->parse_lxc_network($value);
+ $net->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+ $newconf->{$opt} = PVE::LXC::Config->print_lxc_network($net);
+ } else {
+ # copy everything else
+ $newconf->{$opt} = $value;
}
- die "can't clone CT to node '$target' (CT uses local storage)\n"
- if $target && !$sharedvm;
+ }
+ die "can't clone CT to node '$target' (CT uses local storage)\n"
+ if $target && !$sharedvm;
- # Replace the 'disk' lock with a 'create' lock.
- $newconf->{lock} = 'create';
+ # Replace the 'disk' lock with a 'create' lock.
+ $newconf->{lock} = 'create';
- delete $newconf->{snapshots};
- delete $newconf->{pending};
- delete $newconf->{template};
- if ($param->{hostname}) {
- $newconf->{hostname} = $param->{hostname};
- }
+ delete $newconf->{snapshots};
+ delete $newconf->{pending};
+ delete $newconf->{template};
+ if ($param->{hostname}) {
+ $newconf->{hostname} = $param->{hostname};
+ }
- if ($param->{description}) {
- $newconf->{description} = $param->{description};
- }
+ if ($param->{description}) {
+ $newconf->{description} = $param->{description};
+ }
+ PVE::LXC::Config->lock_config($newid, sub {
+ # read empty config, lock needs to be still here
+ my $conf = PVE::LXC::Config->load_config($newid);
+ die "Lost 'create' config lock, aborting.\n"
+ if !PVE::LXC::Config->has_lock($conf, 'create');
+ # write the actual new config now to disk
+ PVE::LXC::Config->write_config($newid, $newconf);
+ });
+ };
+ if (my $err = $@) {
+ eval { PVE::LXC::Config->remove_lock($vmid, 'disk') };
+ warn "Failed to remove source CT config lock - $@\n" if $@;
+
+ eval {
PVE::LXC::Config->lock_config($newid, sub {
- # read empty config, lock needs to be still here
my $conf = PVE::LXC::Config->load_config($newid);
die "Lost 'create' config lock, aborting.\n"
if !PVE::LXC::Config->has_lock($conf, 'create');
- # write the actual new config now to disk
- PVE::LXC::Config->write_config($newid, $newconf);
+ PVE::LXC::Config->destroy_config($newid);
});
};
- if (my $err = $@) {
- eval { PVE::LXC::Config->remove_lock($vmid, 'disk') };
- 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 $@;
+ warn "Failed to remove target CT config - $@\n" if $@;
- die $err;
- }
- });
+ die $err;
+ }
my $update_conf = sub {
my ($key, $value) = @_;
--
2.30.2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [pve-devel] [PATCH container 4/6] clone_vm: move linked clone check in eval
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
` (2 preceding siblings ...)
2021-06-18 12:51 ` [pve-devel] [PATCH container 3/6] clone_vm: reduce source flock scope Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 5/6] clone_vm: refactor locking further Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 6/6] clone_vm: rework firewall config cloning Fabian Grünbichler
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
so that the source config is properly cleaned up/unlocked
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/PVE/API2/LXC.pm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 1554ef2..5406923 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1404,9 +1404,11 @@ __PACKAGE__->register_method({
if (!defined($full)) {
$full = !PVE::LXC::Config->is_template($src_conf);
}
- die "parameter 'storage' not allowed for linked clones\n" if defined($storage) && !$full;
eval {
+ die "parameter 'storage' not allowed for linked clones\n"
+ if defined($storage) && !$full;
+
die "snapshot '$snapname' does not exist\n"
if $snapname && !defined($src_conf->{snapshots}->{$snapname});
--
2.30.2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [pve-devel] [PATCH container 5/6] clone_vm: refactor locking further
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
` (3 preceding siblings ...)
2021-06-18 12:51 ` [pve-devel] [PATCH container 4/6] clone_vm: move linked clone check in eval Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
2021-06-18 12:51 ` [pve-devel] [PATCH container 6/6] clone_vm: rework firewall config cloning Fabian Grünbichler
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
introduce a new helper handling
- obtaining the flock
- (re)loading the config
- checking that the 'create' lock is still there
before calling a passed-in sub with the current config, since this
pattern was used quite a lot here.
intentionally changed behaviour:
- flock is now held for the post_clone hook call
- failure to remove the 'create' lock or to move the config to the
target node if applicable will not undo the clone, since either is
trivially fixable ('pct unlock' or a no-op migration), and copying all
those volumes might have been quite expensive..
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
there are probably quite a few places in the container/qemu-server code
where we should employ this or a similar mechanism with digest tracking
to be 100% on the safe side..
src/PVE/API2/LXC.pm | 76 ++++++++++++++++++++++++---------------------
1 file changed, 41 insertions(+), 35 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 5406923..4877dd9 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1395,6 +1395,16 @@ __PACKAGE__->register_method({
PVE::LXC::Config->create_and_lock_config($newid, 0);
+ my $lock_and_reload = sub {
+ my ($vmid, $code) = @_;
+ return PVE::LXC::Config->lock_config($vmid, sub {
+ my $conf = PVE::LXC::Config->load_config($vmid);
+ die "Lost 'create' config lock, aborting.\n"
+ if !PVE::LXC::Config->has_lock($conf, 'create');
+
+ return $code->($conf);
+ });
+ };
my $src_conf = PVE::LXC::Config->set_lock($vmid, 'disk');
@@ -1481,12 +1491,7 @@ __PACKAGE__->register_method({
$newconf->{description} = $param->{description};
}
- PVE::LXC::Config->lock_config($newid, sub {
- # read empty config, lock needs to be still here
- my $conf = PVE::LXC::Config->load_config($newid);
- die "Lost 'create' config lock, aborting.\n"
- if !PVE::LXC::Config->has_lock($conf, 'create');
- # write the actual new config now to disk
+ $lock_and_reload->($newid, sub {
PVE::LXC::Config->write_config($newid, $newconf);
});
};
@@ -1495,10 +1500,7 @@ __PACKAGE__->register_method({
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');
+ $lock_and_reload->($newid, sub {
PVE::LXC::Config->destroy_config($newid);
});
};
@@ -1509,10 +1511,8 @@ __PACKAGE__->register_method({
my $update_conf = sub {
my ($key, $value) = @_;
- return 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');
+ return $lock_and_reload->($newid, sub {
+ my $conf = shift;
$conf->{$key} = $value;
PVE::LXC::Config->write_config($newid, $conf);
});
@@ -1559,23 +1559,20 @@ __PACKAGE__->register_method({
PVE::AccessControl::add_vm_to_pool($newid, $pool) if $pool;
- $newconf = PVE::LXC::Config->load_config($newid);
- die "Lost 'create' config lock, aborting.\n"
- if !PVE::LXC::Config->has_lock($newconf, 'create');
- my $rootdir = PVE::LXC::mount_all($newid, $storecfg, $newconf, 1);
- my $lxc_setup = PVE::LXC::Setup->new($newconf, $rootdir);
- $lxc_setup->post_clone_hook($newconf);
- PVE::LXC::umount_all($newid, $storecfg, $newconf, 1);
-
- PVE::LXC::Config->remove_lock($newid, 'create');
-
- PVE::LXC::Config->lock_config($newid, sub {
- if ($target) {
- # always deactivate volumes - avoid lvm LVs to be active on several nodes
- PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
- PVE::Storage::deactivate_volumes($storecfg, $newvollist);
-
- PVE::LXC::Config->move_config_to_node($newid, $target);
+ $lock_and_reload->($newid, sub {
+ my $conf = shift;
+ my $rootdir = PVE::LXC::mount_all($newid, $storecfg, $conf, 1);
+ eval {
+ my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
+ $lxc_setup->post_clone_hook($conf);
+ };
+ my $err = $@;
+ eval { PVE::LXC::umount_all($newid, $storecfg, $conf, 1); };
+ if ($err) {
+ warn "$@\n" if $@;
+ die $err;
+ } else {
+ die $@ if $@;
}
});
};
@@ -1594,10 +1591,7 @@ __PACKAGE__->register_method({
}
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');
+ $lock_and_reload->($newid, sub {
PVE::LXC::Config->destroy_config($newid);
});
};
@@ -1606,6 +1600,18 @@ __PACKAGE__->register_method({
die "clone failed: $err";
}
+ $lock_and_reload->($newid, sub {
+ PVE::LXC::Config->remove_lock($newid, 'create');
+
+ if ($target) {
+ # always deactivate volumes - avoid lvm LVs to be active on several nodes
+ PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
+ PVE::Storage::deactivate_volumes($storecfg, $newvollist);
+
+ PVE::LXC::Config->move_config_to_node($newid, $target);
+ }
+ });
+
PVE::Firewall::clone_vmfw_conf($vmid, $newid);
return;
};
--
2.30.2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [pve-devel] [PATCH container 6/6] clone_vm: rework firewall config cloning
2021-06-18 12:51 ` [pve-devel] [PATCH container 0/6] clone_vm follow-ups Fabian Grünbichler
` (4 preceding siblings ...)
2021-06-18 12:51 ` [pve-devel] [PATCH container 5/6] clone_vm: refactor locking further Fabian Grünbichler
@ 2021-06-18 12:51 ` Fabian Grünbichler
5 siblings, 0 replies; 14+ messages in thread
From: Fabian Grünbichler @ 2021-06-18 12:51 UTC (permalink / raw)
To: pve-devel
we need to clone the firewall config before doing any actual work, else
we risk partially aborting and leaving a non-firewalled container
around. accordingly, we need to (attempt to) remove the cloned FW config
after successfully removing the guest config in error handling.
partially reverts/fixes 4925b86a920a862f25f0d93d243ce099c922979d clone_vm: improve config locking
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/PVE/API2/LXC.pm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 4877dd9..0d4d91a 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1394,6 +1394,7 @@ __PACKAGE__->register_method({
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) = @_;
@@ -1502,6 +1503,7 @@ __PACKAGE__->register_method({
eval {
$lock_and_reload->($newid, sub {
PVE::LXC::Config->destroy_config($newid);
+ PVE::Firewall::remove_vmfw_conf($newid);
});
};
warn "Failed to remove target CT config - $@\n" if $@;
@@ -1593,6 +1595,7 @@ __PACKAGE__->register_method({
eval {
$lock_and_reload->($newid, sub {
PVE::LXC::Config->destroy_config($newid);
+ PVE::Firewall::remove_vmfw_conf($newid);
});
};
warn "Failed to remove target CT config - $@\n" if $@;
@@ -1612,7 +1615,6 @@ __PACKAGE__->register_method({
}
});
- PVE::Firewall::clone_vmfw_conf($vmid, $newid);
return;
};
--
2.30.2
^ permalink raw reply [flat|nested] 14+ messages in thread