Commit 86e47193 authored by Kirk Webb's avatar Kirk Webb

Implement lock/unlock. Make "replace" an explicit flag for Store()

Clean up some comments and error messages.
parent dc5fc29e
......@@ -39,13 +39,14 @@ use vars qw(@ISA @EXPORT);
use English;
use emdb;
use emutil qw( TBGetUniqueIndex );
use libtestbed;
use libtblog_simple;
use Experiment;
use IPBuddyAlloc;
use Socket;
use Data::Dumper;
# Constants
my $BUDDYRESLOCK = "reserved_addresses";
# Prototypes
......@@ -104,18 +105,27 @@ sub _newrange($$$) { $_[0]->_putrange($_[1],$_[2]);
push @{$_[0]->_allnew()}, $_[2]; }
#
# XXX: implement
# Grab the reserved address lock.
#
sub lock($) {
my $self = shift;
# Use a file lock instead of a table lock since we don't know what
# other tables might be used while this is locked.
TBScriptLock($BUDDYRESLOCK) == TBSCRIPTLOCK_OKAY()
or return 0;
return 1;
}
#
# XXX: implement
# Release the lock.
#
sub unlock($) {
my $self = shift;
TBScriptUnlock();
return 1;
}
......@@ -170,7 +180,7 @@ sub loadReservedRanges($;$) {
my $mask = inet_aton($vlrow->mask());
my $prefix = unpack('%32b*', $mask);
my $base = inet_ntoa($ip & $mask);
next if !$self->_getrange("$base/$prefix");
next if $self->_getrange("$base/$prefix");
my $rval = eval { $bud->embedAddressRange("$base/$prefix") };
if ($@) {
# Just skip if the current range isn't in the base
......
......@@ -38,6 +38,7 @@ use Data::Dumper;
use overload ('""' => 'Stringify');
use vars qw($STORE_FLAGS_DEBUG $STORE_FLAGS_IMPOTENT $STORE_FLAGS_SIMPARSE
$STORE_FLAGS_REPLACE
$LOOKUP_FLAGS_NOLOAD
%virtual_tables %experiment_fields
$AUTOLOAD @EXPORT_OK);
......@@ -46,12 +47,14 @@ use vars qw($STORE_FLAGS_DEBUG $STORE_FLAGS_IMPOTENT $STORE_FLAGS_SIMPARSE
$STORE_FLAGS_DEBUG = 0x01;
$STORE_FLAGS_IMPOTENT = 0x02;
$STORE_FLAGS_SIMPARSE = 0x04;
$STORE_FLAGS_REPLACE = 0x08;
# Lookup Flags
$LOOKUP_FLAGS_NOLOAD = 0x01;
# Why, why, why?
@EXPORT_OK = qw($STORE_FLAGS_DEBUG $STORE_FLAGS_IMPOTENT
$STORE_FLAGS_SIMPARSE $LOOKUP_FLAGS_NOLOAD);
$STORE_FLAGS_SIMPARSE $STORE_FLAGS_REPLACE
$LOOKUP_FLAGS_NOLOAD);
# Configure variables
my $TB = "@prefix@";
......@@ -935,6 +938,7 @@ sub Store($;$)
my $debug = ($flags & $VirtExperiment::STORE_FLAGS_DEBUG ? 1 : 0);
my $impotent = ($flags & $VirtExperiment::STORE_FLAGS_IMPOTENT ? 1 : 0);
my $simparse = ($flags & $VirtExperiment::STORE_FLAGS_SIMPARSE ? 1 : 0);
my $replace = ($flags & $VirtExperiment::STORE_FLAGS_REPLACE ? 1 : 0);
my $tablename= $self->tablename();
my $row = $self->tablerow();
my $pid = $self->experiment()->pid();
......@@ -999,7 +1003,7 @@ sub Store($;$)
return -1;
}
my $query;
if ($simparse) {
if ($simparse || $replace) {
#
# If we are called after an nseparse, we need to use replace
# coz some of the tables such as virt_agents and eventlist are
......
......@@ -7679,7 +7679,7 @@ sub SetUpTracing($$$$$)
# This usually means getting a new mutually exclusive address range,
# reserving it for this experiment in the database. Substitute
# addresses on co-located link/lan members to accomodate. This
# reservation does _NOT_ persist across swapins.
# reservation purposely does _NOT_ persist across swapins.
#
sub CheckIPAddressReservations($) {
my ($self) = @_;
......@@ -7702,9 +7702,10 @@ sub CheckIPAddressReservations($) {
my $vnodename = $member->vnode();
my $virtnode = $member->virt_node();
my $vtype = $virtnode->type();
# XXX: This isn't quite right. Need to figure out how to check
# to see if the lan member is attached to a 'sanhost', but I can't
# figure out the right path through the libvtop objects...
# XXX: This isn't quite right. Need to figure out how to
# check to see if the current lan member is attached to a
# 'sanhost', but I can't figure out the right path through
# the libvtop objects...
if ($vtype eq "blockstore") {
push @sharedlans, $virtlan;
next virtlans;
......@@ -7724,11 +7725,11 @@ sub CheckIPAddressReservations($) {
# dependencies. If we find ourselves using it in other places,
# then move this up to package scope.
require IPBuddyWrapper;
# Tie this buddy allocator to the "storage_host" global address range.
# Tie this buddy allocator to the "storage_pool" global address range.
my $buddy = IPBuddyWrapper->new("storage_pool");
return -1
unless defined($buddy);
# This call will lock the "reserved_addresses" table.
# Grab the reserved addresses buddy allocator lock.
$buddy->lock()
or return -1;
# Now preload the reservations in the DB, including those associated
......@@ -7784,11 +7785,9 @@ sub CheckIPAddressReservations($) {
$self->printdb("$vnodename: $ip -> $new_ip\n");
$vmember->ip($new_ip);
$vmember->mask($newmask);
# XXX: This is a bit hacky, but the only impact
# setting the "simparse" flag has on the Store()
# method is to use "replace" instead of "insert" in
# the query. This is what we need here.
my $sflags = $VirtExperiment::STORE_FLAGS_SIMPARSE;
# Replace the virt_lans row. It already exists, so an insert
# would fail.
my $sflags = $VirtExperiment::STORE_FLAGS_REPLACE;
$sflags |= $self->verbose() ?
$VirtExperiment::STORE_FLAGS_DEBUG :
0;
......@@ -7796,7 +7795,7 @@ sub CheckIPAddressReservations($) {
$VirtExperiment::STORE_FLAGS_IMPOTENT :
0;
if ($vmember->Store($sflags) != 0 && !$self->impotent()) {
tberror("Could not store updated vlan_member entry!\n");
tberror("Could not store updated virt_lans row!\n");
$buddy->unlock();
return -1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment