Commit 04c605bf authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Fix several bugs wrt swapmod and backup/restore of new tables and old vlans

table.
parent 3eab6635
......@@ -305,6 +305,8 @@ sub BackupExperimentLans($$$)
DBQueryWarn("select lanid from lans where exptidx='$exptidx'");
return -1
if (! $query_result);
return 0
if (! $query_result->numrows);
while (my ($lanid) = $query_result->fetchrow_array()) {
push(@lanids, $lanid);
......@@ -316,6 +318,33 @@ sub BackupExperimentLans($$$)
"into outfile '$pstatedir/$table'")
or return -1;
}
# Keep the vlans table in sync for now. Will remove later.
DBQueryWarn("select * from vlans where exptidx='$exptidx' ".
"into outfile '$pstatedir/vlans' ")
or return -1;
return 0;
}
#
# Class method to restore all lans for an experiment.
#
sub RestoreExperimentLans($$$)
{
my ($class, $experiment, $pstatedir) = @_;
return -1
if (! ref($experiment));
# Keep the vlans table in sync for now. Will remove later.
foreach my $table ("lans", "lan_attributes", "lan_members",
"lan_member_attributes", "ifaces", "vlans") {
if (-e "$pstatedir/$table") {
DBQueryWarn("load data infile '$pstatedir/$table' ".
"into table $table")
or return -1;
}
}
return 0;
}
......@@ -513,40 +542,36 @@ sub AddMember($$;$)
return undef
if (!ref($self));
my $member = Lan::Member->Create($self);
if (defined($node)) {
if (!ref($node)) {
$node = Node->Lookup($node);
if (!defined($node)) {
$member->Destroy();
return undef;
}
}
# And the node.
if ($member->SetAttribute("node_id", $node->node_id()) != 0) {
$member->Destroy();
return undef;
}
# Set the attribute for the physical interface.
if (defined($iface) &&
$member->SetAttribute("iface", $iface) != 0) {
$member->Destroy();
if (!ref($node)) {
$node = Node->Lookup($node);
if (!defined($node)) {
return undef;
}
}
my $member = Lan::Member->Create($self, $node);
# Keep vlans table in sync for now.
if ($self->type() eq "vlan" && !$initialize) {
my $member = $node->node_id() . ":" . $iface;
my $vlanid;
# And the node attribute
if ($member->SetAttribute("node_id", $node->node_id()) != 0) {
$member->Destroy();
return undef;
}
# Set the attribute for the physical interface.
if (defined($iface) &&
$member->SetAttribute("iface", $iface) != 0) {
$member->Destroy();
return undef;
}
# Keep vlans table in sync for now.
if ($self->type() eq "vlan" && !$initialize) {
my $member = $node->node_id() . ":" . $iface;
my $vlanid;
$self->GetAttribute("vlanid", \$vlanid);
$self->GetAttribute("vlanid", \$vlanid);
DBQueryWarn("update vlans set ".
" members=CONCAT_WS(' ', members, '$member') ".
"where id='$vlanid'");
}
DBQueryWarn("update vlans set ".
" members=CONCAT_WS(' ', members, '$member') ".
"where id='$vlanid'");
}
return $member;
}
......@@ -950,14 +975,21 @@ sub Stringify($)
#
# Create a new Lan::Member object (on a specific lan) and return it.
#
sub Create($$)
sub Create($$$)
{
my ($class, $lan) = @_;
my $lanid = $lan->lanid();
my ($class, $lan, $node) = @_;
if (!ref($node)) {
$node = Node->Lookup($node);
return 0
if (!defined($node));
}
my $nodeid = $node->node_id();
my $lanid = $lan->lanid();
my $query_result =
DBQueryWarn("insert into lan_members set ".
" lanid='$lanid', memberid=NULL");
" lanid='$lanid', memberid=NULL, node_id='$nodeid'");
return undef
if (!$query_result);
......@@ -1233,7 +1265,7 @@ sub Create($$$$$;$)
# Use supplied member (which provides the ifaceid) or generate a
# new one.
if (!defined($member)) {
$member = $lan->AddMember();
$member = $lan->AddMember($node);
return undef
if (!defined($member));
}
......@@ -2018,8 +2050,7 @@ sub ExperimentVLans($$$)
############################################################################
#
# The most common kind of Lan is a Vlan, so lets create a package/object
# for it.
# Another convenience package, for tunnels.
#
package Tunnel;
use libdb;
......@@ -2072,9 +2103,9 @@ sub GetExperiment($) { return $_[0]->{'EXPT'}; }
#
# Create a new Tunnel object and return it. No members yet ...
#
sub Create($$$$;$$)
sub Create($$$$$;$$)
{
my ($class, $experiment, $vname, $secretkey, $mask, $port) = @_;
my ($class, $experiment, $vname, $secretkey, $style, $mask, $port) = @_;
# The new lan has the 'ready' bit set to zero.
my $lan = Lan->Create($experiment, $vname, "tunnel");
......@@ -2086,6 +2117,10 @@ sub Create($$$$;$$)
$lan->Destroy();
return undef;
}
if ($lan->SetAttribute("style", $style) != 0) {
$lan->Destroy();
return undef;
}
if (defined($port) &&
$lan->SetAttribute("serverport", $port) != 0) {
$lan->Destroy();
......@@ -2134,14 +2169,14 @@ sub Stringify($)
#
sub AddInterface($$$$;$$)
{
my ($self, $node, $vnode, $vport, $ip, $peerip, $isserver) = @_;
my ($self, $node, $vnode, $vport) = @_;
if (!ref($node)) {
$node = Node->Lookup($node);
return undef
if (!defined($node));
}
my $member = $self->AddMember($node, $ip, $peerip, $isserver);
my $member = $self->AddMember($node);
return undef
if (!defined($member));
......@@ -2154,11 +2189,11 @@ sub AddInterface($$$$;$$)
}
#
# Add a member to a tunnel.
# Add a member to a tunnel. The caller needs to a bunch of stuff.
#
sub AddMember($$$;$$)
sub AddMember($$)
{
my ($self, $node, $ip, $peerip, $isserver) = @_;
my ($self, $node) = @_;
if (!ref($node)) {
$node = Node->Lookup($node);
......@@ -2169,48 +2204,6 @@ sub AddMember($$$;$$)
return undef
if (!defined($member));
if ($member->SetAttribute("ipaddr", $ip) != 0) {
$member->Destroy();
return undef;
}
if (defined($peerip) &&
$member->SetAttribute("peeripaddr", $peerip) != 0) {
$member->Destroy();
return undef;
}
if (defined($isserver) && $isserver &&
$member->SetAttribute("isserver", "1") != 0) {
$member->Destroy();
return undef;
}
# I think this table is going to go away.
my $pid = $self->pid();
my $eid = $self->eid();
my $exptidx = $self->exptidx();
my $node_id = $node->node_id();
my $lan = $self->vname();
my $secretkey;
my $ipmask;
my $serverport;
if ($self->GetAttribute("secretkey", \$secretkey) != 0 ||
$self->GetAttribute("ipmask", \$ipmask) != 0 ||
$self->GetAttribute("serverport", \$serverport) != 0) {
$member->Destroy();
return undef;
}
$isserver = (defined($isserver) && $isserver ? 1 : 0);
if (!DBQueryWarn("insert into tunnels ".
" (pid, eid, node_id, vname, isserver, port, ".
" peer_ip, mask, assigned_ip, password) ".
"values ('$pid', '$eid', '$node_id', '$lan', ".
" $isserver, '$serverport', ".
" '$peerip', '$ipmask', '$ip','$secretkey')")) {
$member->Destroy();
return undef;
}
return $member;
}
......
......@@ -2744,6 +2744,13 @@ sub TBExptRestorePhysicalState($$)
my $errors = 0;
my $pstateDir = TBExptWorkDir($pid, $eid) . "/pstate";
my $experiment = Experiment->Lookup($pid, $eid);
return 1
if (!defined($experiment));
return 1
if (Lan->RestoreExperimentLans($experiment, $pstateDir) != 0);
foreach my $table (@physicalTables) {
DBQueryWarn("LOAD DATA INFILE '$pstateDir/$table' INTO TABLE $table")
or $errors++;
......
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