Commit c5a1812c authored by Mike Hibler's avatar Mike Hibler

First attempt to cleanup some hack jobs.

Make a createdataset to handle dataset leases and move dataset specific
code out of approvelease and into Lease.pm (which is now Lease.pm.in as
it needs to be configured). Lease.pm still needs a bunch of OO-ification
to properly make datasets a subclass of leases. But, another day...
parent fdef02e5
......@@ -86,6 +86,8 @@ use vars qw(@ISA @EXPORT);
LEASE_STATE_VALID LEASE_STATE_UNAPPROVED LEASE_STATE_GRACE
LEASE_STATE_LOCKED LEASE_STATE_EXPIRED
LEASE_ERROR_NONE LEASE_ERROR_FAILED LEASE_ERROR_BUSY
DBLIMIT_NSFILESIZE NODERELOADPENDING_EID
NODEREPOSITIONING_PID NODEREPOSITIONING_EID NODEREPOSPENDING_EID
......@@ -403,6 +405,11 @@ sub LEASE_STATE_LOCKED() { "locked"; }
sub LEASE_STATE_EXPIRED() { "expired"; }
sub LEASE_STATE_INITIALIZING() { "initializing"; }
# Lease Error returns
sub LEASE_ERROR_NONE() { 0; }
sub LEASE_ERROR_FAILED() { -1; }
sub LEASE_ERROR_BUSY() { -2; }
# Node Log Types
sub TB_NODELOGTYPE_MISC { "misc"; }
sub TB_NODELOGTYPES() { ( TB_NODELOGTYPE_MISC() ) ; }
......
This diff is collapsed.
......@@ -35,7 +35,8 @@ BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config \
setdest loghole webcopy linkmon_ctl snmp-if-deref.sh \
template_record spewevents \
wbts_dump mkblob rmblob \
showlease createlease deletelease modlease approvelease
showlease createlease deletelease modlease approvelease \
createdataset
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping grantnodetype import_commitlog daemon_wrapper \
opsreboot deletenode node_statewait grabwebcams \
......
......@@ -44,7 +44,6 @@ my $debug = 0;
my $pid;
my $state = "valid";
my $lname;
my $now = time();
my $lease;
# Protos
......@@ -54,7 +53,6 @@ sub fatal($);
# Configure variables
#
my $TB = "@prefix@";
my $BSCONTROL = "$TB/sbin/bscontrol";
#
# Testbed Support libraries
......@@ -107,7 +105,10 @@ if ($lname =~ /^([-\w]+)\/([-\w]+)$/) {
fatal("Lease name $lname not in the form <pid>/<lname>.");
}
# XXX must be admin right now
#
# Normally, leases are approved at creation time. To approve other leases
# explicitly, you must be admin.
#
if (!TBAdmin()) {
fatal("Only admins can approve leases.");
}
......@@ -132,63 +133,18 @@ if (!$lease) {
if (!$lease->AccessCheck($this_user, LEASE_ACCESS_MODIFY())) {
fatal("$pid/$lname: you are not allowed to modify lease.");
}
# Lock the lease once we start messing with the state.
if ($lease->Lock()) {
fatal("$pid/$lname: currently locked, try again later.");
}
if ($lease->state() ne "unapproved") {
fatal("$pid/$lname: lease has already been approved!?");
fatal("$pid/$lname: lease has already been approved.");
}
#
# Check new state. Must be something other than "unapproved".
#
if ($state eq "unapproved") {
fatal("$pid/$lname: must set to one of the approved states.");
}
#
# Force allocation of storage for dataset leases.
# We put the lease in the special "initializing" state while doing this.
#
if ($lease->type() =~ /dataset$/) {
#
# Must be an associated size attribute.
#
my $size = $lease->GetAttribute("size");
if ($size && $size =~ /^(\d+)$/) {
$size = $1;
} else {
fatal("$pid/$lname: no valid 'size' attribute");
}
#
# Mark the lease as in-transition and unlock it since allocating
# storage could take a long time.
#
if ($lease->UpdateState("initializing")) {
fatal("$pid/$lname: could not set state to 'initializing'.");
}
$lease->Unlock();
#
# Call the blockstore control program to handle all things blockstore
# related (e.g., the actual allocation of storage on the storage servers).
#
my $idx = $lease->lease_idx();
if (system("$BSCONTROL -l $idx -s $size create lease-$idx")) {
$lease->UpdateState("unapproved");
fatal("$pid/$lname: could not allocate storage");
}
# no need to re-lock transitioning out of initializing state
$lease->UpdateState($state);
print "$pid/$lname: allocated $size MiB of storage\n";
} else {
$lease->UpdateState($state);
$lease->Unlock();
# Do it.
if ($lease->Approve($state)) {
fatal("$pid/$lname: could not approve lease into state '$state'");
}
# It all worked!
......@@ -199,9 +155,6 @@ sub fatal($)
{
my ($mesg) = $_[0];
if (defined($lease) && $lease->GotLock()) {
$lease->Unlock();
}
die("*** $0:\n".
" $mesg\n");
}
This diff is collapsed.
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