]> andersk Git - moira.git/blame - incremental/afs_utils.pl
Preserve hidden status of groups
[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";
31 die "Temporary status file: $afs_save exists... abortin\n"
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/);
67 $j = 2*$total - $used - $alloc;
68 @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]);
69 }
70
71# truncate(SRV, 0);
72# for (@afs_data) {
73# ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_);
74# if ($a eq $cell && $asrv eq $max[0] && $apart eq $max[1]) {
75# $alloc += $quota;
76# $_ = join(' ',$a,$asrv,$apart,$t, $total,$used,$alloc);
77# }
78# print SRV "$_\n";
79# }
80
81 &afs_unlock;
82 return(@max);
83}
84
85#
86# Quota adjustments
87#
88sub afs_quota_adj
89{
90 local($cell,$asrv,$apart,$adj) = @_;
5abfab4b 91 local($found) = 0;
6231b320 92
93 &afs_lock;
94 chop(@afs_data);
95 truncate(SRV, 0);
96 for (@afs_data) {
97 local ($c, $as, $ap, $t, $total, $used, $alloc) = split(/\s+/,$_);
98 if ($c eq $cell && $as eq $asrv && $ap eq $apart) {
99 $alloc += $adj;
100 $_ = join(' ',$c,$asrv,$apart,$t,$total,$used,$alloc);
5abfab4b 101 $found = 1;
6231b320 102 }
103 print SRV "$_\n";
104 }
105 &afs_unlock;
5abfab4b 106 return($found);
6231b320 107}
This page took 0.078468 seconds and 5 git commands to generate.