[pve-devel] [PATCH v2 pve-guest-common 4/5] PVE::GuestHelpers::guest_migration_lock - new helper

Dietmar Maurer dietmar at proxmox.com
Tue May 30 15:12:34 CEST 2017


I create a separate class for common guest helpers.
We can move more code into this class later.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 Makefile            |  1 +
 PVE/GuestHelpers.pm | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 PVE/GuestHelpers.pm

diff --git a/Makefile b/Makefile
index 6c7ea4e..e1356a0 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ ${DEB}:
 
 install: PVE
 	install -d ${PERL5DIR}/PVE
+	install -m 0644 PVE/GuestHelpers.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/AbstractConfig.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/AbstractMigrate.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationConfig.pm ${PERL5DIR}/PVE/
diff --git a/PVE/GuestHelpers.pm b/PVE/GuestHelpers.pm
new file mode 100644
index 0000000..d066527
--- /dev/null
+++ b/PVE/GuestHelpers.pm
@@ -0,0 +1,25 @@
+package PVE::GuestHelpers;
+
+use strict;
+use warnings;
+
+use PVE::Tools;
+
+# We use a separate lock to block migration while a replication job
+# is running.
+
+sub guest_migration_lock {
+    my ($vmid, $timeout, $func, @param) = @_;
+
+    my $lockid = "pve-migrate-$vmid";
+    my $lockdir = "/var/lock/pve-manager";
+
+    mkdir $lockdir;
+
+    my $res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
+    die $@ if $@;
+
+    return $res;
+}
+
+1;
-- 
2.11.0




More information about the pve-devel mailing list