Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
17649161
Commit
17649161
authored
Jan 04, 2001
by
mac
Browse files
Added locking.
parent
995ef733
Changes
2
Hide whitespace changes
Inline
Side-by-side
db/nalloc.in
View file @
17649161
...
...
@@ -5,7 +5,7 @@ use English;
#
# Configure variables
#
my
$TB
=
"
@prefix
@/
bin
";
my
$TB
=
"
@prefix
@/
libexec
";
my
$DBNAME
=
"
@TBDBNAME
@
";
my
$dbh
=
Mysql
->
connect
("
localhost
",
$DBNAME
,"
script
","
none
");
...
...
@@ -17,9 +17,8 @@ my $error = 0;
my
$pid
=
shift
;
my
$eid
=
shift
;
my
@node_names
=
@ARGV
;
my
@machines
=
@node_names
;
foreach
my
$m
(
@machines
)
{
$m
=
"
node_id='
"
.
$m
.
"
'
";
}
my
$list
=
join
("
or
",
@machines
);
my
@vals
=
();
my
@nodes
=
();
my
$cmd
=
"";
my
$sth
=
"";
...
...
@@ -34,6 +33,11 @@ if ( ($sth->numrows < 1) && ($UID != 0) && ($EUID != 0)) {
die
("
You are not a member of experiment '
$eid
' in project '
$pid
'.
\n
");
}
print
"
Locking tables.
\n
";
$cmd
=
"
lock tables nodes read, reserved write
";
$sth
=
$dbh
->
query
(
$cmd
)
||
die
("
Locking error:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
");
foreach
my
$n
(
@node_names
)
{
$sth
=
$dbh
->
query
("
select * from reserved where node_id='
$n
'
");
if
(
$sth
->
numrows
>
0
)
{
...
...
@@ -53,15 +57,32 @@ foreach my $n (@node_names) {
print
"
Node '
$n
' does not exist.
\n
";
$error
++
;
next
;
}
else
{
# No one has reserved it, and it exists, so add it to my list
push
(
@vals
,"
('
$n
','
$pid
','
$eid
')
");
push
(
@nodes
,"
$n
");
}
}
print
"
Reserving node '
$n
'...
";
$cmd
=
"
insert into reserved (node_id,pid,eid) values ('
$n
','
$pid
','
$eid
')
";
$sth
=
$dbh
->
query
(
$cmd
)
&&
print
"
Succeeded.
\n
"
||
(
print
"
Failed Command:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
"
&&
$error
++
);
system
("
$consetup
$n
")
==
0
or
print
STDERR
"
WARNING:
$consetup
$n
failed!
";
}
if
(
!
$error
&&
@vals
)
{
print
"
Reserving nodes...
";
$cmd
=
"
insert into reserved (node_id,pid,eid) values
"
.
join
("
,
",
@vals
);
if
(
$sth
=
$dbh
->
query
(
$cmd
))
{
print
"
Succeeded.
\n
";
foreach
$n
(
@nodes
)
{
system
("
$consetup
$n
")
==
0
or
print
STDERR
"
WARNING:
$consetup
$n
failed!
\n
";
}
}
else
{
print
"
Failed Command:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
";
$error
++
;
}
}
print
"
Unlocking tables.
\n
";
$cmd
=
"
unlock tables
";
$sth
=
$dbh
->
query
(
$cmd
)
||
die
("
Locking error:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
");
exit
(
$error
);
db/nfree.in
View file @
17649161
...
...
@@ -4,7 +4,7 @@ use Mysql;
#
# Configure variables
#
my
$TB
=
"
@prefix
@
/bin
";
my
$TB
=
"
@prefix
@
";
my
$DBNAME
=
"
@TBDBNAME
@
";
my
$dbh
=
Mysql
->
connect
("
localhost
",
$DBNAME
,"
script
","
none
");
...
...
@@ -16,8 +16,8 @@ if ($#ARGV < 1) {
}
my
$error
=
0
;
my
$consetup
=
"
$TB
/console_setup
";
my
$osload
=
"
$TB
/os_load
";
my
$consetup
=
"
$TB
/
libexec/
console_setup
";
my
$osload
=
"
$TB
/
bin/
os_load
";
my
$reloadpid
=
"
testbed
";
my
$reloadeid
=
"
reloading
";
my
$pid
=
shift
;
...
...
@@ -36,6 +36,12 @@ if ($sth->numrows < 1) {
die
("
There is no experiment '
$eid
' in project '
$pid
'.
\n
");
}
print
"
Locking tables.
\n
";
$cmd
=
"
lock tables nodes read, node_types read, reloads read,
"
.
"
interfaces write, reserved write
";
$sth
=
$dbh
->
query
(
$cmd
)
||
die
("
Locking error:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
");
# If list is empty, put in all the nodes
if
(
$#node_names
==
-
1
)
{
print
"
Releasing all nodes from experiment '
$eid
' in project '
$pid
'...
\n
";
...
...
@@ -100,8 +106,9 @@ foreach my $n (@node_names) {
if
(
!
(
$n
=~
/^tbsh/
))
{
#If its not a shark
# Find the control net interface for this node type
$sth
=
$dbh
->
query
("
select control_net from node_types as t left join
"
.
"
nodes as n on n.type=t.type where node_id='
$n
'
");
$sth
=
$dbh
->
query
("
select control_net from node_types left join
"
.
"
nodes on nodes.type=node_types.type where node_id='
$n
'
");
my
@row
=
$sth
->
fetchrow_array
();
my
$control
=
$row
[
0
];
# Clean out all IPs except the control net
...
...
@@ -113,9 +120,14 @@ foreach my $n (@node_names) {
}
system
("
$consetup
$n
")
==
0
or
print
STDERR
"
WARNING:
$consetup
$n
failed!
";
print
STDERR
"
WARNING:
$consetup
$n
failed!
\n
";
}
print
"
Unlocking tables.
\n
";
$cmd
=
"
unlock tables
";
$sth
=
$dbh
->
query
(
$cmd
)
||
die
("
Locking error:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
");
foreach
$reload
(
keys
(
%reloads
))
{
@list
=
@
{
$reloads
{
$reload
}};
# Call os_load to start the reload
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment