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