]> andersk Git - moira.git/blame - incremental/afs_utils.pl
Suppress warning about ownership changes - administrators have been warned.
[moira.git] / incremental / afs_utils.pl
CommitLineData
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
12# File format:
13# cell server partition total used alloc
14
15# Locking/re-write algorithm:
16# 1. Open the data file.
17# 2. Obtain a lock on the data file.
18# 3. Check for the existence of a temporary data file - die if it exists.
19# 4. Save current contents into temporary data file.
20# 5. Re-write output (with line-buffering).
21# 6. Unlink temporary file.
22# 7. Unlock data file.
23# 8. Close the data file.
24
25
26sub afs_lock
27{
28 open(SRV,"+<$afs_data") || die "Unable to open $afs_data\n";
29 select((select(SRV), $|=1)[$[]);
30 flock(SRV, $LOCK_EX) || die "Unable to lock $afs_data\n";
f00e5df1 31 die "Temporary status file: $afs_save exists... aborting\n"
6231b320 32 if (-f $afs_save);
33 open(SRV2, ">$afs_save");
34 @afs_data = <SRV>;
35 print SRV2 @afs_data;
36 close(SRV2);
37 seek(SRV, 0, 0);
38}
39
40sub afs_unlock
41{
42 unlink($afs_save);
43 close(SRV);
44}
45
46# Find server/partition for allocation.
47#
48# Best fit algorithm used:
49# max[ (2*free space) - (unused quota) ]
50# = max(2*total - usage - alloc)
51#
52# Note: This routine does not actually adjust the quota; the caller
53# should use afs_quota_adj();
54
55sub afs_find
56{
57 local($cell,$type,$quota) = @_;
58 local($j);
5abfab4b 59 local(@max) = '';
6231b320 60
61 &afs_lock;
62 chop(@afs_data);
63
64 for (@afs_data) {
65 local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
66 next if ($a ne $cell || !$total || $type !~ /$t/);
f00e5df1 67 $alloc = $used if ($alloc < $used);
6231b320 68 $j = 2*$total - $used - $alloc;
69 @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
70 }
71
6231b320 72 &afs_unlock;
73 return(@max);
74}
75
76#
77# Quota adjustments
78#
79sub afs_quota_adj
80{
81 local($cell,$asrv,$apart,$adj) = @_;
5abfab4b 82 local($found) = 0;
6231b320 83
84 &afs_lock;
85 chop(@afs_data);
86 truncate(SRV, 0);
87 for (@afs_data) {
88 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
89 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
90 $alloc += $adj;
91 $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
5abfab4b 92 $found = 1;
6231b320 93 }
94 print SRV "$_\n";
95 }
96 &afs_unlock;
5abfab4b 97 return($found);
6231b320 98}
This page took 0.157079 seconds and 5 git commands to generate.