Commit 9f0b4c4b authored by Kirk Webb's avatar Kirk Webb

Re-tool Lease->UsingResources() into Lease->GetReservations()

I needed more info back about the set of reservations referencing a
particular lease. Existing code updated to compensate.

Also includes some bug fixes.
parent eb985c84
......@@ -677,7 +677,6 @@ sub exportSlice($$$$) {
return -1;
}
my $bsid = $sconf->{'BSID'};
my $volname = $sconf->{'VOLNAME'};
$volname = "UNKNOWN" if (!$volname);
......@@ -730,8 +729,8 @@ sub exportSlice($$$$) {
# initiator group identifier instead of the vnode_id because this
# entry may end up being shared (simultaneous RO use).
my $tag_ident = $vnode_id;
if ($bsid =~ /^lease-\d+$/) {
$tag_ident = $bsid;
if ($priv->{'volume'} =~ /^lease-\d+$/) {
$tag_ident = $priv->{'volume'};
}
# Go through the whole iSCSI extent/target setup if it hasn't been
......@@ -1166,7 +1165,6 @@ sub removeVlanInterface($$) {
sub unexportSlice($$$$) {
my ($vnode_id, $sconf, $vnconfig, $priv) = @_;
my $bsid = $sconf->{'BSID'};
my $volname = $sconf->{'VOLNAME'};
$volname = "UNKNOWN" if (!$volname);
......@@ -1190,7 +1188,7 @@ sub unexportSlice($$$$) {
# iSCSI auth group identifier instead of the vnode_id because
# this entry may be shared (simultaneous RO use).
my $tag_ident = $vnode_id;
if ($bsid =~ /^(lease-\d+)$/) {
if ($sconf->{'UUID'} =~ /:(lease-\d+)$/) {
$tag_ident = $1; # untaint
}
......
......@@ -465,6 +465,12 @@ sub Reserve($$$$$)
# size, to indicate nothing has actually been reserved in the
# blockstore_state table.
#
# However, if this is a lease (dataset), then we are just going to
# stuff the full size of it into the reserved_blockstores table
# and forgo any other capacity accounting. Also, its
# 'remaining_capacity' is always its full size. This allows for
# simultaneous read-only use (modes enforced elsewhere).
#
$query_result =
DBQueryWarn("select size from reserved_blockstores ".
"where exptidx='$exptidx' and bsidx='$bsidx' and ".
......@@ -472,11 +478,16 @@ sub Reserve($$$$$)
goto bad
if (!$query_result);
my $newsize = 0;
if ($self->lease_idx() > 0) {
$newsize = $self->total_size();
}
if (! $query_result->numrows) {
if (! DBQueryWarn("insert into reserved_blockstores set ".
" bsidx='$bsidx', node_id='$bs_node_id', bs_id='$bs_id', ".
" vname='$bs_name', pid='$pid', eid='$eid', ".
" size='0', vnode_id='$vnode_id', ".
" size='$newsize', vnode_id='$vnode_id', ".
" exptidx='$exptidx', rsrv_time=now()")) {
goto bad;
}
......@@ -502,6 +513,10 @@ sub Reserve($$$$$)
if ($current_size);
}
# Leases do not require any further size accounting updates.
goto done
if ($self->lease_idx() > 0);
#
# Now do an atomic update that changes both tables.
#
......
......@@ -469,24 +469,11 @@ sub InUseReadWrite() {
return LEASE_ERROR_FAILED()
if (!ref($self));
my $expts = $self->UsingResources();
if (@$expts) {
my $bs = Blockstore->LookupByLease($self->lease_idx());
if (!$bs) {
print STDERR "Lease->InUseReadWrite(): $self is not a ".
"blockstore lease?\n";
return LEASE_ERROR_FAILED();
}
# We only need to check the first experiment in the list. No
# concurrent use/mix of RO and RW is allowed.
my $firstexpt = Experiment->Lookup($expts->[0]);
my $resv = Blockstore::Reservation->Lookup($bs, $firstexpt);
if (!$resv) {
print STDERR "Lease->InUseReadWrite(): $self is not actually ".
"reserved to $experiment!\n";
return LEASE_ERROR_FAILED();
}
$rw = $resv->IsReadOnly() == 0 ? 1 : 0;
my $resvref = $self->GetReservations();
if ($resvref && @$resvref) {
# We only need to check the first reservation in the list since no
# concurrent mix of RO and RW is allowed.
$rw = $resvref->[0]->IsReadOnly() ? 0 : 1;
}
return $rw;
......@@ -498,7 +485,7 @@ sub InUse($) {
return LEASE_ERROR_FAILED()
if (!ref($self));
my $lref = $self->UsingResources();
my $lref = $self->GetReservations();
if (!$lref) {
return 0;
}
......@@ -507,16 +494,17 @@ sub InUse($) {
}
#
# Returns a list of experiment indicies that are currently using the
# resources associated with this lease.
# Returns a list of blockstore reservations that are currently using the
# resources associated with this lease. XXX: this is a blockstore-specific
# function.
#
sub UsingResources($) {
sub GetReservations($) {
my ($self) = @_;
return undef
if (!ref($self));
my @eidxlist = ();
my @resvlist = ();
#
# Before doing a big honkin query, see if the lease has resources
......@@ -526,17 +514,22 @@ sub UsingResources($) {
my $lidx = $self->lease_idx();
my $query_result =
DBQueryWarn("select r.exptidx from blockstores as b,".
DBQueryWarn("select r.vnode_id from blockstores as b,".
" reserved_blockstores as r,project_leases as l ".
"where b.bsidx=r.bsidx ".
" and b.lease_idx=l.lease_idx ".
" and l.lease_idx='$lidx'");
while (my ($eidx) = $query_result->fetchrow_array()) {
push(@eidxlist, $eidx);
return undef
if (!$query_result);
while (my ($vnode_id,) = $query_result->fetchrow_array()) {
next if (!$vnode_id);
push(@resvlist,
Blockstore::Reservation->LookupByNodeid($vnode_id));
}
}
return \@eidxlist;
return \@resvlist;
}
#
......
......@@ -6922,8 +6922,9 @@ sub HandleBlockstore($$$$$$@)
#
if ($lease->InUse()) {
# This will always be one for now.
my ($exptidx) = @{ $lease->UsingResources() };
if (defined($exptidx) && $exptidx != $experiment->idx()) {
my ($reservation) = @{ $lease->GetReservations() };
if (defined($reservation) &&
$reservation->exptidx() != $experiment->idx()) {
$message = "Dataset $leasename is already in use";
goto bad;
}
......
......@@ -706,7 +706,7 @@ sub lease_list(@)
if ($lease->last_used()) {
$ltime = strftime("%D %R", localtime($lease->last_used()));
}
my $lusers = $lease->UsingResources();
my $lusers = $lease->GetReservations();
if (!$lusers) {
$lusers = ();
}
......
......@@ -900,7 +900,7 @@ sub GenDefsFile($)
#
if ($lease->state() eq LEASE_STATE_VALID()) {
# Force RO if user does not have RW privs.
$ro = !$lease->allow_modify();
$ro = $lease->allow_modify() ? 0 : 1;
} elsif ($lease->state() eq LEASE_STATE_GRACE()) {
$ro = 1;
} else {
......@@ -912,7 +912,7 @@ sub GenDefsFile($)
my $bstore = Blockstore->LookupByLease($idx);
next if (!$bstore);
my $name = "$pid/" . $lease->lease_id();
my $name = $lease->pid() ."/". $lease->lease_id();
my $type = $lease->type();
my $node = $bstore->node_id();
my $bsid = $bstore->bs_id();
......
......@@ -184,7 +184,7 @@ if (!defined($waittime)) {
# if the lease is in use, disallow unless forced
if ($lease->InUse()) {
my $expts = int(@{$lease->UsingResources()});
my $expts = int(@{$lease->GetReservations()});
if ($force < 2) {
fatal("$pid/$lname is in use by $expts experiment(s) right now");
}
......
......@@ -307,7 +307,7 @@ if (@lids > 0) {
my $stime = datestr($lease->inception());
my $etime = datestr($lease->lease_end());
my $ltime = datestr($lease->last_used());
my $lusers = $lease->UsingResources();
my $lusers = $lease->GetReservations();
if (!$lusers) {
$lusers = ();
}
......
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