[24319] | 1 | #!/usr/bin/perl |
---|
[23095] | 2 | # Usage: afs_quota path quota |
---|
| 3 | |
---|
| 4 | require "/moira/bin/afs_utils.pl"; |
---|
| 5 | |
---|
| 6 | die "Usage: $0 path quota\n" unless (@ARGV==2); |
---|
| 7 | |
---|
| 8 | ($path,$newq) = @ARGV; |
---|
| 9 | $path =~ s:^/afs/([^.]):/afs/.\1:; |
---|
| 10 | |
---|
| 11 | system("$fs checkb >/dev/null"); |
---|
| 12 | |
---|
| 13 | open(PROG,"$fs lv $path|"); |
---|
| 14 | chop(@fs=<PROG>); |
---|
| 15 | close(PROG); |
---|
| 16 | die "Unable to get information about $path\n" if ($?); |
---|
| 17 | |
---|
| 18 | shift(@fs); |
---|
| 19 | @tmp = split(/\s+/, shift(@fs)); |
---|
| 20 | $vname = pop(@tmp); |
---|
| 21 | @tmp = split(/\s+/, shift(@fs)); |
---|
| 22 | $oldq = pop(@tmp); |
---|
| 23 | |
---|
| 24 | open(PROG,"$fs whichcell $path|"); |
---|
| 25 | chop($_=<PROG>); |
---|
| 26 | close(PROG); |
---|
| 27 | die "Unable to get information about $path\n" if ($?); |
---|
| 28 | |
---|
| 29 | @tmp=split(/\s+/,$_); |
---|
| 30 | ($cell=pop(@tmp)) =~ s/^'(.*)'$/\1/; |
---|
| 31 | $cell =~ tr/a-z/A-Z/; |
---|
| 32 | |
---|
| 33 | open(PROG,"$vos ex $vname -cell $cell|"); |
---|
| 34 | chop(@tmp=<PROG>); |
---|
| 35 | close(PROG); |
---|
| 36 | die "Unable to get volume information about $vname ($path)\n" if ($?); |
---|
| 37 | |
---|
| 38 | $_ = shift(@tmp); |
---|
| 39 | ($vusage, $vusage, $vusage, $vusage) = split(/\s+/,$_); |
---|
| 40 | $_ = shift(@tmp); |
---|
| 41 | ($asrv,$asrv,$apart) = split(/\s+/,$_); |
---|
| 42 | |
---|
| 43 | open(PROG,"$vos partinfo $asrv $apart -cell $cell|"); |
---|
| 44 | chop($_ = <PROG>); |
---|
| 45 | close(PROG); |
---|
| 46 | die "Unable to get partition information about $asrv $apart\n" if ($?); |
---|
| 47 | |
---|
| 48 | @tmp = split(/\s+/,$_); |
---|
| 49 | $dtotal = $tmp[11]; |
---|
| 50 | $dusage = $dtotal - $tmp[5]; |
---|
| 51 | |
---|
| 52 | system("$fs","sq",$path,$newq); |
---|
| 53 | die "Unable to change quota on $path\n" if ($?); |
---|
| 54 | |
---|
| 55 | &afs_quota_adj($cell,$asrv,$apart,$newq-$oldq,$dusage); |
---|
| 56 | |
---|
| 57 | if ($dusage > (0.9 * $dtotal)) { |
---|
| 58 | system("$zwrite","-q","-n","-c","afsadm","-i","moira","-m", |
---|
| 59 | "WARNING: Disk usage on $asrv:$apart is greater than 90% |
---|
| 60 | Used $dusage K out of $dtotal K"); |
---|
| 61 | } |
---|
| 62 | elsif (($dusage + ($newq-$vusage)) > (0.9 * $dtotal)) { |
---|
| 63 | system("$zwrite","-q","-n","-c","afsadm","-i","moira","-m", |
---|
| 64 | "Quota change on volume $vname, if used completely will cause |
---|
| 65 | $asrv:$apart to be over 90% used. |
---|
| 66 | |
---|
| 67 | Current volume usage: $vusage, old quota $oldq, new quota $newq"); |
---|
| 68 | } |
---|
| 69 | elsif ($newq-$oldq > 3999999) { |
---|
| 70 | system("$zwrite","-q","-n","-c","afsadm","-i","moira","-m", |
---|
| 71 | "Increased quota on volume $vname ($asrv:$apart) from $oldq to $newq"); |
---|
| 72 | } |
---|