[pve-devel] [PATCH v2 container] Improve error handling in snapshot_create
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Feb 8 10:16:00 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.
Combine existing code from snapshot_commit with a call to
snapshot_delete to create the new method snapshot_abort.
This way, we can cleanup the config and (try to) delete
the failed snapshot in one go, wrapped by lock_container.
---
src/PVE/LXC.pm | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f761f33..185c77e 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1791,6 +1791,35 @@ my $snapshot_commit = sub {
lock_container($vmid, 10 ,$updatefn);
};
+my $snapshot_abort = sub {
+ my ($vmid, $snapname) = @_;
+
+ my $updatefn = sub {
+
+ my $conf = load_config($vmid);
+
+ die "missing snapshot lock\n"
+ if !($conf->{lock} && $conf->{lock} eq 'snapshot');
+
+ die "snapshot '$snapname' does not exist\n"
+ if !defined($conf->{snapshots}->{$snapname});
+
+ die "wrong snapshot state\n"
+ if !($conf->{snapshots}->{$snapname}->{'snapstate'} &&
+ $conf->{snapshots}->{$snapname}->{'snapstate'} eq "prepare");
+
+ delete $conf->{snapshots}->{$snapname}->{'snapstate'};
+ delete $conf->{lock};
+
+ write_config($vmid, $conf);
+
+ eval { snapshot_delete($vmid, $snapname, 1); };
+ warn "$@\n" if $@;
+ };
+
+ lock_container($vmid, 10 ,$updatefn);
+};
+
sub has_feature {
my ($feature, $conf, $storecfg, $snapname) = @_;
@@ -1827,8 +1856,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 +1876,8 @@ sub snapshot_create {
}
if ($err) {
- snapshot_delete($vmid, $snapname, 1);
+ eval { &$snapshot_abort($vmid, $snapname); };
+ warn "$@\n" if $@;
die "$err\n";
}
}
--
2.1.4
More information about the pve-devel
mailing list