[pve-devel] [PATCH manager] replication: use a dedicated lock file

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Jun 1 15:26:01 CEST 2017


Otherwise $update_job_state's file_set_contents() call
drops our lock.
---
 PVE/Replication.pm             | 5 +++--
 bin/test/ReplicationTestEnv.pm | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 96c54b09..9256177c 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -22,6 +22,7 @@ use PVE::ReplicationConfig;
 
 # Note: regression tests can overwrite $state_path for testing
 our $state_path = "/var/lib/pve-manager/pve-replication-state.json";
+our $lock_file = "/var/lock/pve-replication";
 
 my $update_job_state = sub {
     my ($stateobj, $jobcfg, $state) = @_;
@@ -506,7 +507,7 @@ sub run_single_job {
 	$run_replication->($stateobj, $jobcfg, $now, $logfunc);
     };
 
-    my $res = PVE::Tools::lock_file($state_path, 60, $code);
+    my $res = PVE::Tools::lock_file($lock_file, 60, $code);
     die $@ if $@;
 }
 
@@ -525,7 +526,7 @@ sub run_jobs {
 	}
     };
 
-    my $res = PVE::Tools::lock_file($state_path, 60, $code);
+    my $res = PVE::Tools::lock_file($lock_file, 60, $code);
     die $@ if $@;
 }
 
diff --git a/bin/test/ReplicationTestEnv.pm b/bin/test/ReplicationTestEnv.pm
index fffe3cd6..4399b824 100755
--- a/bin/test/ReplicationTestEnv.pm
+++ b/bin/test/ReplicationTestEnv.pm
@@ -57,9 +57,11 @@ my $mocked_ssh_info_to_command = sub {
 };
 
 my $statefile = ".mocked_repl_state";
+my $lockfile = ".mocked_repl_lock";
 
 unlink $statefile;
 $PVE::Replication::state_path = $statefile;
+$PVE::Replication::lock_file = $lockfile;
 
 my $mocked_write_state = sub {
     my ($state) = @_;
-- 
2.11.0





More information about the pve-devel mailing list