[pve-devel] [PATCH] [FIX] Avoid indefinite wait on lxc-freeze command.

Gerrit Venema gmoniker at gmail.com
Thu Jan 14 21:57:28 CET 2016


lxc-freeze is not guaranteed to return in a reasonable time.
Processes waiting in uninterruptible state stall the freeze.
But when the container is in FREEZING state, processes popping up
will be frozen immediately anyway, so just abort after 15 seconds.

Signed-off-by: Gerrit Venema <gmoniker at gmail.com>
---
 src/PVE/LXC.pm        | 27 ++++++++++++++++++++-------
 src/PVE/VZDump/LXC.pm |  4 ++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 860901f..b5daad3 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -748,6 +748,22 @@ sub check_running {
     return undef;
 }
 
+# It may not be possible to freeze all container processes within timeout
+# But any unfrozen process returning to scheduler will immediately be frozen anyway
+sub suspend_container {
+    my ($vmid) = @_;
+
+    eval { PVE::Tools::run_command(['/usr/bin/lxc-freeze', '-n', $vmid], timeout => 15); };
+    warn $@ if $@;
+}
+
+sub resume_container {
+    my ($vmid) = @_;
+
+    eval { PVE::Tools::run_command(['/usr/bin/lxc-unfreeze', '-n', $vmid]); };
+    warn $@ if $@;
+}
+
 sub get_container_disk_usage {
     my ($vmid, $pid) = @_;
 
@@ -1790,7 +1806,7 @@ sub snapshot_create {
     
     eval {
 	if ($running) {
-	    PVE::Tools::run_command(['/usr/bin/lxc-freeze', '-n', $vmid]);
+	    suspend_container($vmid);
 	    $unfreeze = 1;
 	    PVE::Tools::run_command(['/bin/sync']);
 	};
@@ -1803,12 +1819,9 @@ sub snapshot_create {
 	&$snapshot_commit($vmid, $snapname);
     };
     my $err = $@;
-    
-    if ($unfreeze) {
-	eval { PVE::Tools::run_command(['/usr/bin/lxc-unfreeze', '-n', $vmid]); };
-	warn $@ if $@;
-    }
-    
+
+    resume_container($vmid) if $unfreeze;
+
     if ($err) {
 	snapshot_delete($vmid, $snapname, 1);
 	die "$err\n";
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 7f27f0b..75d1f46 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -245,13 +245,13 @@ sub start_vm {
 sub suspend_vm {
     my ($self, $task, $vmid) = @_;
 
-    $self->cmd ("lxc-freeze -n $vmid");
+    PVE::LXC::suspend_container($vmid);
 }
 
 sub resume_vm {
     my ($self, $task, $vmid) = @_;
 
-    $self->cmd ("lxc-unfreeze -n $vmid");
+    PVE::LXC::resume_container($vmid);
 }
 
 sub assemble {
-- 
2.1.4




More information about the pve-devel mailing list