[pve-devel] [PATCH v2 container 7/7] stop using lxc-freeze/unfreeze binaries

Wolfgang Bumiller w.bumiller at proxmox.com
Fri May 15 11:08:42 CEST 2020


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
No change to v1

 src/PVE/LXC/Config.pm     |  4 ++--
 src/PVE/VZDump/LXC.pm     |  6 ++----
 src/test/snapshot-test.pm | 11 +++++++----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index dcc8755..51470cf 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -103,10 +103,10 @@ sub __snapshot_freeze {
     my ($class, $vmid, $unfreeze) = @_;
 
     if ($unfreeze) {
-	eval { PVE::Tools::run_command(['/usr/bin/lxc-unfreeze', '-n', $vmid]); };
+	eval { PVE::LXC::freeze_thaw($vmid, 0); };
 	warn $@ if $@;
     } else {
-	PVE::Tools::run_command(['/usr/bin/lxc-freeze', '-n', $vmid]);
+	PVE::LXC::freeze_thaw($vmid, 1);
 	PVE::LXC::sync_container_namespace($vmid);
     }
 }
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 45a3d8f..cb745bf 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -61,8 +61,6 @@ sub new {
 
     PVE::VZDump::check_bin('lxc-stop');
     PVE::VZDump::check_bin('lxc-start');
-    PVE::VZDump::check_bin('lxc-freeze');
-    PVE::VZDump::check_bin('lxc-unfreeze');
 
     my $self = bless {};
 
@@ -274,13 +272,13 @@ sub start_vm {
 sub suspend_vm {
     my ($self, $task, $vmid) = @_;
 
-    $self->cmd ("lxc-freeze -n $vmid");
+    PVE::LXC::freeze_thaw($vmid, 1);
 }
 
 sub resume_vm {
     my ($self, $task, $vmid) = @_;
 
-    $self->cmd ("lxc-unfreeze -n $vmid");
+    PVE::LXC::freeze_thaw($vmid, 0);
 }
 
 sub assemble {
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index 0a1bd6b..1194805 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -122,15 +122,17 @@ sub mocked_vm_stop {
     }
 }
 
+sub mocked_freeze_thaw {
+    my ($vmid, $freeze) = @_;
+    return () if $freeze_possible;
+    die "lxc-[un]freeze disabled\n";
+}
+
 sub mocked_run_command {
     my ($cmd, %param) = @_;
     my $cmdstring;
     if (my $ref = ref($cmd)) {
 	$cmdstring = PVE::Tools::cmd2string($cmd);
-	if ($cmdstring =~ m/.*\/lxc-(un)?freeze.*/) {
-	    return 1 if $freeze_possible;
-	    die "lxc-[un]freeze disabled\n";
-	}
 	if ($cmdstring =~ m/.*\/lxc-stop.*--kill.*/) {
 	    mocked_vm_stop();
 	}
@@ -280,6 +282,7 @@ my $lxc_module = new Test::MockModule('PVE::LXC');
 $lxc_module->mock('sync_container_namespace', sub { return; });
 $lxc_module->mock('check_running', \&mocked_check_running);
 $lxc_module->mock('vm_stop', \&mocked_vm_stop);
+$lxc_module->mock('freeze_thaw', \&mocked_freeze_thaw);
 
 my $lxc_config_module = new Test::MockModule('PVE::LXC::Config');
 $lxc_config_module->mock('config_file_lock', sub { return "snapshot-working/pve-test.lock"; });
-- 
2.20.1





More information about the pve-devel mailing list