]>
Commit | Line | Data |
---|---|---|
6231b320 | 1 | $afsbin="/moira/bin"; |
2 | $vos="$afsbin/vos"; | |
3 | $pts="$afsbin/pts"; | |
4 | $fs="$afsbin/fs"; | |
5 | ||
c09dcc8c | 6 | $afs_data="/moira/afs/afs_data"; |
6231b320 | 7 | $afs_save="$afs_data.tmp"; |
8 | ||
9 | $LOCK_EX=2; | |
10 | $LOCK_UN=8; | |
11 | ||
8a6a9ced | 12 | %vtypes_ATHENA_MIT_EDU = |
13 | ("ACTIVITY", "activity", | |
14 | "APROJ", "aproj", | |
15 | "AREF", "aref", | |
16 | "CONTRIB", "contrib", | |
17 | "COURSE", "course", | |
18 | "HOMEDIR", "user", | |
19 | "PROJECT", "project", | |
20 | "REF", "ref", | |
21 | "SW", "sw", | |
22 | "SYSTEM", "system", | |
23 | "UROP", "urop", | |
24 | ); | |
25 | ||
6231b320 | 26 | # File format: |
27 | # cell server partition total used alloc | |
28 | ||
29 | # Locking/re-write algorithm: | |
30 | # 1. Open the data file. | |
31 | # 2. Obtain a lock on the data file. | |
32 | # 3. Check for the existence of a temporary data file - die if it exists. | |
33 | # 4. Save current contents into temporary data file. | |
34 | # 5. Re-write output (with line-buffering). | |
35 | # 6. Unlink temporary file. | |
36 | # 7. Unlock data file. | |
37 | # 8. Close the data file. | |
38 | ||
39 | ||
40 | sub afs_lock | |
41 | { | |
42 | open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n"; | |
43 | select((select(SRV), $|=1)[$[]); | |
44 | flock(SRV, $LOCK_EX) || die "Unable to lock $afs_data\n"; | |
f00e5df1 | 45 | die "Temporary status file: $afs_save exists... aborting\n" |
6231b320 | 46 | if (-f $afs_save); |
47 | open(SRV2, ">$afs_save"); | |
48 | @afs_data = <SRV>; | |
49 | print SRV2 @afs_data; | |
50 | close(SRV2); | |
51 | seek(SRV, 0, 0); | |
52 | } | |
53 | ||
54 | sub afs_unlock | |
55 | { | |
56 | unlink($afs_save); | |
57 | close(SRV); | |
58 | } | |
59 | ||
754ef493 | 60 | # Find server/partition for allocation. |
6231b320 | 61 | # |
62 | # Best fit algorithm used: | |
63 | # max[ (2*free space) - (unused quota) ] | |
64 | # = max(2*total - usage - alloc) | |
65 | # | |
66 | # Note: This routine does not actually adjust the quota; the caller | |
67 | # should use afs_quota_adj(); | |
754ef493 | 68 | |
6231b320 | 69 | sub afs_find |
70 | { | |
97798f36 | 71 | local($cell,$type,$quota,@except) = @_; |
72 | local($j,$k); | |
5abfab4b | 73 | local(@max) = ''; |
6231b320 | 74 | |
75 | &afs_lock; | |
76 | chop(@afs_data); | |
77 | ||
97798f36 | 78 | sloop: |
754ef493 | 79 | for (@afs_data) { |
80 | local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_); | |
6231b320 | 81 | next if ($a ne $cell || !$total || $type !~ /$t/); |
97798f36 | 82 | for $j (@except) { |
83 | next sloop if ($j eq $asrv); | |
84 | } | |
f00e5df1 | 85 | $alloc = $used if ($alloc < $used); |
6231b320 | 86 | $j = 2*$total - $used - $alloc; |
754ef493 | 87 | @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]); |
6231b320 | 88 | } |
89 | ||
6231b320 | 90 | &afs_unlock; |
91 | return(@max); | |
92 | } | |
93 | ||
754ef493 | 94 | # |
95 | # Quota adjustments | |
96 | # | |
6231b320 | 97 | sub afs_quota_adj |
98 | { | |
99 | local($cell,$asrv,$apart,$adj) = @_; | |
5abfab4b | 100 | local($found) = 0; |
6231b320 | 101 | |
102 | &afs_lock; | |
103 | chop(@afs_data); | |
104 | truncate(SRV, 0); | |
105 | for (@afs_data) { | |
106 | local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_); | |
107 | if ($c eq $cell && $as eq $asrv && $ap eq $apart) { | |
108 | $alloc += $adj; | |
109 | $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc); | |
5abfab4b | 110 | $found = 1; |
6231b320 | 111 | } |
112 | print SRV "$_\n"; | |
113 | } | |
114 | &afs_unlock; | |
5abfab4b | 115 | return($found); |
6231b320 | 116 | } |