6 $afs_data="/moira/afs/afs_data";
7 $afs_save="$afs_data.tmp";
12 %vtypes_ATHENA_MIT_EDU =
13 ("ACTIVITY", "activity",
27 # Returns the canonical volume name for (locker,type,cell)
30 local($name,$type,$cell) = @_;
32 $vtype = eval "\$vtypes_$cell{$type}";
33 return "" unless $vtype;
35 $vname = $vtype . "." . $name;
36 $vname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters
42 # cell server partition total used alloc
44 # Locking/re-write algorithm:
45 # 1. Open the data file.
46 # 2. Obtain a lock on the data file.
47 # 3. Check for the existence of a temporary data file - die if it exists.
48 # 4. Save current contents into temporary data file.
49 # 5. Re-write output (with line-buffering).
50 # 6. Unlink temporary file.
51 # 7. Unlock data file.
52 # 8. Close the data file.
57 open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n";
58 select((select(SRV), $|=1)[$[]);
59 flock(SRV, $LOCK_EX) || die "Unable to lock $afs_data\n";
60 die "Temporary status file: $afs_save exists... aborting\n"
62 open(SRV2, ">$afs_save");
76 # Finds server/partition for allocation.
78 # Best fit algorithm used:
79 # max[ (2*free space) - (unused quota) ]
80 # = max(2*total - usage - alloc)
82 # Note: This routine does not actually adjust the quota; the caller
83 # should use afs_quota_adj();
86 local($cell,$type,$quota) = @_;
87 local($i, $j, $vos, $a);
93 for $i ($[ .. $#afs_data) {
94 ($a, $asrv, $apart, $t, $total, $used, $alloc) =
95 split(/\s+/, $afs_data[$i]);
96 next if ($a ne $cell || !$total || $type !~ /$t/);
97 $alloc = $used if ($alloc < $used);
98 $j = 2*$total - $used - $alloc;
99 if (! @max || $j > $max[2]) {
100 ($total, $used) = &afs_partinfo($asrv, $apart, $cell);
102 $afs_data[$i]=join(' ',$cell,$asrv,$apart,$t,$total,$used,$alloc);
103 @max = ($asrv,$apart,$j);
112 # Function: afs_quota_adj
113 # Adjusts the quota allocation for a given server/partition
116 local($cell,$asrv,$apart,$adj) = @_;
123 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
124 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
126 $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
138 local($as, $ap, $c) = @_;
139 local(@vos, $total, $used);
141 open(VOS,"$vos partinfo $as $ap -cell $c -noauth|");
146 @vos = split(/\s+/,$vos[0]);
148 $used = $total-$vos[5];
149 return ($total,$used);