11 $zwrite="/usr/athena/bin/zwrite";
13 $afs_data="/moira/afs/afs_data";
14 $afs_save="$afs_data.tmp";
16 %vtypes_ATHENA_MIT_EDU =
17 ("ACTIVITY", "activity",
33 # cell server partition total used alloc
35 # Locking/re-write algorithm:
36 # 1. Open the data file.
37 # 2. Obtain a lock on the data file.
38 # 3. Check for the existence of a temporary data file - die if it exists.
39 # 4. Save current contents into temporary data file.
40 # 5. Re-write output (with line-buffering).
41 # 6. Unlink temporary file.
42 # 7. Unlock data file.
43 # 8. Close the data file.
46 $flock_t="ssllllllll";
50 open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n";
51 select((select(SRV), $|=1)[$[]);
53 $flkarr[1]=$flkarr[2]=$flkarr[3]=$flkarr[4]=$flkarr[5]=$flkarr[6]=0;
54 $flkarr[7]=$flkarr[8]=$flkarr[9]=0;
55 $flk=pack($flock_t,@flkarr);
56 fcntl(SRV, &F_SETLKW, $flk) || die "Unable to lock $afs_data:$!\n";
57 die "Temporary status file: $afs_save exists... aborting\n"
59 open(SRV2, ">$afs_save");
72 # Find server/partition for allocation.
74 # Best fit algorithm used:
75 # max[ (2*free space) - (unused quota) ]
76 # = max(2*total - usage - alloc)
78 # Note: This routine does not actually adjust the quota;
79 # the calling routine should use afs_quota_adj();
83 local($cell,$type,$quota,@except) = @_;
85 local(@max) = ("", "", -10000000);
92 local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
93 next if ($a ne $cell || !$total || $type !~ /$t/);
95 next sloop if ($j eq $asrv);
97 $alloc = $used if ($alloc < $used);
98 $j = 2*$total - $used - $alloc;
99 @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
111 local($cell,$asrv,$apart,$adj,$dusage) = @_;
118 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
119 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
120 $dusage = $used unless ($dusage);
122 $_ = join(' ',$c,$asrv,$apart,$t,$total,$dusage,$alloc);