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