]> andersk Git - moira.git/blob - incremental/afs_utils.pl
Add the pathname to the zwrite binary
[moira.git] / incremental / afs_utils.pl
1 # $Header$
2
3 $afsbin="/moira/bin";
4 $vos="$afsbin/vos";
5 $pts="$afsbin/pts";
6 $fs="$afsbin/fs";
7 $zwrite="/usr/athena/bin/zwrite"
8
9 $afs_data="/moira/afs/afs_data";
10 $afs_save="$afs_data.tmp";
11
12 $LOCK_EX=2;
13 $LOCK_UN=8;
14
15 %vtypes_ATHENA_MIT_EDU =
16     ("ACTIVITY", "activity",
17      "APROJ", "aproj",
18      "AREF", "aref",
19      "CONTRIB", "contrib",
20      "COURSE", "course",
21      "HOMEDIR", "user",
22      "LEASE", "dept",
23      "ORG", "org",
24      "PROJECT", "project",
25      "REF", "ref",
26      "SW", "sw",
27      "SYSTEM", "system",
28      "UROP", "urop",
29      );
30
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
45 sub 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";
50     die "Temporary status file: $afs_save exists... aborting\n"
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
59 sub afs_unlock
60 {
61     unlink($afs_save);
62     close(SRV);
63 }
64
65 # Find server/partition for allocation.
66 #
67 # Best fit algorithm used:
68 #    max[ (2*free space) - (unused quota) ]
69 #    = max(2*total - usage - alloc)
70 #
71 # Note: This routine does not actually adjust the quota; the caller
72 # should use afs_quota_adj();
73
74 sub afs_find
75 {
76     local($cell,$type,$quota,@except) = @_;
77     local($j,$k);
78     local(@max) = ("", "", -10000000);
79
80     &afs_lock;
81     chop(@afs_data);
82
83   sloop:
84     for (@afs_data) {
85         local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
86         next if ($a ne $cell || !$total || $type !~ /$t/);
87         for $j (@except) {
88             next sloop if ($j eq $asrv);
89         }
90         $alloc = $used if ($alloc < $used);
91         $j = 2*$total - $used - $alloc;
92         @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
93     }
94
95     &afs_unlock;
96     return(@max);
97 }
98
99 #
100 # Quota adjustments
101 #
102 sub afs_quota_adj
103 {
104     local($cell,$asrv,$apart,$adj) = @_;
105     local($found) = 0;
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) {
113             $alloc += $adj;
114             $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
115             $found = 1;
116         }
117         print SRV "$_\n";
118     }
119     &afs_unlock;
120     return($found);
121 }
This page took 0.047777 seconds and 5 git commands to generate.