]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
mg-allocate: Support --steal
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 22 Mar 2016 18:47:55 +0000 (18:47 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 27 Jun 2016 16:55:55 +0000 (17:55 +0100)
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mg-allocate

index 10a83ebc158b0c49b7be49a835f66c39a32db5fa..08fa96d06ffcbf3b71507adc7993df9d9a78d1cb 100755 (executable)
 #
 #   -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.
@@ -54,6 +61,8 @@ $|=1;
 
 our $tid;
 our %magictask;
+our @steal_specs;
+our %steal_taskids;
 
 sub alloc_prep () {
     $tid= findtask();
@@ -64,6 +73,11 @@ sub alloc_prep () {
 END
         $magictask{$rk}= $row->{taskid};
     }
+
+    foreach my $spec (@steal_specs) {
+       my ($taskid) = findtask_spec($spec, "victim ");
+       $steal_taskids{$taskid} = 1;
+    }
 }
 
 sub parse_1res ($) {
@@ -136,12 +150,20 @@ END
                     $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) = @_;
@@ -176,6 +198,7 @@ END
                 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;
@@ -202,6 +225,7 @@ END
         } else {
             if ($isshared) {
                 logm("$desc: unsharing, freeing");
+            } elsif ($isstealable->($candrow)) {
             } elsif ($candrow->{owntaskid} != $tid) {
                 logm("$desc: locked by ".$findowner->($candrow));
                 next;
@@ -401,6 +425,9 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
                                              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 \`$_'";
         }
@@ -408,6 +435,8 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
 }
 
 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)';