Commit 8ae34050 authored by Robert Ricci's avatar Robert Ricci

Added simple support for limiting how many machines an image can be

loaded on at once. The idea is to use this for things like rtLinux
that require a per-machine license. This mechanism is circumventable,
(for example, by simply making a second image), so it's mainly to
prevent experimenters from accidentally violating the license.
parent ecebc964
......@@ -321,6 +321,7 @@ CREATE TABLE images (
ezid tinyint(4) NOT NULL default '0',
shared tinyint(4) NOT NULL default '0',
updated datetime default NULL,
max_concurrent int(11) default NULL,
PRIMARY KEY (imagename,pid),
KEY imageid (imageid)
) TYPE=MyISAM;
......
......@@ -192,11 +192,12 @@ foreach my $node (@nodes) {
}
%imageid_row = $db_result->fetchhash();
my $loadpart = $imageid_row{'loadpart'};
my $loadlen = $imageid_row{'loadlength'};
my $imagepath = $imageid_row{'path'};
my $defosid = $imageid_row{'default_osid'};
my $shared = $imageid_row{'shared'};
my $loadpart = $imageid_row{'loadpart'};
my $loadlen = $imageid_row{'loadlength'};
my $imagepath = $imageid_row{'path'};
my $defosid = $imageid_row{'default_osid'};
my $shared = $imageid_row{'shared'};
my $max_concurrent = $imageid_row{'max_concurrent'};
# Check for a few errors early!
if (!defined($imagepath)) {
......@@ -208,6 +209,32 @@ foreach my $node (@nodes) {
" $imagepath does not exists or cannot be read!\n");
}
#
# If there's a maxiumum number of concurrent loads listed, check to
# see if we'll go over the limit, by checking to see how many other
# nodes are currently booting thie image's default_osid. This is NOT
# intended to be strong enforcement of license restrictions, just a way
# to catch mistakes.
# XXX This could go outside the @nodes loop, but so could most of this
# stuff
#
if ($max_concurrent && !TBAdmin($UID)) {
# Exclude nodes in this load from the count
my $nodelist = join(" or ",map("node_id='$_'",@nodes));
if (!@nodes) {
$nodelist = "1";
}
my $count_result = DBQueryFatal("select count(*) from nodes where " .
"def_boot_osid='$defosid' and !($nodelist)");
my ($current_count) = $count_result->fetchrow();
if ($current_count + @nodes > $max_concurrent) {
die("*** $0:\n".
" This image is limited to $max_concurrent concurrent " .
" loads, and $current_count\nnodes are already running ".
" $defosid\n");
}
}
#
# Compute a maxwait time based on the image size plus a constant
# factor for the reboot cycle.
......
......@@ -345,6 +345,20 @@ function SPITFORM($formfields, $errors)
echo " > Yes
</td>
</tr>\n";
#
# Maxiumum concurrent loads
#
echo "<tr>
<td>Maximum concurrent loads[<b>7</b>]:</td>
<td class=left>
<input type=text
name=\"formfields[max_concurrent]\"
value=\"" . $formfields[max_concurrent] . "\"
size=4 maxlength=4>
</td>
</tr>\n";
if ($isadmin) {
#
......@@ -420,6 +434,9 @@ function SPITFORM($formfields, $errors)
<li> If you need to snapshot the entire disk (including the MBR),
check this option. <b>Most users will not need to check this
option. Please ask us first to make sure</b>.
<li> If your image contains software that is only licensed to run
on a limited number of nodes at a time, you can put this
number here. Most users will want to leave this option blank.
</ol>
</blockquote></h4>\n";
}
......@@ -620,6 +637,17 @@ if (isset($formfields[wholedisk]) &&
$shared = 1;
}
if (isset($formfields[max_concurrent]) &&
strcmp($formfields[max_concurrent],"")) {
if (!preg_match ("/^\d+$/",$formfields[max_concurrent])) {
$errors["Maximum Concurrent Loads"] = "Invalid number";
}
$max_concurrent = "'" . $formfields[max_concurrent] . "'";
} else {
$max_concurrent = "NULL";
}
#
# If any errors, respit the form with the current values and the
......@@ -693,11 +721,12 @@ if (TBValidImageID($imageid) || TBValidOSID($imageid)) {
DBQueryFatal("INSERT INTO images ".
"(imagename, imageid, ezid, description, loadpart, loadlength, ".
" part" . "$bootpart" . "_osid, ".
" default_osid, path, pid, shared, creator, created) ".
" default_osid, path, pid, shared, creator, created, ".
" max_concurrent) ".
"VALUES ".
" ('$imagename', '$imageid', 1, '$description', $loadpart, ".
" $loadlen, '$imageid', '$imageid', '$path', '$pid', $shared, ".
" '$uid', now())");
" '$uid', now(), $max_concurrent)");
DBQueryFatal("INSERT INTO os_info ".
"(osname, osid, ezid, description, OS, version, path, magic, ".
......
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