[pve-devel] [PATCH container 1/2] destroy_config: die if unlink fails

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jan 28 08:06:47 CET 2019


We use this in two places, in the cleanup path of the create/restore
API path and indirectly through PVE::LXC::destroy_lxc_container, once
again in the restore code path of the create API call, to cleanup a
CT before overwriting it with a backup if the force flag ist set. The
second time in the destroy CT API call, both times a hard error in a
erroneous cleanup is wanted.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

This method could be probably pulled out to the config base class,
but that's for another time if it's worth at all.

 src/PVE/API2/LXC.pm | 3 ++-
 src/PVE/LXC.pm      | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 2ab98da..d0e82ee 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -430,7 +430,8 @@ __PACKAGE__->register_method({
 	    };
 	    if (my $err = $@) {
 		PVE::LXC::destroy_disks($storage_cfg, $vollist);
-		PVE::LXC::destroy_config($vmid);
+		eval { PVE::LXC::destroy_config($vmid) };
+		warn $@ if $@;
 		die $err;
 	    }
 	    PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index ab15ec0..8d138f0 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -54,7 +54,8 @@ sub config_list {
 sub destroy_config {
     my ($vmid) = @_;
 
-    unlink PVE::LXC::Config->config_file($vmid, $nodename);
+    my $config_fn = PVE::LXC::Config->config_file($vmid, $nodename);
+    unlink $config_file or die "failed to remove config file: $!\n";
 }
 
 # container status helpers
-- 
2.20.1





More information about the pve-devel mailing list