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... abortin\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 $j = 2*$total - $used - $alloc;
68 @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
73 # ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
74 # if ($a eq $cell && $asrv eq $max[0] && $apart eq $max[1]) {
76 # $_ = join(' ',$a,$asrv,$apart,$t, $total,$used,$alloc);
90 local($cell,$asrv,$apart,$adj) = @_;
96 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
97 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
99 $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
108 # Nightly reaper - Recompute all usages/allocations.
112 local ($key, @vos, %used,%alloc,%total, %a);
113 local ($c,$as,$ap,$total,$used,$alloc);
120 ($c,$as,$ap,$t,$total,$used,$alloc) = split(/\s+/,$_);
121 ($as) = gethostbyname($as);
124 $ap =~ s:^([^/]):/vicep\1:;
127 print SRV "$_\n"; next;
131 $total{$key} = $used{$key} = $alloc{$key} = 0;
134 open(VOS,"$vos partinfo $as $ap -cell $c -noauth|");
138 @vos = split(/\s+/,$vos[0]);
139 $total{$key} = pop(@vos);
140 $used{$key} = $total{$key}-$vos[5];
142 open(VOS,"$vos listvol $as $ap -cell $c -long -noauth|");
147 while ($_ = shift(@vos)) {
148 next unless /On-line/;
149 local($vn,$id) = split(/\s+/, $_);
151 local($p,$p,$p) = split(/\s+/, shift(@vos));
152 local($q,$q,$q) = split(/\s+/, shift(@vos));
153 if ($id==$p || !$a{$p}) {
157 for $p (keys %a) { $alloc{$key} += $a{$p}; delete $a{$p}; }
160 for (sort keys %total) {
161 print SRV "$_ $type{$_} $total{$_} $used{$_} $alloc{$_}\n";