@@ -1175,7 +1175,7 @@ sub selecthost ($;$$) {
my ($ident, $none_ok, $prospective) = @_;
# must be run outside transaction
- # $ident is <identspec>
+ # $ident is [@]<identspec>
#
# <identspec> can be <ident>, typically "host" or "xxx_host"
# which means look up the runvar $r{$ident} which
@@ -1191,8 +1191,16 @@ sub selecthost ($;$$) {
# <hostspec> can be <parent_identspec>:<domname> meaning use the
# Xen domain name <domname> on the host specified by
# <parent_identspec>, which is an <identspec> as above.
+ #
+ # The leading @, if present, specifies that this script should be
+ # skipped if the host is being reused or shared. Specifically:
+ # if the host is shared and in sharing state `ready'. And, it is
+ # wrong to specify @ when multiple hosts are being selected.
my $name;
+
+ my $isprep = $ident =~ s/^\@//;
+
if ($ident =~ m/=/) {
$ident= $`;
$name= $'; #'
@@ -1352,13 +1360,27 @@ sub selecthost ($;$$) {
$mjobdb->host_check_allocated($ho);
- logm("host $ho->{Ident}: selected $ho->{Name} ".
+ logm("host $ho->{Ident}".
+ ($isprep ? " (prep)" : "").
+ ": selected $ho->{Name} ".
(defined $ho->{Ether} ? $ho->{Ether} : '<unknown-ether>').
" $ho->{Ip}".
(!$ho->{Shared} ? '' :
sprintf(" - shared %s %s %d", $ho->{Shared}{Type},
$ho->{Shared}{State}, $ho->{Shared}{Others}+1)));
+ if ($isprep && $ho->{Shared}) {
+ my $st = $ho->{Shared}{State};
+ if ($st eq 'ready') {
+ logm("host is ready, skipping step");
+ exit 0;
+ } elsif ($st eq 'prep') {
+ # ok, we need to do it
+ } else {
+ die "host sharestate is $st but isprep (@ in ident)";
+ }
+ }
+
return $ho;
}