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