1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | require "/moira/bin/afs_utils.pl"; |
---|
4 | |
---|
5 | # |
---|
6 | # Nightly reaper - Recompute all usages/allocations. |
---|
7 | # |
---|
8 | |
---|
9 | local ($key, @vos, %used,%alloc,%total, %a); |
---|
10 | local ($c,$as,$ap,$total,$used,$alloc); |
---|
11 | |
---|
12 | if (open(TMP,"/afs/athena.mit.edu/service/afs_data")) { |
---|
13 | @new_data = <TMP>; |
---|
14 | close(TMP); |
---|
15 | } |
---|
16 | |
---|
17 | chop(@new_data); |
---|
18 | |
---|
19 | for (@new_data) { |
---|
20 | ($c,$as,$ap) = split(/\s+/,$_); |
---|
21 | ($as) = gethostbyname($as) unless ($c =~ /^\#/); |
---|
22 | $c =~ tr/a-z/A-Z/; |
---|
23 | $as =~ tr/a-z/A-Z/; |
---|
24 | $ap =~ s:^([^/]):/vicep\1:; |
---|
25 | $ok{"$c $as $ap"} = 1; |
---|
26 | } |
---|
27 | for (@new_data) { |
---|
28 | $as = $ap = 0; |
---|
29 | if ($_ !~ /^\#/) { |
---|
30 | ($c,$as,$ap,$type) = split(/\s+/,$_); |
---|
31 | ($as) = gethostbyname($as); |
---|
32 | $c =~ tr/a-z/A-Z/; |
---|
33 | $as =~ tr/a-z/A-Z/; |
---|
34 | $ap =~ s:^([^/]):/vicep\1:; |
---|
35 | } |
---|
36 | next unless ($as && $ap); |
---|
37 | |
---|
38 | &afs_lock; |
---|
39 | truncate(SRV, 0); |
---|
40 | for (@afs_data) { |
---|
41 | ($c2,$as2,$ap2) = split(/\s+/,$_); |
---|
42 | next unless ($c2 =~ /^\#/ || $ok{"$c2 $as2 $ap2"}); |
---|
43 | print SRV $_ unless ($c eq $c2 && $as eq $as2 && $ap eq $ap2); |
---|
44 | } |
---|
45 | &afs_unlock; |
---|
46 | |
---|
47 | open(VOS,"$vos partinfo $as $ap -cell $c -noauth|"); |
---|
48 | chop(@vos = <VOS>); |
---|
49 | close(VOS); |
---|
50 | next if ($?); |
---|
51 | @vos = split(/\s+/,$vos[0]); |
---|
52 | $total = pop(@vos); |
---|
53 | $used = $total-$vos[5]; |
---|
54 | $alloc = 0; |
---|
55 | |
---|
56 | open(VOS,"$vos listvol $as $ap -cell $c -long -noauth|"); |
---|
57 | @vos = <VOS>; |
---|
58 | close(VOS); |
---|
59 | next if ($?); |
---|
60 | |
---|
61 | while ($_ = shift(@vos)) { |
---|
62 | next unless /On-line/; |
---|
63 | local($vn,$id) = split(/\s+/, $_); |
---|
64 | shift(@vos); |
---|
65 | local($p,$p,$p) = split(/\s+/, shift(@vos)); |
---|
66 | local($q,$q,$q) = split(/\s+/, shift(@vos)); |
---|
67 | if ($id==$p || !$a{$p}) { |
---|
68 | $a{$p} = $q; |
---|
69 | } |
---|
70 | } |
---|
71 | for $p (keys %a) { $alloc += $a{$p}; delete $a{$p}; } |
---|
72 | |
---|
73 | &afs_lock; |
---|
74 | seek(SRV, 0, 2); |
---|
75 | print SRV "$c $as $ap $type $total $used $alloc\n"; |
---|
76 | &afs_unlock; |
---|
77 | } |
---|