[pve-devel] [PATCH v3 guest-common 1/1] guest helpers: add run_with_replication_guard

Fabian Ebner f.ebner at proxmox.com
Mon Feb 21 12:58:25 CET 2022


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

New in v3.

 src/PVE/GuestHelpers.pm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
index 970c460..1183819 100644
--- a/src/PVE/GuestHelpers.pm
+++ b/src/PVE/GuestHelpers.pm
@@ -3,8 +3,9 @@ package PVE::GuestHelpers;
 use strict;
 use warnings;
 
-use PVE::Tools;
+use PVE::ReplicationConfig;
 use PVE::Storage;
+use PVE::Tools;
 
 use POSIX qw(strftime);
 use Scalar::Util qw(weaken);
@@ -82,6 +83,18 @@ sub guest_migration_lock {
     return $res;
 }
 
+sub run_with_replication_guard {
+    my ($vmid, $timeout, $log, $func, @param) = @_;
+
+    my $repl_conf = PVE::ReplicationConfig->new();
+    if ($repl_conf->check_for_existing_jobs($vmid, 1)) {
+	$log->("checking/waiting for active replication..") if $log;
+	guest_migration_lock($vmid, $timeout, $func, @param);
+    } else {
+	$func->(@param);
+    }
+}
+
 sub check_hookscript {
     my ($volid, $storecfg) = @_;
 
-- 
2.30.2






More information about the pve-devel mailing list