]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
flight preservation: Provide a way to allocate flights
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 4 Oct 2016 12:24:34 +0000 (13:24 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 4 Oct 2016 12:25:26 +0000 (13:25 +0100)
Teach mg-allocate to create and delete resources table entries for
flights, as necessary.  And, provide a conveniance alias F/<flight>.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
README.planner
mg-allocate

index 9d35b40643cb3c9d100f55938b3bb761e46f778b..f3cab537c27123c3c79e7a2fd61213acda4138d8 100644 (file)
@@ -206,9 +206,15 @@ Flight logs and build artefacts are normally expired based on their
 start time, or the start time of the most recent flight which refers
 to them.
 
-Flights can be protected (preserved) by allocating them somehow:
+Flights can be protected (preserved) by allocating them with
+./mg-allocate F/<flight>.
+
 Flights are represented by restype='share-flight' entries in the
-resources table.
+resources table.  Conventionally, the shareix is the owning taskid.
+This allows multiple tasks to lock a single flight.  There is no
+corresponding entry with restype='flight', nor a resource_sharing
+entry.  mg-allocate will create and clean up share-flight entries as
+needed.
 
 
 DETAILED PROTOCOL NOTES
index 0317229cfa112a8347db96c9ffd261b2bb777131..ef57bb81ddd24dde9efde66714128bcf330ec441 100755 (executable)
@@ -6,6 +6,7 @@
 # <resource-spec> syntax:
 #   [!][<type>/]<name>[/<share>]      type defaults to 'host'
 #                                     type=='S' means 'shared-host'
+#                                     type=='F' means 'shared-flight'
 #                                     share defaults to *
 #                                     "!" prefix means deallocate
 #                                     name=option|option|... means
@@ -112,6 +113,17 @@ sub parse_1res ($) {
     $restype= 'share-host' if $restype eq 'S';
     my $resname= $3;
     my $shareix= $4;
+
+    if ($restype eq 'F') {
+       die unless $resname =~ m/^\d+$/;
+       die unless $resname eq $resname+0;
+       die if defined $shareix;
+       die if $donate_spec;
+       die if @steal_specs;
+       $restype = 'share-flight';
+       $shareix = $tid;
+    }
+
     $shareix= defined($shareix) ? $shareix+0 : '*';
     my $shareixcond = $shareix eq '*' ? '' : "AND shareix = $shareix";
 
@@ -147,6 +159,23 @@ sub alloc_1rescand ($$) {
     my ($res, $rescand) = @_;
     my ($allocate, $restype, $resname, $shareix, $shareixcond) = @$rescand;
 
+    if ($allocate && $restype eq 'share-flight' && $shareix == $tid) {
+       $dbh_tests->do(<<END,{},
+            INSERT INTO resources
+                 (SELECT ? AS restype,
+                         ? AS resname,
+                         ? AS shareix,
+                         ? AS owntaskid
+                   WHERE NOT EXISTS
+                    (SELECT 1 FROM resources
+                         WHERE restype=?
+                           AND resname=?
+                           AND shareix=?))
+END
+                      $restype,$resname,$shareix, $magictask{idle},
+                      $restype,$resname,$shareix);
+    }
+
     my $resq= $dbh_tests->prepare(<<END);
                 SELECT * FROM resources r
                          JOIN tasks t
@@ -257,6 +286,16 @@ END
                 logm("$desc: freeing");
             }
            $setres->($donate_taskid // $magictask{idle});
+           if ($restype eq 'share-flight' && $shareix == $tid) {
+               $dbh_tests->do(<<END,{},
+                    DELETE FROM resources
+                          WHERE restype = ?
+                            AND resname = ?
+                            AND shareix = ?
+                            AND owntaskid = ?
+END
+                              $restype,$resname,$shareix, $magictask{idle});
+           }
         }
 
         if ($isshared) {