From 37d09d99298b5c7f46a76edf0b38dee6bda12871 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 17 Aug 2011 18:06:34 +0000 Subject: [PATCH] Implement locking around data store configuration git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10303 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/esx.pm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index eded5c862..83698f1d6 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -17,6 +17,7 @@ use POSIX qw(WNOHANG nice); use File::Path qw/mkpath rmtree/; use File::Temp qw/tempdir/; use File::Copy; +use Fcntl qw/:flock/; use IO::Socket; #Need name resolution #use Data::Dumper; Getopt::Long::Configure("bundling"); @@ -54,7 +55,21 @@ my $vmwaresdkdetect = eval { VMware::VIRuntime->import(); 1; }; +my %lockhandles; +sub lockbyname { + my $name = shift; + my $lckh; + mkpath("/tmp/xcat/locks/"); + while (-e "/tmp/xcat/locks/$name") { sleep 1; } + open($lockhandles{$name},">>","/tmp/xcat/locks/$name"); + flock($lockhandles{$name},LOCK_EX); +} +sub unlockbyname { + my $name = shift; + unlink("/tmp/xcat/locks/$name"); + close($lockhandles{$name}); +} my %guestidmap = ( "rhel.6.*" => "rhel6_", @@ -3561,6 +3576,16 @@ sub refreshclusterdatastoremap { #a whole cluster instead of chasing one host, a whole lot slower. One would hope vmware would've done this, but they don't } sub validate_datastore_prereqs { + my $hyp = $_[1]; + lockbyname($hyp.".datastores"); + $@=""; + my $rc; + eval { $rc=validate_datastore_prereqs_inlock(@_); }; + unlockbyname($hyp.".datastores"); + if ($@) { die $@; } + return $rc; +} +sub validate_datastore_prereqs_inlock { my $nodes = shift; my $hyp = shift; my $newdatastores = shift; # a hash reference of URLs to afflicted nodes outside of table space @@ -3627,7 +3652,7 @@ sub validate_datastore_prereqs { my $uri = "nfs://$server/$path"; unless ($hyphash{$hyp}->{datastoremap}->{$uri}) { #If not already there, must mount it unless ($datastoreautomount) { - xCAT::SvrUtils::sendmsg([1,":) $uri is not currently accessible at the given location and automount is disabled in site table"], $output_handler,$node); + xCAT::SvrUtils::sendmsg([1,": $uri is not currently accessible at the given location and automount is disabled in site table"], $output_handler,$node); return 0; } $refresh_names=1;