[pve-devel] r5439 - pve-cluster/trunk/data/perl

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Jan 25 11:28:18 CET 2011


Author: dietmar
Date: 2011-01-25 11:28:18 +0100 (Tue, 25 Jan 2011)
New Revision: 5439

Modified:
   pve-cluster/trunk/data/perl/Cluster.pm
Log:
implement template (only support local locks)


Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-01-25 10:25:18 UTC (rev 5438)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-01-25 10:28:18 UTC (rev 5439)
@@ -13,10 +13,16 @@
 use Encode;
 use base 'Exporter';
 
-our @EXPORT_OK = qw(cfs_read_file cfs_write_file cfs_register_file);
+our @EXPORT_OK = qw(
+cfs_read_file 
+cfs_write_file 
+cfs_register_file 
+cfs_lock_file);
 
 use Data::Dumper; # fixme: remove
 
+my $lockdir = "/var/lock/pve-manager";
+mkdir $lockdir;
 
 # x509 certificate utils
 
@@ -465,6 +471,19 @@
     PVE::Tools::file_set_contents($fsname, $raw);
 }
 
+sub cfs_lock_file {
+    my ($filename, $timeout, $text, $code, @param) = @_;
+
+    my $info = $file_info->{$filename} || die "unknown file '$filename'";
+
+    my $lockid = $filename;
+    $lockid =~ s/[.\/]/_/g;
+
+    # fimxe: do cluster wide lock instead
+
+    PVE::Tools::lock_file("$lockdir/.lock-file-$lockid", $timeout, $text, $code, @param);
+}
+
 my $log_levels = {
     "emerg" => 0,
     "alert" => 1,




More information about the pve-devel mailing list