]> andersk Git - moira.git/blobdiff - incremental/afs_utils.pl
added hosttable stuff
[moira.git] / incremental / afs_utils.pl
index c1fd793c2fc3da3228bf88cb567952af71a09e01..f64579b0f1dbb5be8bca5c7b02f4416bf9ccafd1 100644 (file)
@@ -1,3 +1,5 @@
+# $Header$
+
 $afsbin="/moira/bin";
 $vos="$afsbin/vos";
 $pts="$afsbin/pts";
@@ -9,6 +11,21 @@ $afs_save="$afs_data.tmp";
 $LOCK_EX=2;
 $LOCK_UN=8;
 
+%vtypes_ATHENA_MIT_EDU =
+    ("ACTIVITY", "activity",
+     "APROJ", "aproj",
+     "AREF", "aref",
+     "CONTRIB", "contrib",
+     "COURSE", "course",
+     "HOMEDIR", "user",
+     "LEASE", "dept",
+     "PROJECT", "project",
+     "REF", "ref",
+     "SW", "sw",
+     "SYSTEM", "system",
+     "UROP", "urop",
+     );
+
 # File format:
 #    cell server partition total used alloc
 
@@ -28,7 +45,7 @@ sub afs_lock
     open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n";
     select((select(SRV), $|=1)[$[]);
     flock(SRV, $LOCK_EX) || die "Unable to lock $afs_data\n";
-    die "Temporary status file: $afs_save exists... abortin\n"
+    die "Temporary status file: $afs_save exists... aborting\n"
        if (-f $afs_save);
     open(SRV2, ">$afs_save");
     @afs_data = <SRV>;
@@ -54,30 +71,25 @@ sub afs_unlock
 
 sub afs_find
 {
-    local($cell,$type,$quota) = @_;
-    local($j);
-    local(@max);
+    local($cell,$type,$quota,@except) = @_;
+    local($j,$k);
+    local(@max) = ("", "", -10000000);
 
     &afs_lock;
     chop(@afs_data);
 
+  sloop:
     for (@afs_data) {
        local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
        next if ($a ne $cell || !$total || $type !~ /$t/);
+       for $j (@except) {
+           next sloop if ($j eq $asrv);
+       }
+       $alloc = $used if ($alloc < $used);
        $j = 2*$total - $used - $alloc;
        @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
     }
 
-#    truncate(SRV, 0);
-#    for (@afs_data) {
-#      ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
-#      if ($a eq $cell && $asrv eq $max[0] && $apart eq $max[1]) {
-#          $alloc += $quota;
-#          $_ = join(' ',$a,$asrv,$apart,$t, $total,$used,$alloc);
-#      }
-#      print SRV "$_\n";
-#    }
-
     &afs_unlock;
     return(@max);
 }
@@ -88,6 +100,7 @@ sub afs_find
 sub afs_quota_adj
 {
     local($cell,$asrv,$apart,$adj) = @_;
+    local($found) = 0;
 
     &afs_lock;
     chop(@afs_data);
@@ -97,73 +110,10 @@ sub afs_quota_adj
        if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
            $alloc += $adj;
            $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
+           $found = 1;
        }
        print SRV "$_\n";
     }
     &afs_unlock;
-}
-
-
-#
-# Nightly reaper - Recompute all usages/allocations.
-#
-sub afs_nightly
-{
-    local ($key, @vos, %used,%alloc,%total, %a);
-    local ($c,$as,$ap,$total,$used,$alloc);
-
-    &afs_lock;
-    truncate(SRV, 0);
-    for (@afs_data) {
-       $as = $ap = 0;
-       if ($_ !~ /^\#/) {
-           ($c,$as,$ap,$t,$total,$used,$alloc) = split(/\s+/,$_);
-           ($as) = gethostbyname($as);
-           $c =~ tr/a-z/A-Z/;
-           $as =~ tr/a-z/A-Z/;
-           $ap =~ s:^([^/]):/vicep\1:;
-       }
-       if (!$as || !$ap) {
-           print SRV "$_\n"; next;
-       }
-
-       $key = "$c $as $ap";
-       $total{$key} = $used{$key} = $alloc{$key} = 0;
-       $type{$key} = $t;
-
-       open(VOS,"$vos partinfo $as $ap -cell $c -noauth|");
-       chop(@vos = <VOS>);
-       close(VOS);
-       next if ($?);
-       @vos = split(/\s+/,$vos[0]);
-       $total{$key} = pop(@vos);
-       $used{$key} = $total{$key}-$vos[5];
-
-       open(VOS,"$vos listvol $as $ap -cell $c -long -noauth|");
-       @vos = <VOS>;
-       close(VOS);
-       next if ($?);
-
-       while ($_ = shift(@vos)) {
-           next unless /On-line/;
-           local($vn,$id) = split(/\s+/, $_);
-           shift(@vos);
-           local($p,$p,$p) = split(/\s+/, shift(@vos));
-           local($q,$q,$q) = split(/\s+/, shift(@vos));
-           if ($id==$p || !$a{$p}) {
-               $a{$p} = $q;
-           }
-       }
-       for $p (keys %a) { $alloc{$key} += $a{$p}; delete $a{$p}; }
-    }
-
-    for (sort keys %total) {
-       print SRV "$_ $type{$_} $total{$_} $used{$_} $alloc{$_}\n";
-       delete $type{$_};
-       delete $total{$_};
-       delete $used{$_};
-       delete $alloc{$_};
-    }
-
-    &afs_unlock;
+    return($found);
 }
This page took 0.036121 seconds and 4 git commands to generate.