[pve-devel] [PATCH container] Improve error handling in snapshot_create

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Feb 4 16:05:11 CET 2016


Set unfreeze before trying to freeze, otherwise an aborted
or failed lxc-freeze will not be reversed by our error
handling, leaving the container in a (partially) frozen
state.

Add a call to snapshot_commit in its own eval block to the
error handling code, because we want to cleanup and unlock
the config file in case of freeze or volume_snapshot
errors. This needs to be done before attempting to call
snapshot_delete.

Move the cleanup snapshot_delete call into its own eval
block, because we want to die with the original $err even
if the snapshot_delete fails for whatever reason.
---
Comment: this should ease recovery for those affected by the
hanging lxc-freeze issue. Previously, if the issue occured
one would have to manually unfreeze or force stop the container
and remove the lock in the config file. The first subsequent
snapshot (backup) would still fail on the first attempt because
the config file would reference a snapshot that was not created
on the storage level. Now, unfreezing the container and cleaning
up the config file should happen automatically if an error
occurs (for example, if a hanging lxc-freeze is killed by the
administrator).

 src/PVE/LXC.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f761f33..c5c6607 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1827,8 +1827,8 @@ sub snapshot_create {
     
     eval {
 	if ($running) {
-	    PVE::Tools::run_command(['/usr/bin/lxc-freeze', '-n', $vmid]);
 	    $unfreeze = 1;
+	    PVE::Tools::run_command(['/usr/bin/lxc-freeze', '-n', $vmid]);
 	    PVE::Tools::run_command(['/bin/sync']);
 	};
 
@@ -1847,7 +1847,10 @@ sub snapshot_create {
     }
     
     if ($err) {
-	snapshot_delete($vmid, $snapname, 1);
+	eval { &$snapshot_commit($vmid, $snapname); };
+	warn $@ if $@;
+	eval { snapshot_delete($vmid, $snapname, 1); };
+	warn $@ if $@;
 	die "$err\n";
     }
 }
-- 
2.1.4





More information about the pve-devel mailing list