#
# -U allocate with high priority (makes sense with
# specified duration only)
+#
+# --steal <task-spec>
+# Treat resources owned by the task <task-spec>
+# as if they were free. This allows us to steal
+# resources from other tasks. May be repeated.
+#
+# <task-spec> must exist (and be in a format valid for OSSTEST_TASK).
# This is part of "osstest", an automated testing framework for Xen.
# Copyright (C) 2009-2013 Citrix Inc.
our $tid;
our %magictask;
+our @steal_specs;
+our %steal_taskids;
sub alloc_prep () {
$tid= findtask();
END
$magictask{$rk}= $row->{taskid};
}
+
+ foreach my $spec (@steal_specs) {
+ my ($taskid) = findtask_spec($spec, "victim ");
+ $steal_taskids{$taskid} = 1;
+ }
}
sub parse_1res ($) {
$ndone==1 or die "$restype $resname $newtid $desc";
};
+ my $isstealable= sub {
+ my ($joinedrow) = @_;
+ return 0 unless $steal_taskids{ $joinedrow->{taskid} };
+ logm("$desc: stealing ".(join '/', map { $joinedrow->{$_} }
+ qw(restype resname shareix)));
+ return 1;
+ };
my $isallocatable= sub {
my ($joinedrow) = @_;
return
!$joinedrow->{live} ||
$joinedrow->{taskid}==$magictask{allocatable} ||
- $joinedrow->{taskid}==$magictask{idle};
+ $joinedrow->{taskid}==$magictask{idle} ||
+ $isstealable->($joinedrow);
};
my $findowner= sub {
my ($joinedrow) = @_;
next if $isallocatable->($sharerow);
next if $sharerow->{taskid} == $tid;
next if $sharerow->{taskid} == $magictask{preparing};
+ next if $isstealable->{$sharerow};
logm("$desc: shared, $sharerow->{shareix} locked by ".
$findowner->($sharerow));
$allshareok= 0;
} else {
if ($isshared) {
logm("$desc: unsharing, freeing");
+ } elsif ($isstealable->($candrow)) {
} elsif ($candrow->{owntaskid} != $tid) {
logm("$desc: locked by ".$findowner->($candrow));
next;
1);
} elsif (s/^\-U/-/) {
$ENV{OSSTEST_RESOURCE_PRIORITY} //= -1000000;
+ } elsif (s/^--steal$/-/) {
+ die "--steal needs task\n" unless @ARGV;
+ push @steal_specs, shift @ARGV;
} else {
die "bad option \`$_'";
}
}
if ($duration) {
+ die "--steal is incompatible with the planning system\n"
+ if @steal_specs;
{
logm("pre-checking resources (dry run)...");
local $Osstest::TestSupport::logm_prefix = $logm_prefix.' (precheck)';