6 $afs_data="/moira/afs/afs_data";
7 $afs_save="$afs_data.tmp";
13 # cell server partition total used alloc
15 # Locking/re-write algorithm:
16 # 1. Open the data file.
17 # 2. Obtain a lock on the data file.
18 # 3. Check for the existence of a temporary data file - die if it exists.
19 # 4. Save current contents into temporary data file.
20 # 5. Re-write output (with line-buffering).
21 # 6. Unlink temporary file.
22 # 7. Unlock data file.
23 # 8. Close the data file.
28 open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n";
29 select((select(SRV), $|=1)[$[]);
30 flock(SRV, $LOCK_EX) || die "Unable to lock $afs_data\n";
31 die "Temporary status file: $afs_save exists... aborting\n"
33 open(SRV2, ">$afs_save");
46 # Find server/partition for allocation.
48 # Best fit algorithm used:
49 # max[ (2*free space) - (unused quota) ]
50 # = max(2*total - usage - alloc)
52 # Note: This routine does not actually adjust the quota; the caller
53 # should use afs_quota_adj();
57 local($cell,$type,$quota) = @_;
65 local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
66 next if ($a ne $cell || !$total || $type !~ /$t/);
67 $alloc = $used if ($alloc < $used);
68 $j = 2*$total - $used - $alloc;
69 @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
81 local($cell,$asrv,$apart,$adj) = @_;
88 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
89 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
91 $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);