]> git.proxmox.com Git - pve-guest-common.git/commitdiff
PVE::GuestHelpers::guest_migration_lock - new helper
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 24 May 2017 05:24:34 +0000 (07:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 30 May 2017 10:06:08 +0000 (12:06 +0200)
I create a separate class for common guest helpers.
We can move more code into this class later.

Makefile
PVE/GuestHelpers.pm [new file with mode: 0644]

index 6c7ea4ed56c093b3c54a3296020c4dd3f9113c19..e1356a0233d0fea7faa698abad7848b824fa9c8c 100644 (file)
--- 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 (file)
index 0000000..d066527
--- /dev/null
@@ -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;