Commit 53da48f7 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Merge branch 'master' of git-public.flux.utah.edu:/flux/git/emulab-devel

parents f018d5a9 4cdb4c7f
......@@ -4383,6 +4383,10 @@ sub ReserveSharedBandwidth($;$$)
$query_result = $previous_result;
$previous_result = $tmp;
}
# Need to do this when we want to seek around inside the results.
$previous_result = $previous_result->WrapForSeek()
if (defined($previous_result));
$query_result = $query_result->WrapForSeek();
#
# This is how much we need to release.
......
......@@ -3060,6 +3060,7 @@ sub RecordVLanDeletion($$)
sub RecordVLanModification($$$$)
{
my ($class, $lanid, $added, $removed) = @_;
my %current = ();
my $query_result =
DBQueryWarn("select members from vlans where id='$lanid'");
......@@ -3067,7 +3068,9 @@ sub RecordVLanModification($$$$)
return -1
if (!$query_result);
my ($current) = $query_result->fetchrow_array();
my %current = map { $_ => $_ } split(/\s+/, $current);
if (defined($current) && $current ne "") {
%current = map { $_ => $_ } split(/\s+/, $current);
}
if ($added) {
foreach my $port (@$added) {
......
......@@ -167,8 +167,18 @@ sub Lookup($$)
return undef
if (!$query_result || !$query_result->numrows);
#
# Make a copy of the array. Still fighting memory corruption error.
#
my $hash_orig = $query_result->fetchrow_hashref();
my $hash_copy = {};
foreach my $key (keys(%{ $hash_orig })) {
my $val = $hash_orig->{$key};
$hash_copy->{$key} = $val;
}
my $self = {};
$self->{"DBROW"} = $query_result->fetchrow_hashref();
$self->{"DBROW"} = $hash_copy;
$self->{"RSRV"} = undef;
$self->{"TYPEINFO"} = undef;
$self->{"ATTRS"} = undef;
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# Copyright (c) 2005-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Mysql;
#
# usage: dumperrorlog.proxy
......@@ -44,6 +43,7 @@ $| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libtestbed;
use libtbdb;
sub fatal($) {
my ($msg) = @_;
......@@ -78,17 +78,10 @@ else {
fatal("Bad characters in password!");
}
my $DB = Mysql->connect('localhost', $DBNAME, $DBUSER, $pwd);
fatal("Could not connect to errorlog DB!")
if (!defined($DB));
my $query_result =
$DB->query("load data infile '${tempfile}.${tablename}' ".
"replace into table $tablename");
if (! defined($query_result)) {
fatal("DB Error: " . $DB->errstr . "\n");
if (TBDBConnect($DBNAME, $DBUSER, $pwd) < 0) {
fatal("Could not connect to errorlog database!");
}
DBQueryFatal("load data infile '${tempfile}.${tablename}' ".
"replace into table $tablename");
exit(0);
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
......@@ -137,6 +137,10 @@ my $users_result =
DBQueryFatal("select distinct u.uid,u.uid_idx,u.admin,u.status ".
" from group_membership as m ".
"left join users as u on u.uid_idx=m.uid_idx ");
# Need to do this we want to seek around inside the results.
$users_result = $users_result->WrapForSeek();
while (my ($uid,$uid_idx,$admin,$status) = $users_result->fetchrow_array()) {
next
if ($uid eq "elabman");
......
......@@ -42,6 +42,8 @@ sub TBDBConnect($) { return emdbi::TBDBConnect($_[0], $DBNAME); }
sub TBDBReconnect($) { return emdbi::TBDBReconnect($_[0]); }
sub TBDBDisconnect() { return emdbi::TBDBDisconnect(); }
sub NewTBDBHandle() { return emdbi::NewTBDBHandle($DBNAME); }
sub DBHandle() { return emdbi::DBHandleN(0); }
sub DBHandleN($) { return emdbi::DBHandleN($_[0]); }
sub DBQueryN($$) { return emdbi::DBQueryN($_[0], $_[1]); }
sub DBQuery($) { return emdbi::DBQuery($_[0]); }
sub DBQueryFatalN($$) { return emdbi::DBQueryFatalN($_[0], $_[1]); }
......
......@@ -65,7 +65,21 @@ sub Wrap($$$)
sub pid($) { return $_[0]->{'PID'}; };
sub dbh($) { return $_[0]->{'DBH'}; };
sub dbname($) { return $_[0]->{'DBNAME'}; };
sub query($$) { return $_[0]->dbh->query($_[1]); };
#
# Need to wrap the return value. See below.
#
sub query($$)
{
my ($self, $query) = @_;
my $result = $self->dbh->query($query);
return undef
if (!defined($result));
# See below.
bless($result, "emdbi_wrapper::Mysql::Statement");
return $result;
}
sub DESTROY
{
......@@ -78,6 +92,16 @@ sub DESTROY
if $self->dbh()->can("SUPER::DESTROY");
}
#############################################################################
# Trivial wrapper for the Mysql statement so that we can add a method.
#
package emdbi_wrapper::Mysql::Statement;
use vars '@ISA';
@ISA = ('Mysql::Statement');
# Natively supported, so nothing to worry about.
sub WrapForSeek($) { return $_[0]; }
#############################################################################
#
# We are making the transition to DBI so we can stop using the ancient
......@@ -86,6 +110,7 @@ sub DESTROY
package emdbi_wrapper::DBI;
use vars '@ISA';
@ISA = ('DBI::db');
use Data::Dumper;
sub Wrap($$$)
{
......@@ -151,7 +176,6 @@ package emdbi_wrapper::DBI::st;
use vars '@ISA';
@ISA = ('DBI::st');
sub dataseek($$) { return $_[0]->func($_[1], 'dataseek'); };
sub numrows($) { return $_[0]->rows(); };
sub num_rows($) { return $_[0]->rows(); };
sub affectedrows($) { return $_[0]->rows(); };
......@@ -169,6 +193,137 @@ sub fetchhash($)
return ($ref ? %$ref : ());
}
# Not supported so generate an error.
sub dataseek($$)
{
DBWarn("Attempt to 'seek' not supported. Better fix it!");
}
# This is how we do it. See below.
sub WrapForSeek($) { return emdbi_wrapper::DBI::WrapForSeek->Wrap($_[0]); }
#############################################################################
# Another wrapper. DBI does not implement "seek" or "rewind". The only way
# to do this is suck all the data out and save it. We do not want to do this
# for every query though, so anyplace we want to seek around, wrap things
# up with this, and then use it like a normal query result.
#
package emdbi_wrapper::DBI::WrapForSeek;
use Data::Dumper;
sub Wrap($$)
{
my ($class, $sth) = @_;
my @data = ();
my @names = ();
#
# This tells us the original select column ordering.
#
my $names = $sth->{'NAME'};
my $numFields = $sth->{'NUM_OF_FIELDS'};
for (my $i = 0; $i < $numFields; $i++) {
push(@names, $$names[$i]);
}
#
# Grab all the rows. 90 percent of queries request rows as
# arrays, so lets do that. We can construct a hash using the
# column names we grabbed above.
#
while (my $rowref = $sth->fetchrow_arrayref()) {
#
# This looks weird and pointless, but there is some funky
# memory stuff going in underneath; if we do not make a copy
# explicitly, each successive row overwrites the previous row.
# Not very perl like.
#
my @row = @$rowref;
push(@data, \@row);
}
my $self = {};
$self->{'STH'} = $sth;
$self->{'ROWS'} = $sth->rows();
$self->{'COLNAMES'} = \@names;
$self->{'COLCOUNT'} = scalar(@names);
$self->{'DATA'} = \@data;
$self->{'IDX'} = 0;
bless($self, $class);
return $self;
}
sub sth($) { return $_[0]->{'STH'}; };
sub rows($) { return $_[0]->{'ROWS'}; };
sub idx($) { return $_[0]->{'IDX'}; };
sub incridx($) { return $_[0]->{'IDX'}++; };
sub data($) { return $_[0]->{'DATA'}; };
sub colnames($) { return $_[0]->{'COLNAMES'}; };
sub colcount($) { return $_[0]->{'COLCOUNT'}; };
sub numrows($) { return $_[0]->{'ROWS'}; };
sub num_rows($) { return $_[0]->{'ROWS'}; };
sub affectedrows($) { return $_[0]->{'ROWS'}; };
sub insertid($) { return $_[0]->sth()->{'mysql_insertid'}; };
sub dataseek($$) { $_[0]->{'IDX'} = $_[1]; };
sub fetchrow_arrayref($)
{
my ($self) = @_;
my $data = $self->data();
my $idx = $self->idx();
return undef
if ($idx >= $self->rows());
$self->incridx();
return $data->[$idx];
}
sub fetchrow_array($)
{
my ($self) = @_;
my $ref = $self->fetchrow_arrayref();
return ()
if (!defined($ref));
return @{ $ref };
}
sub fetchrow_hashref($)
{
my ($self) = @_;
my $ref = $self->fetchrow_arrayref();
return undef
if (!defined($ref));
#
# Construct a hash using the column names
#
my %hash = ();
my $count = $self->colcount();
for (my $i = 0; $i < $count; $i++) {
$hash{$self->colnames()->[$i]} = $ref->[$i];
}
return \%hash;
}
sub fetchrow($)
{
my ($self) = @_;
my @row = $self->fetchrow_array();
return (@row ? (wantarray ? @row : $row[0]) : ());
}
sub fetchhash($)
{
my ($self) = @_;
my $ref = $self->fetchrow_hashref();
return ($ref ? %$ref : ());
}
#############################################################################
# Back to the main package.
#
......@@ -598,6 +753,17 @@ sub DBKeyExistsN($$$)
}
sub DBKeyExists($$) { return DBKeyExistsN(0,$_[0],$_[1]); }
sub DBHandleN($)
{
my ($dbnum) = @_;
my $dbw = $DB[$dbnum];
my $db = $dbw->dbh();
return $db;
}
sub DBHandle() { return DBHandleN(0); }
END {
# Call it here otherwise may get:
# (in cleanup) Can't call method "FETCH" on an undefined value at
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -151,8 +151,6 @@ EOT
$q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
my @stillidle=();
while (%r = $q->fetchhash()) {
$pid = $r{'pid'};
......@@ -220,7 +218,6 @@ group by pid,eid having idlemin >= idleswap_timeout and staleness < 600
order by pid,eid
EOT
$q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
while (%r = $q->fetchhash()) {
$pid = $r{'pid'};
$eid = $r{'eid'};
......@@ -236,7 +233,6 @@ and paniced=0
having activemin>=autoswap_timeout order by pid,eid
EOT
$q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
while (%r = $q->fetchhash()) {
$pid = $r{'pid'};
$eid = $r{'eid'};
......@@ -267,14 +263,6 @@ idlemin+$idle_warnmin<=idleswap_timeout+$window and
idlemin >= $window order by pid,eid
EOT
$q = DBQueryFatal($sql);
if ($d) { print $sql,";\n",$q->as_string; $q->dataseek(0); }
# enable for extra debugging
if (0 && $q->numrows()>0) {
# SENDMAIL(To, Subject, Message, [From], [More Headers],...)
SENDMAIL("Mac <newbold\@flux.utah.edu>","idlemail warnings",
$q->as_string);
$q->dataseek(0);
}
while (%r = $q->fetchhash()) {
# These get an idlewarn message
$pid = $r{'pid'};
......@@ -300,14 +288,6 @@ having activemin+$auto_warnmin>=autoswap_timeout and
activemin+$auto_warnmin<=autoswap_timeout+$window order by pid,eid
EOT
$q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
# enable for extra debugging
if (0 && $q->numrows()>0) {
# SENDMAIL(To, Subject, Message, [From], [More Headers],...)
SENDMAIL("Mac <newbold\@flux.utah.edu>","idlemail warnings",
$q->as_string);
$q->dataseek(0);
}
while (%r = $q->fetchhash()) {
# These get an autowarn message
$pid = $r{'pid'};
......@@ -349,8 +329,6 @@ EOT
my $q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
if (%r = $q->fetchhash()) {
$pid = $r{'pid'};
$gid = $r{'gid'};
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2008 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -98,8 +98,6 @@ order by pid,eid,n.node_id";
my $q = DBQueryFatal($sql);
if ($d) { print $q->as_string; $q->dataseek(0); }
if ($s && $experiment) {
# No output; For a single experiment, there should be a single row.
my %row = $q->fetchhash();
......
......@@ -299,7 +299,7 @@ sub DBQuoteSpecial($;$)
if (!defined($handle)) {
$dbhandle = $DB;
} else {
$dbhandle = $dbhandle->{'DB'};
$dbhandle = $handle->{'DB'};
}
$string = $dbhandle->quote($string);
......@@ -320,7 +320,7 @@ sub DBDateTime(;$)
$seconds = 0;
}
return strftime("20%y-%m-%d %H:%M:%S", localtime(time() + $seconds));
return strftime("20%y-%m-%d %H:%M:%S", localtime(time() + $seconds));
}
# Binary mode for database query
......@@ -336,7 +336,7 @@ sub DBDateTime(;$)
sub DBBinaryQuery {
my ($handle, $statement, @data) = @_;
my $dbh = $handle->{'DB'}->{'dbh'};
my $dbh = $handle->{'DB'};
my $sth = $dbh->prepare($statement);
if (!$sth) {
$DBErrorString =
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -27,18 +27,17 @@ if ($#ARGV >= 1 || $#ARGV < 0) {
print "parameter (like 'myhost:0') on the command line, and it will \n";
print "attempt to open it.\n";
die("\n");
} else {
use Mysql;
require "ctime.pl";
}
use lib '@prefix@/lib';
use libtestbed;
use emdb;
require "ctime.pl";
my $display = shift;
my $v = 0; # Verbose
my $dbh = Mysql->connect("localhost","@TBDBNAME@","script","none");
my @tbls = $dbh->listtables;
my @tbls = map { $_ =~ s/.*\.//; $_ } emdb::DBHandle()->tables();
my $date = &ctime(time);
......@@ -79,7 +78,7 @@ my %forkeys=();
foreach $tbl ( @tbls ) {
push(@tablelist,$tbl);
print "Found $tbl:\n" if $v;
if ($sth = $dbh->query("describe $tbl") ) {
if ($sth = DBQueryFatal("describe $tbl") ) {
while ( @data = $sth->fetchrow()) {
$col = $data[0];
$col =~ s/[0-9\-]+$//;
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -38,30 +38,6 @@ my $extraopts = ($isvers5 ? "--skip-opt" : "");
#
my $mysqldump = "mysqldump $extraopts -t $DBNAME sitevariables";
#
# We use Mysql module instead of the testbed libraries, so that we can get
# a more precise feel for what the error is.
#
use Mysql;
#
# Check to see if the mysqld is running by trying to connect to it.
#
my $dbh = Mysql->connect(undef,undef,undef,undef);
if (!$dbh) {
fatal("Unable to connect to mysqld - Either it's not running or \n" .
"permission was denied.\n");
}
#
# Check to see if the database exists
#
my @dbs = $dbh->listdbs();
if (! grep (/^$DBNAME$/,@dbs)) {
fatal("Database $DBNAME does not exist in the running database\n");
}
undef $dbh;
#
# Make sure we can write the temporary file
#
......
#
# Snmpit changes. vlan tags are managed exclusively in the DB now
# rather then on the switches. All of vlans are associated with an
# experiment; system vlans are associated with emulab-ops/vlan-holding.
# This script simply creates the holding experiment; a later script
# will do the rest of whatever is needed.
#
use strict;
use libinstall;
use emdb;
use OSinfo;
use NodeType;
my $EID = "vlan-holding";
my $DESC = "Holding experiment for internal vlans";
my $SUDO = "/usr/local/bin/sudo";
my $BATCHEXP = "$TBROOT/bin/batchexp";
sub InstallUpdate($$)
{
my ($version, $phase) = @_;
my $pid = "emulab-ops";
if ($phase eq "pre") {
Phase "vlan-holding", "Setting up vlan holding support", sub {
#
# Holding experiment.
#
Phase "experiment", "Creating vlan holding experiment", sub {
PhaseSkip("Experiment exists")
if (-d "$PROJROOT/$pid/exp/$EID");
ExecQuietFatal("$SUDO -u $PROTOUSER $WAP $BATCHEXP ".
" -q -i -k -j -w -f -n ".
" -S 'System Experiment' ".
" -L 'System Experiment' ".
" -E '$DESC - DO NOT DELETE' ".
" -p $pid -e $EID");
PhaseSucceed();
};
PhaseSucceed();
};
}
}
1;
......@@ -35,7 +35,9 @@ struct emulab_ha_extra_info {
char *pid; /* project */
char *gid; /* group */
char *eid; /* experiment */
char *suid; /* swapper user name */
char *sname; /* swapper user name */
int suid; /* swapper's unix uid */
int egid; /* experiment's unix gid */
};
static char *MC_BASEADDR = FRISEBEEMCASTADDR;
......@@ -184,7 +186,7 @@ emulab_free_host_authinfo(struct config_host_authinfo *ai)
FREE(ei->pid);
FREE(ei->gid);
FREE(ei->eid);
FREE(ei->suid);
FREE(ei->sname);
free(ai->extra);
}
free(ai);
......@@ -333,7 +335,7 @@ allow_stddirs(char *imageid,
snprintf(tpath, sizeof tpath, "%s/%s/%s", GROUPSDIR, ei->pid, ei->gid);
gdir = mystrdup(tpath);
snprintf(tpath, sizeof tpath, "%s/%s", USERSDIR, ei->suid);
snprintf(tpath, sizeof tpath, "%s/%s", USERSDIR, ei->sname);
udir = mystrdup(tpath);
if (SCRATCHDIR) {
......@@ -375,6 +377,7 @@ allow_stddirs(char *imageid,
ci->sig = NULL;
ci->get_options = NULL;
ci->get_methods = 0;
ci->get_uid = ci->get_gid = -1;
ci->put_options = NULL;
ci->extra = NULL;
}
......@@ -408,6 +411,8 @@ allow_stddirs(char *imageid,
ci->sig = NULL;
set_get_options(get, i);
set_get_methods(get, i);
ci->get_uid = ei->suid;
ci->get_gid = ei->egid;