Commit fc2a5b7c authored by Leigh Stoller's avatar Leigh Stoller

Add TBdbfork(), a terribly bogus hack to deal with dropping and

recreating the connection to the DB across a fork. It appears that
with the connection shared, DB queries can fail. It would be nice if
PERL had fork handlers.

Add TBSetNodeEventState() and TBGetNodeEventState() library routines,
and some constants for the event tags.

Beef up the experiment access check code to handle destroy as a
distinct case.
parent 3bd834ad
......@@ -66,6 +66,10 @@ use Exporter;
TB_ASSIGN_TOOFEWNODES TB_OPSPID
TBDB_TBEVENT_ISUP TBDB_TBEVENT_REBOOT
TBDB_NODESTATE_ISUP TBDB_NODESTATE_REBOOT TBDB_NODESTATE_UNKNOWN
TBSetNodeEventState TBGetNodeEventState
TBAdmin TBProjAccessCheck TBNodeAccessCheck TBOSIDAccessCheck
TBImageIDAccessCheck TBExptAccessCheck ExpLeader MarkNodeDown
SetNodeBootStatus OSFeatureSupported IsShelved NodeidToExp
......@@ -74,7 +78,7 @@ use Exporter;
ExpNodes DBDateTime DefaultImageID GroupLeader TBGroupUnixInfo
TBValidNodeLogType TBValidNodeName TBSetNodeLogEntry
TBSetSchedReload MapNodeOSID TBLockExp TBUnLockExp TBSetExpSwapTime
TBUnixGroupList TBOSID TBImageID
TBUnixGroupList TBOSID TBImageID TBdbfork
);
# Must come after package declaration!
......@@ -94,6 +98,12 @@ my $TBOPSPID = "emulab-ops";
#
my $DB = Mysql->connect("localhost", $DBNAME, "script", "none");
sub TBdbfork()
{
undef($DB);
$DB = Mysql->connect("localhost", $DBNAME, "script", "none");
}
#
# Record last DB error string.
#
......@@ -223,6 +233,19 @@ sub TB_ASSIGN_TOOFEWNODES() { 2; }
# System PID.
sub TB_OPSPID() { $TBOPSPID; }
#
# TBCONTROL Events
#
sub TBDB_TBEVENT_ISUP() { "ISUP"; }
sub TBDB_TBEVENT_REBOOT() { "REBOOT"; }
#
# For nodes, we use this set of events.
#
sub TBDB_NODESTATE_ISUP() { TBDB_EVENTTYPE_ISUP; }
sub TBDB_NODESTATE_REBOOT() { TBDB_EVENTTYPE_REBOOT; }
sub TBDB_NODESTATE_UNKNOWN() { "UNKNOWN"; };
#
# We should list all of the DB limits.
#
......@@ -456,16 +479,27 @@ sub TBExptAccessCheck($$$$)
$uid = MapNumericUID($uid);
my $query_result =
DBQueryFatal("SELECT gid FROM experiments WHERE ".
DBQueryFatal("SELECT gid,expt_head_uid FROM experiments WHERE ".
"eid='$eid' and pid='$pid'");
if ($query_result->numrows == 0) {
return 0;
}
my @row = $query_result->fetchrow_array();
my $gid = $row[0];
my $gid = $row[0];
my $creator = $row[1];
if ($access_type == TB_EXPT_READINFO) {
#
# An experiment may be destroyed by the experiment creator or the
# project/group leader.
#
if ($access_type == TB_EXPT_DESTROY) {
if ($uid eq $creator) {
return 1;
}
$mintrust = PROJMEMBERTRUST_GROUPROOT;
}
elsif ($access_type == TB_EXPT_READINFO) {
$mintrust = PROJMEMBERTRUST_USER;
}
else {
......@@ -1290,6 +1324,48 @@ sub TBSetSchedReload($$;$)
return 0;
}
#
# Set event state for a node.
#
# usage: TBSetNodeEventState(char *node, char *state)
# Returns 1 if okay.
# Returns 0 if failed.
#
sub TBSetNodeEventState($$)
{
my ($node, $state) = @_;
return DBQueryFatal("update nodes set eventstatus='$state' ".
"where node_id='$node'");
}
#
# Get event state for a node.
#
# usage: TBGetNodeEventState(char *node, char \*state)
# Returns 1 if okay (and sets state).
# Returns 0 if failed.
#
sub TBGetNodeEventState($$)
{
my ($node, $state) = @_;
my $query_result =
DBQueryFatal("select eventstatus from nodes where node_id='$node'");
if ($query_result->numrows == 0) {
return 0;
}
my @row = $query_result->fetchrow_array();
if (defined($row[0])) {
$$state = $row[0];
}
else {
$$state = TBDB_NODESTATE_UNKNOWN;
}
return 1;
}
#
# Issue a DB query. Argument is a string. Returns the actual query object, so
# it is up to the caller to test it. I would not for one moment view this
......
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